From f03b02c8aba5e77b22c734f835e79e2b7c9b14dc Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 9 Nov 2022 19:21:20 +0100 Subject: [PATCH] String.split: Improve documentation - Add more examples - Fix typo --- CHANGELOG.md | 3 +++ src/Data/String/Common.purs | 9 ++++++++- test/Test/Data/String.purs | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f36a713..37c84da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ New features: Bugfixes: Other improvements: +- `split` (#165) + - Add more examples. + - Fix typo in documentation. ## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16 diff --git a/src/Data/String/Common.purs b/src/Data/String/Common.purs index 9e3132e..f419f34 100644 --- a/src/Data/String/Common.purs +++ b/src/Data/String/Common.purs @@ -56,11 +56,18 @@ foreign import replace :: Pattern -> Replacement -> String -> String -- | ``` foreign import replaceAll :: Pattern -> Replacement -> String -> String --- | Returns the substrings of the second string separated along occurences +-- | Returns the substrings of the second string separated along occurrences -- | of the first string. -- | -- | ```purescript +-- | -- single match -- | split (Pattern " ") "hello world" == ["hello", "world"] +-- | -- multiple matches +-- | split (Pattern " | ") "foo | bar | baz" == ["foo", "bar", "baz"] +-- | -- no match +-- | split (Pattern "baz") "foo bar" == ["foo bar"] +-- | -- empty string +-- | split (Pattern "") "foo bar" == ["f","o","o"," ","b","a","r"] -- | ``` foreign import split :: Pattern -> String -> Array String diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index 5c73153..82e1426 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -99,6 +99,10 @@ testString = do { actual: S.split (Pattern "d") "abc" , expected: ["abc"] } + assertEqual + { actual: S.split (Pattern "--") "a--b--c" + , expected: ["a", "b", "c"] + } log "toLower" assertEqual