Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider empty strings in Text.indexOf #4101

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parser-typechecker/src/Unison/Util/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ toText (Text t) = T.concat (chunkToText <$> unfoldr R.uncons t)
{-# INLINE toText #-}

indexOf :: Text -> Text -> Maybe Word64
indexOf "" _ = Just 0
indexOf needle haystack =
case TL.breakOn needle' haystack' of
(_, "") -> Nothing
Expand Down
2 changes: 2 additions & 0 deletions unison-src/transcripts/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ test> Text.tests.indexOf =
needle6 = "0c"
needle7 = haystack
needle8 = "lopez"
needle9 = ""
checks [
Text.indexOf needle1 haystack == Some 0,
Text.indexOf needle2 haystack == Some 2,
Expand All @@ -271,6 +272,7 @@ test> Text.tests.indexOf =
Text.indexOf needle6 haystack == Some 22,
Text.indexOf needle7 haystack == Some 0,
Text.indexOf needle8 haystack == None,
Text.indexOf needle9 haystack == Some 0,
]

test> Text.tests.indexOfEmoji =
Expand Down
2 changes: 2 additions & 0 deletions unison-src/transcripts/builtins.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ test> Text.tests.indexOf =
needle6 = "0c"
needle7 = haystack
needle8 = "lopez"
needle9 = ""
checks [
Text.indexOf needle1 haystack == Some 0,
Text.indexOf needle2 haystack == Some 2,
Expand All @@ -252,6 +253,7 @@ test> Text.tests.indexOf =
Text.indexOf needle6 haystack == Some 22,
Text.indexOf needle7 haystack == Some 0,
Text.indexOf needle8 haystack == None,
Text.indexOf needle9 haystack == Some 0,
]

test> Text.tests.indexOfEmoji =
Expand Down