Skip to content

Commit

Permalink
Add subspan unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed Apr 25, 2023
1 parent 882adae commit 727c729
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/terminal/parser/ut_parser/StateMachineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class Microsoft::Console::VirtualTerminal::StateMachineTest
TEST_METHOD(PassThroughUnhandledSplitAcrossWrites);

TEST_METHOD(DcsDataStringsReceivedByHandler);

TEST_METHOD(VtParameterSubspanTest);
};

void StateMachineTest::TwoStateMachinesDoNotInterfereWithEachOther()
Expand Down Expand Up @@ -337,3 +339,38 @@ void StateMachineTest::DcsDataStringsReceivedByHandler()
// Verify the control characters were executed (if expected).
VERIFY_ARE_EQUAL(expectedExecuted, engine.executed);
}

void StateMachineTest::VtParameterSubspanTest()
{
const auto parameterList = std::vector<VTParameter>{ 12, 34, 56, 78 };
const auto parameterSpan = VTParameters{ parameterList.data(), parameterList.size() };

{
Log::Comment(L"Subspan from 0 gives all the parameters");
const auto subspan = parameterSpan.subspan(0);
VERIFY_ARE_EQUAL(4, subspan.size());
VERIFY_ARE_EQUAL(12, subspan.at(0));
VERIFY_ARE_EQUAL(34, subspan.at(1));
VERIFY_ARE_EQUAL(56, subspan.at(2));
VERIFY_ARE_EQUAL(78, subspan.at(3));
}
{
Log::Comment(L"Subspan from 2 gives the last 2 parameters");
const auto subspan = parameterSpan.subspan(2);
VERIFY_ARE_EQUAL(2, subspan.size());
VERIFY_ARE_EQUAL(56, subspan.at(0));
VERIFY_ARE_EQUAL(78, subspan.at(1));
}
{
Log::Comment(L"Subspan at the end of the range gives 1 omitted value");
const auto subspan = parameterSpan.subspan(4);
VERIFY_ARE_EQUAL(1, subspan.size());
VERIFY_IS_FALSE(subspan.at(0).has_value());
}
{
Log::Comment(L"Subspan past the end of the range gives 1 omitted value");
const auto subspan = parameterSpan.subspan(6);
VERIFY_ARE_EQUAL(1, subspan.size());
VERIFY_IS_FALSE(subspan.at(0).has_value());
}
}

0 comments on commit 727c729

Please sign in to comment.