Skip to content

Commit 65c045b

Browse files
committed
Add tests to achieve full test coverage
1 parent 96ad744 commit 65c045b

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

lib/node_modules/@stdlib/regexp/whitespace/test/test.main.js

+38-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var replace = require( '@stdlib/string/replace' );
2425
var reWhitespace = require( './../lib/main.js' );
2526

2627

@@ -33,10 +34,12 @@ tape( 'main export is a function', function test( t ) {
3334
});
3435

3536
tape( 'the function returns a regular expression to match white space character sequences (no options)', function test( t ) {
36-
var REGEXP = reWhitespace();
3737
var values;
38+
var re;
3839
var i;
3940

41+
re = reWhitespace();
42+
4043
values = [
4144
'\r',
4245
'\n',
@@ -72,16 +75,18 @@ tape( 'the function returns a regular expression to match white space character
7275
];
7376

7477
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] );
7679
}
7780
t.end();
7881
});
7982

8083
tape( 'the returned regular expression does not match escaped sequences or non-matching strings (no options)', function test( t ) {
81-
var REGEXP = reWhitespace();
8284
var values;
85+
var re;
8386
var i;
8487

88+
re = reWhitespace();
89+
8590
values = [
8691
'\\r',
8792
'\\n',
@@ -95,7 +100,7 @@ tape( 'the returned regular expression does not match escaped sequences or non-m
95100
];
96101

97102
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] );
99104
}
100105
t.end();
101106
});
@@ -139,7 +144,7 @@ tape( 'the function throws an error if provided an invalid option', function tes
139144
5,
140145
NaN,
141146
null,
142-
undefined,
147+
void 0,
143148
[],
144149
function noop() {},
145150
/.*/,
@@ -163,17 +168,42 @@ tape( 'the function throws an error if provided an invalid option', function tes
163168

164169
tape( 'the function supports returning a regular expression wrapped in a capture group', function test( t ) {
165170
var expected;
166-
var REGEXP;
167171
var arr;
168172
var str;
173+
var re;
169174

170-
REGEXP = reWhitespace({
175+
re = reWhitespace({
171176
'capture': true
172177
});
173178
str = 'Hello World!';
174179
expected = [ 'Hello', ' ', 'World!' ];
175-
arr = str.split( REGEXP );
180+
arr = str.split( re );
176181

177182
t.deepEqual( arr, expected, 'returns expected value' );
178183
t.end();
179184
});
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

Comments
 (0)