begin adding tests for regex

This commit is contained in:
2025-10-09 05:34:32 +01:00
parent 70215fbc0a
commit 250ae239be
5 changed files with 89 additions and 3 deletions

43
test/regex-tests.sml Normal file
View File

@@ -0,0 +1,43 @@
structure RegexTests =
struct
open Railroad
open Railroad.Test
structure CiDfa = CaseInsensitiveDfa
structure CsDfa = CaseSensitiveDfa
val caseInsensitiveTests = describe "case insensitive regex"
[ test "recognises word 'hello' in string 'Hello world'" (fn _ =>
let
(* arrange *)
val regexString = "hello"
val dfa = CiDfa.fromString regexString
val inputString = "Hello world"
(* act *)
val matches = CiDfa.matchString (dfa, inputString)
(* assert *)
val expectedMatches = [(0, 4)]
in
Expect.isTrue (matches = expectedMatches)
end)
, test "recognises word 'world' in string 'HELLO WORLD'" (fn _ =>
let
(* arrange *)
val regexString = "world"
val dfa = CiDfa.fromString regexString
val inputString = "HELLO WORLD"
(* act *)
val matches = CiDfa.matchString (dfa, inputString)
(* assert *)
val expectedMatches = [(6, 10)]
in
Expect.isTrue (matches = expectedMatches)
end)
]
val tests = [caseInsensitiveTests]
end

View File

@@ -6,7 +6,12 @@ struct
fun main () =
let
val tests =
List.concat [NormalMove.tests, NormalDelete.tests, Regression.tests]
List.concat
[ NormalMove.tests
, NormalDelete.tests
, Regression.tests
, RegexTests.tests
]
val tests = concat tests
in
runWithConfig [Configuration.PrintPassed false] tests