From e51c18166e209302f329ed3c074f96075351a95a Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 9 Oct 2025 16:50:19 +0100 Subject: [PATCH] begin adding tests based on tutorial by freeCodeCamp --- test/regex-tests.sml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/regex-tests.sml b/test/regex-tests.sml index d3375d2..b9a7952 100644 --- a/test/regex-tests.sml +++ b/test/regex-tests.sml @@ -205,11 +205,38 @@ struct doesNotRecogniseUnescaped ("-", "hello - world")) ] + (* tests based on regex tutorial by FreeCodeCamp *) + val freeCodeCampTests = describe "regex freeCodeCamp tests" + [test "The dog chased the cat" (fn _ => + let + (* arrange *) + val sentence = "The dog chased the cat" + val regexString = "the" + val caseSensitiveDfa = CsDfa.fromString regexString + val caseInsensitiveDfa = CiDfa.fromString regexString + + (* act *) + val caseSensitiveMatches = + CsDfa.matchString (caseSensitiveDfa, sentence) + val caseInsensitiveMatches = + CiDfa.matchString (caseInsensitiveDfa, sentence) + + (* assert *) + val expectedCaseSensitive = [(15, 17)] + val expectedCaseInsensitive = [(0, 2), (15, 17)] + val expected = + caseSensitiveMatches = expectedCaseSensitive + andalso caseInsensitiveMatches = expectedCaseInsensitive + in + Expect.isTrue (expected) + end)] + val tests = [ caseInsensitiveTests , caseSensitiveTests , endMarkerTests , escapeSequenceTests , metacharacterEscapeTest + , freeCodeCampTests ] end