mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-29 14:45:53 +08:00
Add ToggleTest.
This commit is contained in:
parent
f48bfcff10
commit
6600e4fc03
@ -154,6 +154,7 @@ export(TARGETS screen dom component NAMESPACE ftxui::
|
|||||||
find_package(GTest)
|
find_package(GTest)
|
||||||
if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
|
if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
|
||||||
add_executable(tests
|
add_executable(tests
|
||||||
|
src/ftxui/component/toggle_test.cpp
|
||||||
src/ftxui/dom/gauge_test.cpp
|
src/ftxui/dom/gauge_test.cpp
|
||||||
src/ftxui/dom/hbox_test.cpp
|
src/ftxui/dom/hbox_test.cpp
|
||||||
src/ftxui/dom/text_test.cpp
|
src/ftxui/dom/text_test.cpp
|
||||||
@ -161,7 +162,7 @@ if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(tests
|
target_link_libraries(tests
|
||||||
PRIVATE dom
|
PRIVATE component
|
||||||
PRIVATE Threads::Threads
|
PRIVATE Threads::Threads
|
||||||
PRIVATE ${GTEST_BOTH_LIBRARIES}
|
PRIVATE ${GTEST_BOTH_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
75
src/ftxui/component/toggle_test.cpp
Normal file
75
src/ftxui/component/toggle_test.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "ftxui/component/toggle.hpp"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
using namespace ftxui;
|
||||||
|
using namespace ftxui;
|
||||||
|
|
||||||
|
TEST(ToggleTest, leftRightArrow) {
|
||||||
|
Toggle toggle;
|
||||||
|
|
||||||
|
// With arrow key.
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
|
||||||
|
// With vim like characters.
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::Character('l'));
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::Character('l'));
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::Character('h'));
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::Character('h'));
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
|
||||||
|
// With more entries
|
||||||
|
toggle.entries = {L"1", L"2", L"3"};
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(toggle.selected, 2);
|
||||||
|
toggle.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(toggle.selected, 2);
|
||||||
|
toggle.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ToggleTest, Tab) {
|
||||||
|
Toggle toggle;
|
||||||
|
toggle.entries = {L"1", L"2", L"3"};
|
||||||
|
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(toggle.selected, 2);
|
||||||
|
toggle.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(toggle.selected, 2);
|
||||||
|
toggle.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(toggle.selected, 0);
|
||||||
|
toggle.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(toggle.selected, 2);
|
||||||
|
toggle.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(toggle.selected, 1);
|
||||||
|
toggle.OnEvent(Event::TabReverse);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user