begin adding regex tests based on freeCodeCamp tutorial

This commit is contained in:
2025-10-09 16:56:36 +01:00
parent e51c18166e
commit c427cd25fa

View File

@@ -207,7 +207,7 @@ struct
(* tests based on regex tutorial by FreeCodeCamp *) (* tests based on regex tutorial by FreeCodeCamp *)
val freeCodeCampTests = describe "regex freeCodeCamp tests" val freeCodeCampTests = describe "regex freeCodeCamp tests"
[test "The dog chased the cat" (fn _ => [ test "The dog chased the cat" (fn _ =>
let let
(* arrange *) (* arrange *)
val sentence = "The dog chased the cat" val sentence = "The dog chased the cat"
@@ -229,7 +229,53 @@ struct
andalso caseInsensitiveMatches = expectedCaseInsensitive andalso caseInsensitiveMatches = expectedCaseInsensitive
in in
Expect.isTrue (expected) Expect.isTrue (expected)
end)] end)
, test "Somewhere Waldo is hiding in this text." (fn _ =>
let
(* arrange *)
val sentence = "Somewhere Waldo is hiding in this text."
val regexString = "Waldo"
val dfa = CsDfa.fromString regexString
(* act *)
val matches = CsDfa.matchString (dfa, sentence)
(* assert *)
val expectedMatches = [(10, 14)]
in
Expect.isTrue (expected = matches)
end)
, test "James has a pet cat." (fn _ =>
let
(* arrange *)
val sentence = "James has a pet cat."
val regexString = "dog|cat|bird|fish"
val dfa = CsDfa.fromString regexString
(* act *)
val matches = CsDfa.matchString (dfa, sentence)
(* assert *)
val expectedMatches = [(16, 18)]
in
Expect.isTrue (expected = matches)
end)
, test "Ignore Case While Matching" (fn _ =>
let
(* arrange *)
val sentence = "freeCodeCamp"
val regexString = "freecodecamp"
val dfa = CiDfa.fromString regexString
(* act *)
val matches = CiDfa.matchString (dfa, sentence)
(* assert *)
val expectedMatches = [(0, 11)]
in
Expect.isTrue (expected = matches)
end)
]
val tests = val tests =
[ caseInsensitiveTests [ caseInsensitiveTests