diff --git a/bower.json b/bower.json index f2dfc6d..d3aa1f9 100644 --- a/bower.json +++ b/bower.json @@ -17,12 +17,12 @@ "package.json" ], "dependencies": { - "purescript-either": "^1.0.0", - "purescript-maybe": "^1.0.0" + "purescript-either": "^2.0.0", + "purescript-maybe": "^2.0.0" }, "devDependencies": { - "purescript-assert": "^1.0.0", - "purescript-console": "^1.0.0", + "purescript-assert": "^2.0.0", + "purescript-console": "^2.0.0", "purescript-partial": "^1.1.2" } } diff --git a/src/Data/Char.js b/src/Data/Char.js index 4c982b1..15f12b2 100644 --- a/src/Data/Char.js +++ b/src/Data/Char.js @@ -1,8 +1,5 @@ -/* global exports */ "use strict"; -// module Data.Char - exports.toCharCode = function (c) { return c.charCodeAt(0); }; diff --git a/src/Data/String.js b/src/Data/String.js index eb3fb93..fd42223 100644 --- a/src/Data/String.js +++ b/src/Data/String.js @@ -1,8 +1,5 @@ -/* global exports */ "use strict"; -// module Data.String - exports._charAt = function (just) { return function (nothing) { return function (i) { @@ -114,6 +111,14 @@ exports.replace = function (s1) { }; }; +exports.replaceAll = function (s1) { + return function (s2) { + return function (s3) { + return s3.replace(new RegExp(s1.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), s2); + }; + }; +}; + exports.take = function (n) { return function (s) { return s.substr(0, n); diff --git a/src/Data/String.purs b/src/Data/String.purs index b7d8213..849f9e8 100644 --- a/src/Data/String.purs +++ b/src/Data/String.purs @@ -2,7 +2,9 @@ -- | A String represents a sequence of characters. -- | For details of the underlying implementation, see [String Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String). module Data.String - ( charAt + ( Pattern(..) + , Replacement(..) + , charAt , charCodeAt , fromCharArray , toChar @@ -17,6 +19,7 @@ module Data.String , singleton , localeCompare , replace + , replaceAll , take , takeWhile , drop @@ -36,17 +39,39 @@ module Data.String import Prelude import Data.Maybe (Maybe(..), isJust) +import Data.Newtype (class Newtype) import Data.String.Unsafe as U +-- | A newtype used in cases where there is a string to be matched. +newtype Pattern = Pattern String + +derive instance eqPattern :: Eq Pattern +derive instance ordPattern :: Ord Pattern +derive instance newtypePattern :: Newtype Pattern _ + +instance showPattern :: Show Pattern where + show (Pattern s) = "(Pattern " <> s <> ")" + +-- | A newtype used in cases to specify a replacement for a pattern. +newtype Replacement = Replacement String + +derive instance eqReplacement :: Eq Replacement +derive instance ordReplacement :: Ord Replacement +derive instance newtypeReplacement :: Newtype Replacement _ + +instance showReplacement :: Show Replacement where + show (Replacement s) = "(Replacement " <> s <> ")" + -- | Returns the character at the given index, if the index is within bounds. charAt :: Int -> String -> Maybe Char charAt = _charAt Just Nothing -foreign import _charAt :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> Int - -> String - -> Maybe Char +foreign import _charAt + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Int + -> String + -> Maybe Char -- | Returns a string of length `1` containing the given character. foreign import singleton :: Char -> String @@ -56,19 +81,21 @@ foreign import singleton :: Char -> String charCodeAt :: Int -> String -> Maybe Int charCodeAt = _charCodeAt Just Nothing -foreign import _charCodeAt :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> Int - -> String - -> Maybe Int +foreign import _charCodeAt + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Int + -> String + -> Maybe Int toChar :: String -> Maybe Char toChar = _toChar Just Nothing -foreign import _toChar :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> String - -> Maybe Char +foreign import _toChar + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> String + -> Maybe Char -- | Returns `true` if the given string is empty. null :: String -> Boolean @@ -81,7 +108,7 @@ uncons "" = Nothing uncons s = Just { head: U.charAt zero s, tail: drop one s } -- | Returns the longest prefix (possibly empty) of characters that satisfy --- | the predicate: +-- | the predicate. takeWhile :: (Char -> Boolean) -> String -> String takeWhile p s = take (count p s) s @@ -91,80 +118,82 @@ dropWhile p s = drop (count p s) s -- | If the string starts with the given prefix, return the portion of the -- | string left after removing it, as a Just value. Otherwise, return Nothing. --- | * `stripPrefix "http:" "http://purescript.org" == Just "//purescript.org"` --- | * `stripPrefix "http:" "https://purescript.org" == Nothing` -stripPrefix :: String -> String -> Maybe String -stripPrefix prefix str = +-- | * `stripPrefix (Pattern "http:") "http://purescript.org" == Just "//purescript.org"` +-- | * `stripPrefix (Pattern "http:") "https://purescript.org" == Nothing` +stripPrefix :: Pattern -> String -> Maybe String +stripPrefix prefix@(Pattern prefixS) str = case indexOf prefix str of - Just 0 -> Just $ drop (length prefix) str - _ -> Nothing + Just 0 -> Just $ drop (length prefixS) str + _ -> Nothing -- | If the string ends with the given suffix, return the portion of the -- | string left after removing it, as a Just value. Otherwise, return Nothing. --- | * `stripSuffix ".exe" "psc.exe" == Just "psc"` --- | * `stripSuffix ".exe" "psc" == Nothing` -stripSuffix :: String -> String -> Maybe String -stripSuffix suffix str = +-- | * `stripSuffix (Pattern ".exe") "psc.exe" == Just "psc"` +-- | * `stripSuffix (Pattern ".exe") "psc" == Nothing` +stripSuffix :: Pattern -> String -> Maybe String +stripSuffix suffix@(Pattern suffixS) str = case lastIndexOf suffix str of - Just x | x == length str - length suffix -> - Just $ take x str - _ -> - Nothing + Just x | x == length str - length suffixS -> Just $ take x str + _ -> Nothing -- | Converts an array of characters into a string. foreign import fromCharArray :: Array Char -> String -- | Checks whether the first string exists in the second string. -contains :: String -> String -> Boolean -contains x s = isJust (indexOf x s) +contains :: Pattern -> String -> Boolean +contains pat = isJust <<< indexOf pat -- | Returns the index of the first occurrence of the first string in the -- | second string. Returns `Nothing` if there is no match. -indexOf :: String -> String -> Maybe Int +indexOf :: Pattern -> String -> Maybe Int indexOf = _indexOf Just Nothing -foreign import _indexOf :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> String - -> String - -> Maybe Int +foreign import _indexOf + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Pattern + -> String + -> Maybe Int -- | Returns the index of the first occurrence of the first string in the -- | second string, starting at the given index. Returns `Nothing` if there is -- | no match. -indexOf' :: String -> Int -> String -> Maybe Int +indexOf' :: Pattern -> Int -> String -> Maybe Int indexOf' = _indexOf' Just Nothing -foreign import _indexOf' :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> String - -> Int - -> String - -> Maybe Int +foreign import _indexOf' + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Pattern + -> Int + -> String + -> Maybe Int -- | Returns the index of the last occurrence of the first string in the -- | second string. Returns `Nothing` if there is no match. -lastIndexOf :: String -> String -> Maybe Int +lastIndexOf :: Pattern -> String -> Maybe Int lastIndexOf = _lastIndexOf Just Nothing -foreign import _lastIndexOf :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> String - -> String - -> Maybe Int +foreign import _lastIndexOf + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Pattern + -> String + -> Maybe Int -- | Returns the index of the last occurrence of the first string in the -- | second string, starting at the given index. Returns `Nothing` if there is -- | no match. -lastIndexOf' :: String -> Int -> String -> Maybe Int +lastIndexOf' :: Pattern -> Int -> String -> Maybe Int lastIndexOf' = _lastIndexOf' Just Nothing -foreign import _lastIndexOf' :: (forall a. a -> Maybe a) - -> (forall a. Maybe a) - -> String - -> Int - -> String - -> Maybe Int +foreign import _lastIndexOf' + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Pattern + -> Int + -> String + -> Maybe Int -- | Returns the number of characters the string is composed of. foreign import length :: String -> Int @@ -173,15 +202,19 @@ foreign import length :: String -> Int localeCompare :: String -> String -> Ordering localeCompare = _localeCompare LT EQ GT -foreign import _localeCompare :: Ordering - -> Ordering - -> Ordering - -> String - -> String - -> Ordering +foreign import _localeCompare + :: Ordering + -> Ordering + -> Ordering + -> String + -> String + -> Ordering -- | Replaces the first occurence of the first argument with the second argument. -foreign import replace :: String -> String -> String -> String +foreign import replace :: Pattern -> Replacement -> String -> String + +-- | Replaces all occurences of the first argument with the second argument. +foreign import replaceAll :: Pattern -> Replacement -> String -> String -- | Returns the first `n` characters of the string. foreign import take :: Int -> String -> String @@ -196,7 +229,7 @@ foreign import count :: (Char -> Boolean) -> String -> Int -- | Returns the substrings of the second string separated along occurences -- | of the first string. -- | * `split " " "hello world" == ["hello", "world"]` -foreign import split :: String -> String -> Array String +foreign import split :: Pattern -> String -> Array String -- | Returns the substrings of split at the given index, if the index is within bounds. splitAt :: Int -> String -> Maybe (Array String) diff --git a/src/Data/String/CaseInsensitiveString.purs b/src/Data/String/CaseInsensitiveString.purs new file mode 100644 index 0000000..124810f --- /dev/null +++ b/src/Data/String/CaseInsensitiveString.purs @@ -0,0 +1,22 @@ +module Data.String.CaseInsensitive where + +import Prelude + +import Data.Newtype (class Newtype) +import Data.String (toLower) + +-- | A newtype for case insensitive string comparisons and ordering. +newtype CaseInsensitiveString = CaseInsensitiveString String + +instance eqCaseInsensitiveString :: Eq CaseInsensitiveString where + eq (CaseInsensitiveString s1) (CaseInsensitiveString s2) = + toLower s1 == toLower s2 + +instance ordCaseInsensitiveString :: Ord CaseInsensitiveString where + compare (CaseInsensitiveString s1) (CaseInsensitiveString s2) = + compare (toLower s1) (toLower s2) + +instance showCaseInsensitiveString :: Show CaseInsensitiveString where + show (CaseInsensitiveString s) = "(CaseInsensitiveString " <> s <> ")" + +derive instance newtypeCaseInsensitiveString :: Newtype CaseInsensitiveString _ diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js index 19e1a3d..1d7e407 100644 --- a/src/Data/String/Regex.js +++ b/src/Data/String/Regex.js @@ -1,8 +1,5 @@ -/* global exports */ "use strict"; -// module Data.String.Regex - exports["showRegex'"] = function (r) { return "" + r; }; diff --git a/src/Data/String/Regex.purs b/src/Data/String/Regex.purs index e665f3f..f1e3716 100644 --- a/src/Data/String/Regex.purs +++ b/src/Data/String/Regex.purs @@ -20,7 +20,7 @@ import Prelude import Data.Either (Either(..)) import Data.Maybe (Maybe(..)) -import Data.String (contains) +import Data.String (Pattern(..), contains) import Data.String.Regex.Flags (RegexFlags(..), RegexFlagsRec) -- | Wraps Javascript `RegExp` objects. @@ -31,11 +31,12 @@ foreign import showRegex' :: Regex -> String instance showRegex :: Show Regex where show = showRegex' -foreign import regex' :: (String -> Either String Regex) - -> (Regex -> Either String Regex) - -> String - -> String - -> Either String Regex +foreign import regex' + :: (String -> Either String Regex) + -> (Regex -> Either String Regex) + -> String + -> String + -> Either String Regex -- | Constructs a `Regex` from a pattern string and flags. Fails with -- | `Left error` if the pattern contains a syntax error. @@ -64,11 +65,11 @@ renderFlags (RegexFlags f) = -- | Parses the string representation of `RegexFlags`. parseFlags :: String -> RegexFlags parseFlags s = RegexFlags - { global: contains "g" s - , ignoreCase: contains "i" s - , multiline: contains "m" s - , sticky: contains "y" s - , unicode: contains "u" s + { global: contains (Pattern "g") s + , ignoreCase: contains (Pattern "i") s + , multiline: contains (Pattern "m") s + , sticky: contains (Pattern "y") s + , unicode: contains (Pattern "u") s } -- | Returns `true` if the `Regex` matches the string. In contrast to @@ -76,11 +77,12 @@ parseFlags s = RegexFlags -- | the `lastIndex` property of the Regex. foreign import test :: Regex -> String -> Boolean -foreign import _match :: (forall r. r -> Maybe r) - -> (forall r. Maybe r) - -> Regex - -> String - -> Maybe (Array (Maybe String)) +foreign import _match + :: (forall r. r -> Maybe r) + -> (forall r. Maybe r) + -> Regex + -> String + -> Maybe (Array (Maybe String)) -- | Matches the string against the `Regex` and returns an array of matches -- | if there were any. Each match has type `Maybe String`, where `Nothing` @@ -99,11 +101,12 @@ foreign import replace :: Regex -> String -> String -> String -- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). foreign import replace' :: Regex -> (String -> Array String -> String) -> String -> String -foreign import _search :: (forall r. r -> Maybe r) - -> (forall r. Maybe r) - -> Regex - -> String - -> Maybe Int +foreign import _search + :: (forall r. r -> Maybe r) + -> (forall r. Maybe r) + -> Regex + -> String + -> Maybe Int -- | Returns `Just` the index of the first match of the `Regex` in the string, -- | or `Nothing` if there is no match. diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs index 76e8c90..2684498 100644 --- a/src/Data/String/Regex/Flags.purs +++ b/src/Data/String/Regex/Flags.purs @@ -1,7 +1,11 @@ module Data.String.Regex.Flags where -import Prelude (class Semigroup, (||)) +import Prelude + +import Control.MonadPlus (guard) + import Data.Monoid (class Monoid) +import Data.String (joinWith) type RegexFlagsRec = { global :: Boolean @@ -85,3 +89,26 @@ instance semigroupRegexFlags :: Semigroup RegexFlags where instance monoidRegexFlags :: Monoid RegexFlags where mempty = noFlags + +instance eqRegexFlags :: Eq RegexFlags where + eq (RegexFlags x) (RegexFlags y) + = x.global == y.global + && x.ignoreCase == y.ignoreCase + && x.multiline == y.multiline + && x.sticky == y.sticky + && x.unicode == y.unicode + +instance showRegexFlags :: Show RegexFlags where + show (RegexFlags flags) = + let + usedFlags = + [] + <> (guard flags.global $> "global") + <> (guard flags.ignoreCase $> "ignoreCase") + <> (guard flags.multiline $> "multiline") + <> (guard flags.sticky $> "sticky") + <> (guard flags.unicode $> "unicode") + in + if usedFlags == [] + then "noFlags" + else "(" <> joinWith " <> " usedFlags <> ")" diff --git a/src/Data/String/Unsafe.js b/src/Data/String/Unsafe.js index 726fb29..b54568f 100644 --- a/src/Data/String/Unsafe.js +++ b/src/Data/String/Unsafe.js @@ -1,8 +1,5 @@ -/* global exports */ "use strict"; -// module Data.String.Unsafe - exports.charCodeAt = function (i) { return function (s) { if (i >= 0 && i < s.length) return s.charCodeAt(i); diff --git a/test/Test/Data/Char.purs b/test/Test/Data/Char.purs index e19afa0..ad35c43 100644 --- a/test/Test/Data/Char.purs +++ b/test/Test/Data/Char.purs @@ -26,4 +26,3 @@ testChar = do log "toUpper" assert $ toUpper 'a' == 'A' assert $ toUpper 'A' == 'A' - diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index 0ca90ba..e706ca1 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -60,57 +60,57 @@ testString = do assert $ dropWhile (\c -> c /= 'b') "aabbcc" == "bbcc" log "stripPrefix" - assert $ stripPrefix "" "" == Just "" - assert $ stripPrefix "" "abc" == Just "abc" - assert $ stripPrefix "a" "abc" == Just "bc" - assert $ stripPrefix "!" "abc" == Nothing - assert $ stripPrefix "!" "" == Nothing + assert $ stripPrefix (Pattern "") "" == Just "" + assert $ stripPrefix (Pattern "") "abc" == Just "abc" + assert $ stripPrefix (Pattern "a") "abc" == Just "bc" + assert $ stripPrefix (Pattern "!") "abc" == Nothing + assert $ stripPrefix (Pattern "!") "" == Nothing log "fromCharArray" assert $ fromCharArray [] == "" assert $ fromCharArray ['a', 'b'] == "ab" log "contains" - assert $ contains "" "" - assert $ contains "" "abcd" - assert $ contains "bc" "abcd" - assert $ not (contains "cb" "abcd") + assert $ contains (Pattern "") "" + assert $ contains (Pattern "") "abcd" + assert $ contains (Pattern "bc") "abcd" + assert $ not (contains (Pattern "cb") "abcd") log "indexOf" - assert $ indexOf "" "" == Just 0 - assert $ indexOf "" "abcd" == Just 0 - assert $ indexOf "bc" "abcd" == Just 1 - assert $ indexOf "cb" "abcd" == Nothing + assert $ indexOf (Pattern "") "" == Just 0 + assert $ indexOf (Pattern "") "abcd" == Just 0 + assert $ indexOf (Pattern "bc") "abcd" == Just 1 + assert $ indexOf (Pattern "cb") "abcd" == Nothing log "indexOf'" - assert $ indexOf' "" 0 "" == Just 0 - assert $ indexOf' "" (-1) "ab" == Nothing - assert $ indexOf' "" 0 "ab" == Just 0 - assert $ indexOf' "" 1 "ab" == Just 1 - assert $ indexOf' "" 2 "ab" == Just 2 - assert $ indexOf' "" 3 "ab" == Nothing - assert $ indexOf' "bc" 0 "abcd" == Just 1 - assert $ indexOf' "bc" 1 "abcd" == Just 1 - assert $ indexOf' "bc" 2 "abcd" == Nothing - assert $ indexOf' "cb" 0 "abcd" == Nothing + assert $ indexOf' (Pattern "") 0 "" == Just 0 + assert $ indexOf' (Pattern "") (-1) "ab" == Nothing + assert $ indexOf' (Pattern "") 0 "ab" == Just 0 + assert $ indexOf' (Pattern "") 1 "ab" == Just 1 + assert $ indexOf' (Pattern "") 2 "ab" == Just 2 + assert $ indexOf' (Pattern "") 3 "ab" == Nothing + assert $ indexOf' (Pattern "bc") 0 "abcd" == Just 1 + assert $ indexOf' (Pattern "bc") 1 "abcd" == Just 1 + assert $ indexOf' (Pattern "bc") 2 "abcd" == Nothing + assert $ indexOf' (Pattern "cb") 0 "abcd" == Nothing log "lastIndexOf" - assert $ lastIndexOf "" "" == Just 0 - assert $ lastIndexOf "" "abcd" == Just 4 - assert $ lastIndexOf "bc" "abcd" == Just 1 - assert $ lastIndexOf "cb" "abcd" == Nothing + assert $ lastIndexOf (Pattern "") "" == Just 0 + assert $ lastIndexOf (Pattern "") "abcd" == Just 4 + assert $ lastIndexOf (Pattern "bc") "abcd" == Just 1 + assert $ lastIndexOf (Pattern "cb") "abcd" == Nothing log "lastIndexOf'" - assert $ lastIndexOf' "" 0 "" == Just 0 - assert $ lastIndexOf' "" (-1) "ab" == Nothing - assert $ lastIndexOf' "" 0 "ab" == Just 0 - assert $ lastIndexOf' "" 1 "ab" == Just 1 - assert $ lastIndexOf' "" 2 "ab" == Just 2 - assert $ lastIndexOf' "" 3 "ab" == Nothing - assert $ lastIndexOf' "bc" 0 "abcd" == Nothing - assert $ lastIndexOf' "bc" 1 "abcd" == Just 1 - assert $ lastIndexOf' "bc" 2 "abcd" == Just 1 - assert $ lastIndexOf' "cb" 0 "abcd" == Nothing + assert $ lastIndexOf' (Pattern "") 0 "" == Just 0 + assert $ lastIndexOf' (Pattern "") (-1) "ab" == Nothing + assert $ lastIndexOf' (Pattern "") 0 "ab" == Just 0 + assert $ lastIndexOf' (Pattern "") 1 "ab" == Just 1 + assert $ lastIndexOf' (Pattern "") 2 "ab" == Just 2 + assert $ lastIndexOf' (Pattern "") 3 "ab" == Nothing + assert $ lastIndexOf' (Pattern "bc") 0 "abcd" == Nothing + assert $ lastIndexOf' (Pattern "bc") 1 "abcd" == Just 1 + assert $ lastIndexOf' (Pattern "bc") 2 "abcd" == Just 1 + assert $ lastIndexOf' (Pattern "cb") 0 "abcd" == Nothing log "length" assert $ length "" == 0 @@ -124,9 +124,13 @@ testString = do assert $ localeCompare "b" "a" == GT log "replace" - assert $ replace "b" "" "abc" == "ac" - assert $ replace "b" "!" "abc" == "a!c" - assert $ replace "d" "!" "abc" == "abc" + assert $ replace (Pattern "b") (Replacement "") "abc" == "ac" + assert $ replace (Pattern "b") (Replacement "!") "abc" == "a!c" + assert $ replace (Pattern "d") (Replacement "!") "abc" == "abc" + + log "replaceAll" + assert $ replaceAll (Pattern "b") (Replacement "") "abbbbbc" == "ac" + assert $ replaceAll (Pattern "[b]") (Replacement "!") "a[b]c" == "a!c" log "take" assert $ take 0 "ab" == "" @@ -149,11 +153,11 @@ testString = do assert $ count (_ == 'a') "abaa" == 1 log "split" - assert $ split "" "" == [] - assert $ split "" "a" == ["a"] - assert $ split "" "ab" == ["a", "b"] - assert $ split "b" "aabcc" == ["aa", "cc"] - assert $ split "d" "abc" == ["abc"] + assert $ split (Pattern "") "" == [] + assert $ split (Pattern "") "a" == ["a"] + assert $ split (Pattern "") "ab" == ["a", "b"] + assert $ split (Pattern "b") "aabcc" == ["aa", "cc"] + assert $ split (Pattern "d") "abc" == ["abc"] log "splitAt" assert $ splitAt 1 "" == Nothing diff --git a/test/Test/Data/String/CaseInsensitive.purs b/test/Test/Data/String/CaseInsensitive.purs new file mode 100644 index 0000000..e47b4a9 --- /dev/null +++ b/test/Test/Data/String/CaseInsensitive.purs @@ -0,0 +1,18 @@ +module Test.Data.String.CaseInsensitive (testCaseInsensitiveString) where + +import Prelude (Unit, (==), ($), bind, compare, Ordering(..)) + +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) + +import Data.String.CaseInsensitive + +import Test.Assert (ASSERT, assert) + +testCaseInsensitiveString :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit +testCaseInsensitiveString = do + log "equality" + assert $ CaseInsensitiveString "aB" == CaseInsensitiveString "AB" + + log "comparison" + assert $ compare (CaseInsensitiveString "qwerty") (CaseInsensitiveString "QWERTY") == EQ diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 165098c..b2c7f50 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -10,6 +10,7 @@ import Test.Data.Char (testChar) import Test.Data.String (testString) import Test.Data.String.Regex (testStringRegex) import Test.Data.String.Unsafe (testStringUnsafe) +import Test.Data.String.CaseInsensitive (testCaseInsensitiveString) main :: Eff (console :: CONSOLE, assert :: ASSERT) Unit main = do @@ -17,3 +18,4 @@ main = do testString testStringUnsafe testStringRegex + testCaseInsensitiveString