11module Test.Data.String.Regex (testStringRegex ) where
22
3- import Prelude (Unit , ($), (<>), discard , (==), not )
4-
5- import Effect (Effect )
6- import Effect.Console (log )
3+ import Data.String.Regex
74
5+ import Data.Array.NonEmpty (NonEmptyArray , fromArray )
86import Data.Either (isLeft )
9- import Data.Maybe (Maybe (..))
10- import Data.String.Regex
7+ import Data.Maybe (Maybe (..), fromJust )
118import Data.String.Regex.Flags (global , ignoreCase , noFlags )
129import Data.String.Regex.Unsafe (unsafeRegex )
13-
10+ import Effect (Effect )
11+ import Effect.Console (log )
12+ import Partial.Unsafe (unsafePartial )
13+ import Prelude (type (~>), Unit , discard , not , ($), (<<<), (<>), (==))
1414import Test.Assert (assert )
1515
1616testStringRegex :: Effect Unit
@@ -26,7 +26,8 @@ testStringRegex = do
2626 assert $ " quxbarquxbaz" == replace (unsafeRegex " foo" (global <> ignoreCase)) " qux" " foobarFOObaz"
2727
2828 log " match"
29- assert $ match (unsafeRegex " ^abc$" noFlags) " abc" == Just [Just " abc" ]
29+ assert $ match (unsafeRegex " ^abc$" noFlags) " abc" == Just (nea [Just " abc" ])
30+ assert $ match (unsafeRegex " ^abc$" noFlags) " xyz" == Nothing
3031
3132 log " replace"
3233 assert $ replace (unsafeRegex " -" noFlags) " !" " a-b-c" == " a!b-c"
@@ -50,3 +51,6 @@ testStringRegex = do
5051 let pattern = unsafeRegex " a" (parseFlags " g" )
5152 assert $ test pattern " a"
5253 assert $ test pattern " a"
54+
55+ nea :: Array ~> NonEmptyArray
56+ nea = unsafePartial fromJust <<< fromArray
0 commit comments