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

View File

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