Fix tests.

This commit is contained in:
ArthurSonzogni 2024-12-25 19:00:20 +01:00
parent fe7d67ac6a
commit a3cc6df32b
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
2 changed files with 33 additions and 32 deletions

View File

@ -145,7 +145,7 @@ void Selection::AddPart(const std::string& part, int y, int left, int right) {
} }
[&] { [&] {
if (parts_.str().empty()) { if (parts_.str().empty()) {
parts_ << "[" + part + "]"; parts_ << part;
return; return;
} }
@ -155,11 +155,11 @@ void Selection::AddPart(const std::string& part, int y, int left, int right) {
} }
if (x_ == left + 1) { if (x_ == left + 1) {
parts_ << "|" << part; parts_ << part;
return; return;
} }
parts_ << "-" << part; parts_ << part;
}(); }();
y_ = y; y_ = y;
x_ = right; x_ = right;

View File

@ -26,7 +26,7 @@ Event MousePressed(int x, int y) {
mouse.control = false; mouse.control = false;
mouse.x = x; mouse.x = x;
mouse.y = y; mouse.y = y;
return Event::Mouse("jjj", mouse); return Event::Mouse("", mouse);
} }
Event MouseReleased(int x, int y) { Event MouseReleased(int x, int y) {
@ -38,7 +38,7 @@ Event MouseReleased(int x, int y) {
mouse.control = false; mouse.control = false;
mouse.x = x; mouse.x = x;
mouse.y = y; mouse.y = y;
return Event::Mouse("jjj", mouse); return Event::Mouse("", mouse);
} }
Event MouseMove(int x, int y) { Event MouseMove(int x, int y) {
@ -50,7 +50,7 @@ Event MouseMove(int x, int y) {
mouse.control = false; mouse.control = false;
mouse.x = x; mouse.x = x;
mouse.y = y; mouse.y = y;
return Event::Mouse("jjj", mouse); return Event::Mouse("", mouse);
} }
} // namespace } // namespace
@ -155,65 +155,66 @@ TEST(SelectionTest, StyleSelection) {
} }
TEST(SelectionTest, VBoxSelection) { TEST(SelectionTest, VBoxSelection) {
auto component = Renderer([&] { auto element = vbox({
return vbox({text("Lorem ipsum dolor"), text("Ut enim ad minim")}); text("Lorem ipsum dolor"),
text("Ut enim ad minim"),
}); });
auto screen = ScreenInteractive::FixedSize(20, 2); auto screen = ScreenInteractive::FixedSize(20, 2);
Selection selection(2, 0, 2, 1); Selection selection(2, 0, 2, 1);
Render(screen, element.get(), selection);
Render(screen, component->Render().get(), selection); EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt ");
EXPECT_EQ(screen.ToString(), EXPECT_EQ(screen.ToString(),
"Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n\x1B[7mUt \x1B[27menim ad " "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n"
"minim "); "\x1B[7mUt \x1B[27menim ad minim ");
} }
TEST(SelectionTest, VBoxSaturatedSelection) { TEST(SelectionTest, VBoxSaturatedSelection) {
auto component = Renderer([&] { auto element = vbox({
return vbox({text("Lorem ipsum dolor"), text("Ut enim ad minim"), text("Lorem ipsum dolor"),
text("Duis aute irure")}); text("Ut enim ad minim"),
text("Duis aute irure"),
}); });
auto screen = ScreenInteractive::FixedSize(20, 3); auto screen = ScreenInteractive::FixedSize(20, 3);
Selection selection(2, 0, 2, 2); Selection selection(2, 0, 2, 2);
Render(screen, element.get(), selection);
Render(screen, component->Render().get(), selection); EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt enim ad minim\nDui");
EXPECT_EQ(screen.ToString(), EXPECT_EQ(screen.ToString(),
"Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n\x1B[7mUt enim ad " "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n"
"minim\x1B[27m \r\n\x1B[7mDui\x1B[27ms aute irure "); "\x1B[7mUt enim ad minim\x1B[27m \r\n"
"\x1B[7mDui\x1B[27ms aute irure ");
} }
TEST(SelectionTest, HBoxSelection) { TEST(SelectionTest, HBoxSelection) {
auto component = Renderer([&] { auto element = hbox({
return hbox({text("Lorem ipsum dolor"), text("Ut enim ad minim")}); text("Lorem ipsum dolor"),
text("Ut enim ad minim"),
}); });
auto screen = ScreenInteractive::FixedSize(40, 1); auto screen = ScreenInteractive::FixedSize(40, 1);
Selection selection(2, 0, 20, 0); Selection selection(2, 0, 20, 0);
Render(screen, element.get(), selection);
Render(screen, component->Render().get(), selection); EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt e");
EXPECT_EQ(screen.ToString(), EXPECT_EQ(screen.ToString(),
"Lo\x1B[7mrem ipsum dolorUt e\x1B[27mnim ad minim "); "Lo\x1B[7mrem ipsum dolorUt e\x1B[27mnim ad minim ");
} }
TEST(SelectionTest, HBoxSaturatedSelection) { TEST(SelectionTest, HBoxSaturatedSelection) {
auto component = Renderer([&] { auto element = hbox({
return hbox({text("Lorem ipsum dolor"), text("Ut enim ad minim"), text("Lorem ipsum dolor"),
text("Duis aute irure")}); text("Ut enim ad minim"),
text("Duis aute irure"),
}); });
auto screen = ScreenInteractive::FixedSize(60, 1); auto screen = ScreenInteractive::FixedSize(60, 1);
Selection selection(2, 0, 35, 0); Selection selection(2, 0, 35, 0);
Render(screen, element.get(), selection);
Render(screen, component->Render().get(), selection); EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt enim ad minimDui");
EXPECT_EQ(screen.ToString(), EXPECT_EQ(screen.ToString(),
"Lo\x1B[7mrem ipsum dolorUt enim ad minimDui\x1B[27ms aute irure " "Lo\x1B[7mrem ipsum dolorUt enim ad minimDui\x1B[27ms aute irure "
" "); " ");