Add some expects to Str

This commit is contained in:
Richard Feldman 2022-08-04 22:29:17 -04:00 committed by Folkert
parent d415c72fdc
commit 807f73fecf
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

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