@@ -5,53 +5,48 @@ import Prelude (Unit, ($), (<>), bind, (==), not)
5
5
import Control.Monad.Eff (Eff )
6
6
import Control.Monad.Eff.Console (CONSOLE , log )
7
7
8
- import Data.Either (isLeft , fromRight )
8
+ import Data.Either (isLeft )
9
9
import Data.Maybe (Maybe (..))
10
10
import Data.String.Regex
11
- import Data.String.Regex.Flags (RegexFlags , global , ignoreCase , noFlags )
12
-
13
- import Partial.Unsafe (unsafePartial )
11
+ import Data.String.Regex.Flags (global , ignoreCase , noFlags )
12
+ import Data.String.Regex.Unsafe (unsafeRegex )
14
13
15
14
import Test.Assert (ASSERT , assert )
16
15
17
- -- | Unsafe version of `regex`.
18
- regex' :: String -> RegexFlags -> Regex
19
- regex' pattern flags = unsafePartial $ fromRight (regex pattern flags)
20
-
21
16
testStringRegex :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT | eff ) Unit
22
17
testStringRegex = do
23
18
log " regex"
24
- assert $ test (regex' " ^a" noFlags) " abc"
25
- assert $ not (test (regex' " ^b" noFlags) " abc" )
19
+ assert $ test (unsafeRegex " ^a" noFlags) " abc"
20
+ assert $ not (test (unsafeRegex " ^b" noFlags) " abc" )
26
21
assert $ isLeft (regex " +" noFlags)
27
22
28
23
log " flags"
29
- assert $ " quxbarfoobaz" == replace (regex' " foo" noFlags) " qux" " foobarfoobaz"
30
- assert $ " quxbarquxbaz" == replace (regex' " foo" global) " qux" " foobarfoobaz"
31
- assert $ " quxbarquxbaz" == replace (regex' " foo" (global <> ignoreCase)) " qux" " foobarFOObaz"
24
+ assert $ " quxbarfoobaz" == replace (unsafeRegex " foo" noFlags) " qux" " foobarfoobaz"
25
+ assert $ " quxbarquxbaz" == replace (unsafeRegex " foo" global) " qux" " foobarfoobaz"
26
+ assert $ " quxbarquxbaz" == replace (unsafeRegex " foo" (global <> ignoreCase)) " qux" " foobarFOObaz"
32
27
33
28
log " match"
34
- assert $ match (regex' " ^abc$" noFlags) " abc" == Just [Just " abc" ]
29
+ assert $ match (unsafeRegex " ^abc$" noFlags) " abc" == Just [Just " abc" ]
35
30
36
31
log " replace"
37
- assert $ replace (regex' " -" noFlags) " !" " a-b-c" == " a!b-c"
32
+ assert $ replace (unsafeRegex " -" noFlags) " !" " a-b-c" == " a!b-c"
38
33
39
34
log " replace'"
40
- assert $ replace' (regex' " -" noFlags) (\s xs -> " !" ) " a-b-c" == " a!b-c"
35
+ assert $ replace' (unsafeRegex " -" noFlags) (\s xs -> " !" ) " a-b-c" == " a!b-c"
41
36
42
37
log " search"
43
- assert $ search (regex' " b" noFlags) " abc" == Just 1
44
- assert $ search (regex' " d" noFlags) " abc" == Nothing
38
+ assert $ search (unsafeRegex " b" noFlags) " abc" == Just 1
39
+ assert $ search (unsafeRegex " d" noFlags) " abc" == Nothing
45
40
46
41
log " split"
47
- assert $ split (regex' " " noFlags) " " == []
48
- assert $ split (regex' " " noFlags) " abc" == [" a" , " b" , " c" ]
49
- assert $ split (regex' " b" noFlags) " " == [" " ]
50
- assert $ split (regex' " b" noFlags) " abc" == [" a" , " c" ]
42
+ assert $ split (unsafeRegex " " noFlags) " " == []
43
+ assert $ split (unsafeRegex " " noFlags) " abc" == [" a" , " b" , " c" ]
44
+ assert $ split (unsafeRegex " b" noFlags) " " == [" " ]
45
+ assert $ split (unsafeRegex " b" noFlags) " abc" == [" a" , " c" ]
51
46
52
47
log " test"
53
48
-- Ensure that we have referential transparency for calls to 'test'. No
54
49
-- global state should be maintained between these two calls:
55
- let pattern = regex' " a" (parseFlags " g" )
50
+ let pattern = unsafeRegex " a" (parseFlags " g" )
56
51
assert $ test pattern " a"
57
52
assert $ test pattern " a"
0 commit comments