Skip to content

Commit dd56e4a

Browse files
committed
add test
1 parent ad61881 commit dd56e4a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class TerminalCoreUnitTests::TerminalBufferTests final
5151

5252
TEST_METHOD(TestGetReverseTab);
5353

54+
TEST_METHOD(TestURLPatternDetection);
55+
5456
TEST_METHOD_SETUP(MethodSetup)
5557
{
5658
// STEP 1: Set up the Terminal
@@ -594,3 +596,34 @@ void TerminalBufferTests::TestGetReverseTab()
594596
L"Cursor adjusted to last item in the sample list from position beyond end.");
595597
}
596598
}
599+
600+
void TerminalBufferTests::TestURLPatternDetection()
601+
{
602+
using namespace std::string_view_literals;
603+
604+
constexpr auto BeforeStr = L"<Before>"sv;
605+
constexpr auto UrlStr = L"https://www.contoso.com"sv;
606+
constexpr auto AfterStr = L"<After>"sv;
607+
constexpr auto urlStartX = BeforeStr.size();
608+
constexpr auto urlEndX = BeforeStr.size() + UrlStr.size() - 1;
609+
610+
auto& termSm = *term->_stateMachine;
611+
termSm.ProcessString(fmt::format(FMT_COMPILE(L"{}{}{}"), BeforeStr, UrlStr, AfterStr));
612+
term->UpdatePatternsUnderLock();
613+
614+
std::wstring result;
615+
616+
result = term->GetHyperlinkAtBufferPosition(til::point{ urlStartX - 1, 0 });
617+
VERIFY_IS_TRUE(result.empty(), L"URL is not detected before the actual URL.");
618+
619+
result = term->GetHyperlinkAtBufferPosition(til::point{ urlStartX, 0 });
620+
VERIFY_IS_TRUE(!result.empty(), L"A URL is detected at the start position.");
621+
VERIFY_ARE_EQUAL(result, UrlStr, L"Detected URL matches the given URL.");
622+
623+
result = term->GetHyperlinkAtBufferPosition(til::point{ urlEndX, 0 });
624+
VERIFY_IS_TRUE(!result.empty(), L"A URL is detected at the end position.");
625+
VERIFY_ARE_EQUAL(result, UrlStr, L"Detected URL matches the given URL.");
626+
627+
result = term->GetHyperlinkAtBufferPosition(til::point{ urlEndX + 1, 0 });
628+
VERIFY_IS_TRUE(result.empty(), L"URL is not detected after the actual URL.");
629+
}

0 commit comments

Comments
 (0)