Skip to content

Commit

Permalink
[vtbackend] Screen: Refactor CUU test case for VT sequence coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <christian@parpart.family>
  • Loading branch information
christianparpart committed Sep 21, 2023
1 parent ce47ad4 commit c4345f5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/vtbackend/Screen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ TEST_CASE("ScrollDown", "[screen]")
}
}

TEST_CASE("MoveCursorUp", "[screen]")
TEST_CASE("Sequence.CUU", "[screen]")
{
auto mock = MockTerm { PageSize { LineCount(5), ColumnCount(5) } };
auto& screen = mock.terminal.primaryScreen();
Expand All @@ -1767,48 +1767,54 @@ TEST_CASE("MoveCursorUp", "[screen]")
screen.moveCursorTo(LineOffset { 2 }, ColumnOffset { 1 });
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(2), ColumnOffset(1) });

SECTION("no-op")
SECTION("default")
{
screen.moveCursorUp(LineCount(0));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(2), ColumnOffset(1) });
mock.writeToScreen(CUU());
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(1), ColumnOffset(1) });
}

SECTION("0")
{
mock.writeToScreen(CUU());
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(1), ColumnOffset(1) });
}

SECTION("in-range")
{
screen.moveCursorUp(LineCount(1));
mock.writeToScreen(CUU(1));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(1), ColumnOffset(1) });
}

SECTION("overflow")
{
screen.moveCursorUp(LineCount(5));
mock.writeToScreen(CUU(5));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(0), ColumnOffset(1) });
}

SECTION("with margins")
{
mock.terminal.setTopBottomMargin(LineOffset { 1 }, LineOffset { 3 });
screen.moveCursorTo(LineOffset { 2 }, ColumnOffset { 1 });
mock.writeToScreen(DECSTBM(2, 4));
mock.writeToScreen(CUP(3, 2));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(2), ColumnOffset(1) });

SECTION("in-range")
{
screen.moveCursorUp(LineCount(1));
mock.writeToScreen(CUU(1));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(1), ColumnOffset(1) });
}

SECTION("overflow")
{
screen.moveCursorUp(LineCount(5));
mock.writeToScreen(CUU(5));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(1), ColumnOffset(1) });
}
}

SECTION("cursor already above margins")
{
mock.terminal.setTopBottomMargin(LineOffset { 2 }, LineOffset { 3 });
screen.moveCursorTo(LineOffset { 1 }, ColumnOffset { 2 });
screen.moveCursorUp(LineCount(1));
mock.writeToScreen(DECSTBM(3, 4));
mock.writeToScreen(CUP(2, 3));
mock.writeToScreen(CUU(1));
REQUIRE(screen.logicalCursorPosition() == CellLocation { LineOffset(0), ColumnOffset(2) });
}
}
Expand Down

0 comments on commit c4345f5

Please sign in to comment.