@@ -51,6 +51,8 @@ class TerminalCoreUnitTests::TerminalBufferTests final
51
51
52
52
TEST_METHOD (TestGetReverseTab);
53
53
54
+ TEST_METHOD (TestURLPatternDetection);
55
+
54
56
TEST_METHOD_SETUP (MethodSetup)
55
57
{
56
58
// STEP 1: Set up the Terminal
@@ -594,3 +596,34 @@ void TerminalBufferTests::TestGetReverseTab()
594
596
L" Cursor adjusted to last item in the sample list from position beyond end." );
595
597
}
596
598
}
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