mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Add ContainerTest
This commit is contained in:
parent
2cef695216
commit
e8ed0fbc6d
@ -157,6 +157,7 @@ if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
|
|||||||
add_executable(tests
|
add_executable(tests
|
||||||
src/ftxui/component/toggle_test.cpp
|
src/ftxui/component/toggle_test.cpp
|
||||||
src/ftxui/component/radiobox_test.cpp
|
src/ftxui/component/radiobox_test.cpp
|
||||||
|
src/ftxui/component/container_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
|
||||||
|
76
src/ftxui/component/container_test.cpp
Normal file
76
src/ftxui/component/container_test.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "ftxui/component/container.hpp"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
using namespace ftxui;
|
||||||
|
|
||||||
|
TEST(ContainerTest, HorizontalEvent) {
|
||||||
|
auto container = Container::Horizontal();
|
||||||
|
Component c0, c1, c2;
|
||||||
|
container.Add(&c0);
|
||||||
|
container.Add(&c1);
|
||||||
|
container.Add(&c2);
|
||||||
|
|
||||||
|
// With arrow key.
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::ArrowRight);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::ArrowLeft);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
|
||||||
|
// With arrow key in the wrong dimension.
|
||||||
|
container.OnEvent(Event::ArrowUp);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::ArrowDown);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
|
||||||
|
// With vim like characters.
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::Character('l'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::Character('l'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::Character('l'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::Character('h'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::Character('h'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::Character('h'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
|
||||||
|
// With vim like characters in the wrong direction.
|
||||||
|
container.OnEvent(Event::Character('j'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::Character('k'));
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
|
||||||
|
// With tab characters.
|
||||||
|
container.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::Tab);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c0);
|
||||||
|
container.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c2);
|
||||||
|
container.OnEvent(Event::TabReverse);
|
||||||
|
EXPECT_EQ(container.ActiveChild(), &c1);
|
||||||
|
container.OnEvent(Event::TabReverse);
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
using namespace ftxui;
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
|
||||||
TEST(ToggleTest, leftRightArrow) {
|
TEST(ToggleTest, leftRightArrow) {
|
||||||
|
Loading…
Reference in New Issue
Block a user