Add expect tests for Str.splitFirst

This commit is contained in:
kilianv 2022-09-01 16:57:19 +02:00
parent 23e430d91d
commit d89253779a
No known key found for this signature in database
GPG key ID: 8E1AEB931E0A6174

View file

@ -294,6 +294,18 @@ splitFirst = \haystack, needle ->
None ->
Err NotFound
# splitFirst when needle isn't in haystack
expect splitFirst "foo" "z" == Err NotFound
# splitFirst when haystack ends with needle repeated
expect splitFirst "foo" "o" == Ok { before: "f", after: "o" }
# splitFirst with multi-byte needle
expect splitFirst "hullabaloo" "ab" == Ok { before: "hull", after: "aloo" }
# splitFirst when needle is haystack
expect splitFirst "foo" "foo" == Ok { before: "", after: "" }
firstMatch : Str, Str -> [Some Nat, None]
firstMatch = \haystack, needle ->
haystackLength = Str.countUtf8Bytes haystack