FTXUI/src/ftxui/component/radiobox_test.cpp
ArthurSonzogni f2dc080a35 Variou details:
- Put the MIT copyright at the end.
- Move the directory /other -> tools
- Various improvements.
2020-08-28 23:54:25 +02:00

83 lines
2.5 KiB
C++

#include "ftxui/component/radiobox.hpp"
#include "gtest/gtest.h"
using namespace ftxui;
TEST(RadioboxTest, Navigation) {
RadioBox radiobox;
radiobox.entries = {L"1", L"2", L"3"};
// With arrow key.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
// With vim like characters.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 0);
// With more entries
radiobox.entries = {L"1", L"2", L"3"};
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
// With tab.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::TabReverse);
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.