Skip to content

Commit

Permalink
Add some unit tests for the paging ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed Mar 9, 2024
1 parent bb313cc commit 5b1276c
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/terminal/adapter/ut_adapter/adapterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,89 @@ class AdapterTest
VERIFY_IS_TRUE(_pDispatch->DoVsCodeAction(LR"(Completions;10;20;30;{ "foo": "what;ever", "bar": 2 })"));
}

TEST_METHOD(PageMovementTests)
{
_testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER);
auto& pages = _pDispatch->_pages;
const auto startPos = pages.ActivePage().Cursor().GetPosition();
const auto homePos = til::point{ 0, pages.ActivePage().Top() };

// Testing PPA (page position absolute)
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"Initial page is 1");
_pDispatch->PagePositionAbsolute(3);
VERIFY_ARE_EQUAL(3, pages.ActivePage().Number(), L"PPA 3 moves to page 3");
_pDispatch->PagePositionAbsolute(VTParameter{});
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"PPA with omitted page moves to 1");
_pDispatch->PagePositionAbsolute(9999);
VERIFY_ARE_EQUAL(6, pages.ActivePage().Number(), L"PPA is clamped at page 6");
VERIFY_ARE_EQUAL(startPos, pages.ActivePage().Cursor().GetPosition(), L"Cursor position never changes");

_testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER);
_pDispatch->PagePositionAbsolute(1); // Reset to page 1

// Testing PPR (page position relative)
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"Initial page is 1");
_pDispatch->PagePositionRelative(2);
VERIFY_ARE_EQUAL(3, pages.ActivePage().Number(), L"PPR 2 moves forward 2 pages");
_pDispatch->PagePositionRelative(VTParameter{});
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number(), L"PPR with omitted count moves forward 1");
_pDispatch->PagePositionRelative(9999);
VERIFY_ARE_EQUAL(6, pages.ActivePage().Number(), L"PPR is clamped at page 6");
VERIFY_ARE_EQUAL(startPos, pages.ActivePage().Cursor().GetPosition(), L"Cursor position never changes");

_testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER);

// Testing PPB (page position back)
VERIFY_ARE_EQUAL(6, pages.ActivePage().Number(), L"Initial page is 6");
_pDispatch->PagePositionBack(2);
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number(), L"PPB 2 moves back 2 pages");
_pDispatch->PagePositionBack(VTParameter{});
VERIFY_ARE_EQUAL(3, pages.ActivePage().Number(), L"PPB with omitted count moves back 1");
_pDispatch->PagePositionBack(9999);
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"PPB is clamped at page 1");
VERIFY_ARE_EQUAL(startPos, pages.ActivePage().Cursor().GetPosition(), L"Cursor position never changes");

_testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER);

// Testing NP (next page)
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"Initial page is 1");
_pDispatch->NextPage(2);
VERIFY_ARE_EQUAL(3, pages.ActivePage().Number(), L"NP 2 moves forward 2 pages");
_pDispatch->NextPage(VTParameter{});
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number(), L"NP with omitted count moves forward 1");
_pDispatch->NextPage(9999);
VERIFY_ARE_EQUAL(6, pages.ActivePage().Number(), L"NP is clamped at page 6");
VERIFY_ARE_EQUAL(homePos, pages.ActivePage().Cursor().GetPosition(), L"Cursor position is reset to home");

_testGetSet->PrepData(CursorX::XCENTER, CursorY::YCENTER);

// Testing PP (preceding page)
VERIFY_ARE_EQUAL(6, pages.ActivePage().Number(), L"Initial page is 6");
_pDispatch->PrecedingPage(2);
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number(), L"PP 2 moves back 2 pages");
_pDispatch->PrecedingPage(VTParameter{});
VERIFY_ARE_EQUAL(3, pages.ActivePage().Number(), L"PP with omitted count moves back 1");
_pDispatch->PrecedingPage(9999);
VERIFY_ARE_EQUAL(1, pages.ActivePage().Number(), L"PP is clamped at page 1");
VERIFY_ARE_EQUAL(homePos, pages.ActivePage().Cursor().GetPosition(), L"Cursor position is reset to home");

// Testing DECPCCM (page cursor coupling mode)
_pDispatch->SetMode(DispatchTypes::ModeParams::DECPCCM_PageCursorCouplingMode);
_pDispatch->PagePositionAbsolute(2);
VERIFY_ARE_EQUAL(2, pages.ActivePage().Number());
VERIFY_ARE_EQUAL(2, pages.VisiblePage().Number(), L"Visible page should follow active if DECPCCM set");
_pDispatch->ResetMode(DispatchTypes::ModeParams::DECPCCM_PageCursorCouplingMode);
_pDispatch->PagePositionAbsolute(4);
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number());
VERIFY_ARE_EQUAL(2, pages.VisiblePage().Number(), L"Visible page should not change if DECPCCM reset");
_pDispatch->SetMode(DispatchTypes::ModeParams::DECPCCM_PageCursorCouplingMode);
VERIFY_ARE_EQUAL(4, pages.ActivePage().Number());
VERIFY_ARE_EQUAL(4, pages.VisiblePage().Number(), L"Active page should become visible when DECPCCM set");

// Reset to page 1
_pDispatch->PagePositionAbsolute(1);
}

private:
TerminalInput _terminalInput;
std::unique_ptr<TestGetSet> _testGetSet;
Expand Down

0 comments on commit 5b1276c

Please sign in to comment.