21
21
// MODULES //
22
22
23
23
var tape = require ( 'tape' ) ;
24
+ var replace = require ( '@stdlib/string/replace' ) ;
24
25
var reWhitespace = require ( './../lib/main.js' ) ;
25
26
26
27
@@ -33,10 +34,12 @@ tape( 'main export is a function', function test( t ) {
33
34
} ) ;
34
35
35
36
tape ( 'the function returns a regular expression to match white space character sequences (no options)' , function test ( t ) {
36
- var REGEXP = reWhitespace ( ) ;
37
37
var values ;
38
+ var re ;
38
39
var i ;
39
40
41
+ re = reWhitespace ( ) ;
42
+
40
43
values = [
41
44
'\r' ,
42
45
'\n' ,
@@ -72,16 +75,18 @@ tape( 'the function returns a regular expression to match white space character
72
75
] ;
73
76
74
77
for ( i = 0 ; i < values . length ; i ++ ) {
75
- t . strictEqual ( REGEXP . test ( values [ i ] ) , true , 'matches when provided ' + values [ i ] ) ;
78
+ t . strictEqual ( re . test ( values [ i ] ) , true , 'matches when provided ' + values [ i ] ) ;
76
79
}
77
80
t . end ( ) ;
78
81
} ) ;
79
82
80
83
tape ( 'the returned regular expression does not match escaped sequences or non-matching strings (no options)' , function test ( t ) {
81
- var REGEXP = reWhitespace ( ) ;
82
84
var values ;
85
+ var re ;
83
86
var i ;
84
87
88
+ re = reWhitespace ( ) ;
89
+
85
90
values = [
86
91
'\\r' ,
87
92
'\\n' ,
@@ -95,7 +100,7 @@ tape( 'the returned regular expression does not match escaped sequences or non-m
95
100
] ;
96
101
97
102
for ( i = 0 ; i < values . length ; i ++ ) {
98
- t . strictEqual ( REGEXP . test ( values [ i ] ) , false , 'does not match when provided ' + values [ i ] ) ;
103
+ t . strictEqual ( re . test ( values [ i ] ) , false , 'does not match when provided ' + values [ i ] ) ;
99
104
}
100
105
t . end ( ) ;
101
106
} ) ;
@@ -139,7 +144,7 @@ tape( 'the function throws an error if provided an invalid option', function tes
139
144
5 ,
140
145
NaN ,
141
146
null ,
142
- undefined ,
147
+ void 0 ,
143
148
[ ] ,
144
149
function noop ( ) { } ,
145
150
/ .* / ,
@@ -163,17 +168,42 @@ tape( 'the function throws an error if provided an invalid option', function tes
163
168
164
169
tape ( 'the function supports returning a regular expression wrapped in a capture group' , function test ( t ) {
165
170
var expected ;
166
- var REGEXP ;
167
171
var arr ;
168
172
var str ;
173
+ var re ;
169
174
170
- REGEXP = reWhitespace ( {
175
+ re = reWhitespace ( {
171
176
'capture' : true
172
177
} ) ;
173
178
str = 'Hello World!' ;
174
179
expected = [ 'Hello' , ' ' , 'World!' ] ;
175
- arr = str . split ( REGEXP ) ;
180
+ arr = str . split ( re ) ;
176
181
177
182
t . deepEqual ( arr , expected , 'returns expected value' ) ;
178
183
t . end ( ) ;
179
184
} ) ;
185
+
186
+ tape ( 'the function supports specifying regular expression flags' , function test ( t ) {
187
+ var expected ;
188
+ var actual ;
189
+ var str ;
190
+ var re ;
191
+
192
+ str = ' Hello World! ' ;
193
+
194
+ re = reWhitespace ( ) ;
195
+ actual = replace ( str , re , '!' ) ;
196
+ expected = '!Hello World! ' ;
197
+
198
+ t . strictEqual ( actual , expected , 'returns expected value' ) ;
199
+
200
+ re = reWhitespace ( {
201
+ 'flags' : 'g'
202
+ } ) ;
203
+ actual = replace ( str , re , '!' ) ;
204
+ expected = '!Hello!World!!!!' ;
205
+
206
+ t . strictEqual ( actual , expected , 'returns expected value' ) ;
207
+
208
+ t . end ( ) ;
209
+ } ) ;
0 commit comments