mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Add expect tests for Str.splitFirst
This commit is contained in:
parent
23e430d91d
commit
d89253779a
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue