diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 6130d2df3f93..7db9375412d5 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -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;