Fix ButtonTest.Animate

This commit is contained in:
ArthurSonzogni 2022-04-28 11:03:39 +02:00
parent c2e1920449
commit e4c5c7b43b

View File

@ -94,6 +94,7 @@ TEST(ButtonTest, Basic) {
} }
TEST(ButtonTest, Animation) { TEST(ButtonTest, Animation) {
Terminal::SetColorSupport(Terminal::Color::TrueColor);
int press_count = 0; int press_count = 0;
std::string last_press = ""; std::string last_press = "";
auto option = ButtonOption::Animated(); auto option = ButtonOption::Animated();
@ -123,23 +124,23 @@ TEST(ButtonTest, Animation) {
{ {
Screen screen(12, 3); Screen screen(12, 3);
Render(screen, container->Render()); Render(screen, container->Render());
EXPECT_EQ( EXPECT_EQ(screen.ToString(),
screen.ToString(), "\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m \x1B[22m "
"\x1B[1m\x1B[38;5;250m\x1B[48;5;16m \x1B[22m " " \x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;"
"\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;250m\x1B[48;5;16m btn1 \x1B[22m " "0m btn1 \x1B[22m btn2 "
"btn2 \x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;250m\x1B[48;5;16m " "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;"
"\x1B[22m \x1B[39m\x1B[49m"); "0m \x1B[22m \x1B[39m\x1B[49m");
} }
selected = 1; selected = 1;
{ {
Screen screen(12, 3); Screen screen(12, 3);
Render(screen, container->Render()); Render(screen, container->Render());
EXPECT_EQ( EXPECT_EQ(screen.ToString(),
screen.ToString(), "\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m \x1B[1m "
"\x1B[38;5;250m\x1B[48;5;16m \x1B[1m " "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;"
"\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m btn1 \x1B[1m " "0m btn1 \x1B[1m btn2 "
"btn2 \x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m " "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;"
"\x1B[1m \x1B[22m\x1B[39m\x1B[49m"); "0m \x1B[1m \x1B[22m\x1B[39m\x1B[49m");
} }
animation::Params params(2s); animation::Params params(2s);
container->OnAnimation(params); container->OnAnimation(params);
@ -148,11 +149,13 @@ TEST(ButtonTest, Animation) {
Render(screen, container->Render()); Render(screen, container->Render());
EXPECT_EQ( EXPECT_EQ(
screen.ToString(), screen.ToString(),
"\x1B[38;5;250m\x1B[48;5;16m \x1B[1m\x1B[38;5;231m\x1B[48;5;244m " "\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m "
" \x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m btn1 " "\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m "
"\x1B[1m\x1B[38;5;231m\x1B[48;5;244m btn2 " "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m "
"\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m " "btn1 \x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m btn2 "
"\x1B[1m\x1B[38;5;231m\x1B[48;5;244m \x1B[22m\x1B[39m\x1B[49m"); "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m "
" \x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m "
"\x1B[22m\x1B[39m\x1B[49m");
} }
EXPECT_EQ(selected, 1); EXPECT_EQ(selected, 1);
container->OnEvent(MousePressed(3, 1)); container->OnEvent(MousePressed(3, 1));
@ -160,25 +163,29 @@ TEST(ButtonTest, Animation) {
{ {
Screen screen(12, 3); Screen screen(12, 3);
Render(screen, container->Render()); Render(screen, container->Render());
EXPECT_EQ(screen.ToString(), EXPECT_EQ(
"\x1B[1m\x1B[38;5;253m\x1B[48;5;238m " screen.ToString(),
"\x1B[22m\x1B[38;5;231m\x1B[48;5;244m " "\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m "
"\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;253m\x1B[48;5;238m btn1 " "\x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m "
"\x1B[22m\x1B[38;5;231m\x1B[48;5;244m btn2 " "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m "
"\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;253m\x1B[48;5;238m " "btn1 \x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m btn2 "
"\x1B[22m\x1B[38;5;231m\x1B[48;5;244m \x1B[39m\x1B[49m"); "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m "
" \x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m "
"\x1B[39m\x1B[49m");
} }
container->OnAnimation(params); container->OnAnimation(params);
{ {
Screen screen(12, 3); Screen screen(12, 3);
Render(screen, container->Render()); Render(screen, container->Render());
EXPECT_EQ(screen.ToString(), EXPECT_EQ(
"\x1B[1m\x1B[38;5;231m\x1B[48;5;244m " screen.ToString(),
"\x1B[22m\x1B[38;5;250m\x1B[48;5;16m " "\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m "
"\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;231m\x1B[48;5;244m btn1 " "\x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m "
"\x1B[22m\x1B[38;5;250m\x1B[48;5;16m btn2 " "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;"
"\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;231m\x1B[48;5;244m " "128m btn1 \x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m btn2 "
"\x1B[22m\x1B[38;5;250m\x1B[48;5;16m \x1B[39m\x1B[49m"); "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;"
"128m \x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m "
"\x1B[39m\x1B[49m");
} }
} }