Add coverage for menu and resizable_split.

This commit is contained in:
ArthurSonzogni
2022-04-27 23:00:29 +02:00
parent d0890f94d1
commit c33e805a76
4 changed files with 194 additions and 1 deletions

View File

@@ -14,6 +14,8 @@
namespace ftxui {
using namespace std::chrono_literals;
TEST(MenuTest, RemoveEntries) {
int focused_entry = 0;
int selected = 0;
@@ -90,6 +92,84 @@ TEST(MenuTest, Directions) {
}
}
TEST(MenuTest, AnimationsHorizontal) {
int selected = 0;
std::vector<std::string> entries = {"1", "2", "3"};
auto option = MenuOption::HorizontalAnimated();
auto menu = Menu(&entries, &selected, &option);
{
Screen screen(4, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[1m\x1B[7m1\x1B[22m\x1B[27m \x1B[2m2\x1B[22m "
"\r\n\x1B[97m\x1B[49m\xE2\x94\x80\x1B[90m\x1B["
"49m\xE2\x95\xB6\xE2\x94\x80\xE2\x94\x80\x1B[39m\x1B[49m\r\n ");
}
selected = 1;
{
Screen screen(4, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[7m1\x1B[27m \x1B[1m2\x1B[22m "
"\r\n\x1B[97m\x1B[49m\xE2\x94\x80\x1B[90m\x1B["
"49m\xE2\x95\xB6\xE2\x94\x80\xE2\x94\x80\x1B[39m\x1B[49m\r\n ");
}
animation::Params params(2s);
menu->OnAnimation(params);
{
Screen screen(4, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[7m1\x1B[27m \x1B[1m2\x1B[22m "
"\r\n\x1B[90m\x1B[49m\xE2\x94\x80\xE2\x95\xB4\x1B[97m\x1B["
"49m\xE2\x94\x80\x1B[90m\x1B[49m\xE2\x95\xB6\x1B[39m\x1B[49m\r\n ");
}
}
TEST(MenuTest, AnimationsVertical) {
int selected = 0;
std::vector<std::string> entries = {"1", "2", "3"};
auto option = MenuOption::VerticalAnimated();
auto menu = Menu(&entries, &selected, &option);
{
Screen screen(10, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[90m\x1B[49m\xE2\x94\x82\x1B[1m\x1B[7m\x1B[39m\x1B[49m1\x1B["
"22m\x1B[27m "
"\r\n\x1B[97m\x1B[49m\xE2\x95\xB7\x1B[2m\x1B[39m\x1B[49m2\x1B[22m "
" \r\n\x1B[97m\x1B[49m\xE2\x94\x82\x1B[2m\x1B[39m\x1B[49m3\x1B[22m "
" ");
}
selected = 1;
{
Screen screen(10, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[90m\x1B[49m\xE2\x94\x82\x1B[7m\x1B[39m\x1B[49m1\x1B[27m "
"\r\n\x1B[97m\x1B[49m\xE2\x95\xB7\x1B[1m\x1B[39m\x1B[49m2\x1B[22m "
" \r\n\x1B[97m\x1B[49m\xE2\x94\x82\x1B[2m\x1B[39m\x1B[49m3\x1B[22m "
" ");
}
animation::Params params(2s);
menu->OnAnimation(params);
{
Screen screen(10, 3);
Render(screen, menu->Render());
EXPECT_EQ(
screen.ToString(),
"\x1B[97m\x1B[49m\xE2\x95\xB5\x1B[7m\x1B[39m\x1B[49m1\x1B[27m "
"\r\n\x1B[90m\x1B[49m\xE2\x94\x82\x1B[1m\x1B[39m\x1B[49m2\x1B[22m "
" \r\n\x1B[97m\x1B[49m\xE2\x95\xB7\x1B[2m\x1B[39m\x1B[49m3\x1B[22m "
" ");
}
}
} // namespace ftxui
// Copyright 2022 Arthur Sonzogni. All rights reserved.