File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ exports.flags = function (r) {
37
37
38
38
exports . test = function ( r ) {
39
39
return function ( s ) {
40
- return r . test ( s ) ;
40
+ var lastIndex = r . lastIndex ;
41
+ var result = r . test ( s ) ;
42
+ r . lastIndex = lastIndex ;
43
+ return result ;
41
44
} ;
42
45
} ;
43
46
Original file line number Diff line number Diff line change @@ -84,7 +84,9 @@ parseFlags s =
84
84
, unicode: contains " u" s
85
85
}
86
86
87
- -- | Returns `true` if the `Regex` matches the string.
87
+ -- | Returns `true` if the `Regex` matches the string. In contrast to
88
+ -- | `RegExp.prototype.test()` in JavaScript, `test` does not affect
89
+ -- | the `lastIndex` property of the Regex.
88
90
foreign import test :: Regex -> String -> Boolean
89
91
90
92
foreign import _match :: (forall r . r -> Maybe r )
Original file line number Diff line number Diff line change @@ -36,3 +36,10 @@ testStringRegex = do
36
36
assert $ split (regex' " " noFlags) " abc" == [" a" , " b" , " c" ]
37
37
assert $ split (regex' " b" noFlags) " " == [" " ]
38
38
assert $ split (regex' " b" noFlags) " abc" == [" a" , " c" ]
39
+
40
+ log " test"
41
+ -- Ensure that we have referential transparency for calls to 'test'. No
42
+ -- global state should be maintained between these two calls:
43
+ let pattern = regex' " a" (parseFlags " g" )
44
+ assert $ test pattern " a"
45
+ assert $ test pattern " a"
You can’t perform that action at this time.
0 commit comments