Skip to content

Commit c1b03d9

Browse files
committed
Update tests
1 parent 9a1f27c commit c1b03d9

1 file changed

Lines changed: 82 additions & 42 deletions

File tree

  • lib/node_modules/@stdlib/string/next-grapheme-cluster-break/test

lib/node_modules/@stdlib/string/next-grapheme-cluster-break/test/test.js

Lines changed: 82 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tape( 'main export is a function', function test( t ) {
3232
t.end();
3333
});
3434

35-
tape( 'the function throws an error if the first argument is not a string primitive', function test( t ) {
35+
tape( 'the function throws an error if the first argument is not a string (one argument)', function test( t ) {
3636
var values;
3737
var i;
3838

@@ -58,78 +58,85 @@ tape( 'the function throws an error if the first argument is not a string primit
5858

5959
function badValue( value ) {
6060
return function badValue() {
61-
nextGraphemeClusterBreak( value, 0 );
61+
nextGraphemeClusterBreak( value );
6262
};
6363
}
6464
});
6565

66-
tape( 'the function throws an error if the second argument is not an integer', function test( t ) {
66+
tape( 'the function throws an error if the first argument is not a string (two arguments)', function test( t ) {
6767
var values;
6868
var i;
6969

7070
values = [
71-
'bar',
71+
-5,
7272
3.14,
73+
-1.0,
7374
NaN,
75+
true,
76+
false,
7477
null,
7578
void 0,
7679
[ 'beep', 'boop' ],
7780
[ 1, 2, 3 ],
7881
{},
7982
function noop() {}
8083
];
84+
8185
for ( i = 0; i < values.length; i++ ) {
8286
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
8387
}
8488
t.end();
8589

8690
function badValue( value ) {
8791
return function badValue() {
88-
nextGraphemeClusterBreak( 'foo', value );
92+
nextGraphemeClusterBreak( value, 0 );
8993
};
9094
}
9195
});
9296

93-
tape( 'the function returns -1 if the provided position is greater than or equal to the string length', function test( t ) {
94-
var out;
95-
96-
out = nextGraphemeClusterBreak( 'last man standing', 17 );
97-
t.strictEqual( out, -1, 'returns expected value' );
98-
99-
out = nextGraphemeClusterBreak( 'presidential election', 22 );
100-
t.strictEqual( out, -1, 'returns expected value' );
101-
102-
out = nextGraphemeClusterBreak( 'अनुच्छेद', 10 );
103-
t.strictEqual( out, -1, 'returns expected value' );
104-
105-
out = nextGraphemeClusterBreak( '🌷', 2 );
106-
t.strictEqual( out, -1, 'returns expected value' );
97+
tape( 'the function throws an error if the second argument is not an integer', function test( t ) {
98+
var values;
99+
var i;
107100

101+
values = [
102+
'bar',
103+
3.14,
104+
NaN,
105+
null,
106+
void 0,
107+
[ 'beep', 'boop' ],
108+
[ 1, 2, 3 ],
109+
{},
110+
function noop() {}
111+
];
112+
for ( i = 0; i < values.length; i++ ) {
113+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
114+
}
108115
t.end();
116+
117+
function badValue( value ) {
118+
return function badValue() {
119+
nextGraphemeClusterBreak( 'foo', value );
120+
};
121+
}
109122
});
110123

111-
tape( 'the function returns -1 if the provided position is in the last extended grapheme cluster of the string', function test( t ) {
124+
tape( 'the function returns the next grapheme cluster break position in a provided string', function test( t ) {
112125
var out;
113126

114-
out = nextGraphemeClusterBreak( 'last man standing', 16 );
115-
t.strictEqual( out, -1, 'returns expected value' );
116-
117-
out = nextGraphemeClusterBreak( 'presidential election', 20 );
118-
t.strictEqual( out, -1, 'returns expected value' );
119-
120-
out = nextGraphemeClusterBreak( 'अनुच्छेद', 7 );
121-
t.strictEqual( out, -1, 'returns expected value' );
127+
out = nextGraphemeClusterBreak( 'last man standing' );
128+
t.strictEqual( out, 1, 'returns expected value' );
122129

123-
out = nextGraphemeClusterBreak( '🌷', 1 );
124-
t.strictEqual( out, -1, 'returns expected value' );
130+
out = nextGraphemeClusterBreak( 'presidential election' );
131+
t.strictEqual( out, 1, 'returns expected value' );
125132

126-
out = nextGraphemeClusterBreak( '六', 0 );
127-
t.strictEqual( out, -1, 'returns expected value' );
133+
out = nextGraphemeClusterBreak( 'नुच्छेद' );
134+
t.strictEqual( out, 2, 'returns expected value' );
128135

129136
t.end();
130137
});
131138

132-
tape( 'the function returns the next grapheme break position in a specified string', function test( t ) {
139+
tape( 'the function supports providing an index from which to begin searching', function test( t ) {
133140
var out;
134141

135142
out = nextGraphemeClusterBreak( 'last man standing', 4 );
@@ -144,7 +151,7 @@ tape( 'the function returns the next grapheme break position in a specified stri
144151
t.end();
145152
});
146153

147-
tape( 'the function supports negative integers for second argument', function test( t ) {
154+
tape( 'the function supports providing a negative integer for the starting search index', function test( t ) {
148155
var out;
149156

150157
out = nextGraphemeClusterBreak( 'last man standing', -13 );
@@ -159,22 +166,52 @@ tape( 'the function supports negative integers for second argument', function te
159166
t.end();
160167
});
161168

162-
tape( 'the function supports a default `fromIndex` of 0 if second argument is not provided', function test( t ) {
169+
tape( 'the function returns `-1` if the starting search index is greater than or equal to the string length', function test( t ) {
163170
var out;
164171

165-
out = nextGraphemeClusterBreak( 'last man standing' );
166-
t.strictEqual( out, 1, 'returns expected value' );
172+
out = nextGraphemeClusterBreak( 'last man standing', 17 );
173+
t.strictEqual( out, -1, 'returns expected value' );
167174

168-
out = nextGraphemeClusterBreak( 'presidential election' );
169-
t.strictEqual( out, 1, 'returns expected value' );
175+
out = nextGraphemeClusterBreak( 'presidential election', 22 );
176+
t.strictEqual( out, -1, 'returns expected value' );
170177

171-
out = nextGraphemeClusterBreak( 'नुच्छेद' );
172-
t.strictEqual( out, 2, 'returns expected value' );
178+
out = nextGraphemeClusterBreak( 'अनुच्छेद', 10 );
179+
t.strictEqual( out, -1, 'returns expected value' );
180+
181+
out = nextGraphemeClusterBreak( '🌷', 2 );
182+
t.strictEqual( out, -1, 'returns expected value' );
173183

174184
t.end();
175185
});
176186

177-
tape( 'the function returns -1 if provided an empty string', function test( t ) {
187+
tape( 'the function returns `-1` if the starting search index resides within the last extended grapheme cluster of the string', function test( t ) {
188+
var out;
189+
190+
out = nextGraphemeClusterBreak( 'last man standing', 16 );
191+
t.strictEqual( out, -1, 'returns expected value' );
192+
193+
out = nextGraphemeClusterBreak( 'presidential election', 20 );
194+
t.strictEqual( out, -1, 'returns expected value' );
195+
196+
out = nextGraphemeClusterBreak( 'अनुच्छेद', 7 );
197+
t.strictEqual( out, -1, 'returns expected value' );
198+
199+
out = nextGraphemeClusterBreak( '🌷', 1 );
200+
t.strictEqual( out, -1, 'returns expected value' );
201+
202+
out = nextGraphemeClusterBreak( '🌷' );
203+
t.strictEqual( out, -1, 'returns expected value' );
204+
205+
out = nextGraphemeClusterBreak( '六', 0 );
206+
t.strictEqual( out, -1, 'returns expected value' );
207+
208+
out = nextGraphemeClusterBreak( '六' );
209+
t.strictEqual( out, -1, 'returns expected value' );
210+
211+
t.end();
212+
});
213+
214+
tape( 'the function returns `-1` if provided an empty string', function test( t ) {
178215
var out;
179216

180217
out = nextGraphemeClusterBreak( '', -2 );
@@ -186,5 +223,8 @@ tape( 'the function returns -1 if provided an empty string', function test( t )
186223
out = nextGraphemeClusterBreak( '', 0 );
187224
t.strictEqual( out, -1, 'returns expected value' );
188225

226+
out = nextGraphemeClusterBreak( '' );
227+
t.strictEqual( out, -1, 'returns expected value' );
228+
189229
t.end();
190230
});

0 commit comments

Comments
 (0)