|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var contains = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
25 | 25 |
|
26 | 26 |
|
27 | 27 | // TESTS //
|
28 | 28 |
|
29 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
30 | 30 | t.ok( true, __filename );
|
31 |
| - t.strictEqual( typeof contains, 'function', 'main export is a function' ); |
32 |
| - t.end(); |
33 |
| -}); |
34 |
| - |
35 |
| -tape( 'the function throws an error if the first argument is not array-like', function test( t ) { |
36 |
| - var values; |
37 |
| - var i; |
38 |
| - |
39 |
| - values = [ |
40 |
| - 5, |
41 |
| - null, |
42 |
| - true, |
43 |
| - false, |
44 |
| - void 0, |
45 |
| - NaN, |
46 |
| - {}, |
47 |
| - function noop() {} |
48 |
| - ]; |
49 |
| - |
50 |
| - for ( i = 0; i < values.length; i++ ) { |
51 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
52 |
| - } |
53 |
| - t.end(); |
54 |
| - |
55 |
| - function badValue( value ) { |
56 |
| - return function badValue() { |
57 |
| - contains( value, '' ); |
58 |
| - }; |
59 |
| - } |
60 |
| -}); |
61 |
| - |
62 |
| -tape( 'the function throws an error if not provided a second argument', function test( t ) { |
63 |
| - t.throws( badValue, Error, 'throws an error when not provided a second argument' ); |
64 |
| - t.end(); |
65 |
| - |
66 |
| - function badValue() { |
67 |
| - return contains( 'abc' ); |
68 |
| - } |
69 |
| -}); |
70 |
| - |
71 |
| -tape( 'the function throws an error if the first argument is a string and the second argument is not a string', function test( t ) { |
72 |
| - var values; |
73 |
| - var i; |
74 |
| - |
75 |
| - values = [ |
76 |
| - 5, |
77 |
| - null, |
78 |
| - true, |
79 |
| - false, |
80 |
| - void 0, |
81 |
| - NaN, |
82 |
| - [], |
83 |
| - {}, |
84 |
| - function noop() {} |
85 |
| - ]; |
86 |
| - |
87 |
| - for ( i = 0; i < values.length; i++ ) { |
88 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
89 |
| - } |
90 |
| - t.end(); |
91 |
| - |
92 |
| - function badValue( value ) { |
93 |
| - return function badValue() { |
94 |
| - contains( 'abc', value ); |
95 |
| - }; |
96 |
| - } |
97 |
| -}); |
98 |
| - |
99 |
| -tape( 'the function throws an error if the `position` argument is not an integer', function test( t ) { |
100 |
| - var values; |
101 |
| - var i; |
102 |
| - |
103 |
| - values = [ |
104 |
| - 6.5, |
105 |
| - '5', |
106 |
| - null, |
107 |
| - true, |
108 |
| - false, |
109 |
| - void 0, |
110 |
| - NaN, |
111 |
| - [], |
112 |
| - {}, |
113 |
| - function noop() {} |
114 |
| - ]; |
115 |
| - |
116 |
| - for ( i = 0; i < values.length; i++ ) { |
117 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
118 |
| - } |
119 |
| - t.end(); |
120 |
| - |
121 |
| - function badValue( value ) { |
122 |
| - return function badValue() { |
123 |
| - contains( 'Hello World', 'Hello', value ); |
124 |
| - }; |
125 |
| - } |
126 |
| -}); |
127 |
| - |
128 |
| -tape( 'the function returns `true` when a search string is contained in input string', function test( t ) { |
129 |
| - var out; |
130 |
| - |
131 |
| - out = contains( 'Hello World', 'World' ); |
132 |
| - t.equal( out, true, 'returns true' ); |
133 |
| - |
134 |
| - out = contains( 'Hello World', ' ' ); |
135 |
| - t.equal( out, true, 'returns true' ); |
136 |
| - |
137 |
| - out = contains( 'Hello World', 'Hell' ); |
138 |
| - t.equal( out, true, 'returns true' ); |
139 |
| - |
140 |
| - t.end(); |
141 |
| -}); |
142 |
| - |
143 |
| -tape( 'the function returns `false` when a search string is not contained in input string', function test( t ) { |
144 |
| - var out; |
145 |
| - |
146 |
| - out = contains( 'Hello World', 'world' ); |
147 |
| - t.equal( out, false, 'returns false' ); |
148 |
| - |
149 |
| - out = contains( 'Hello World', '\t' ); |
150 |
| - t.equal( out, false, 'returns false' ); |
151 |
| - |
152 |
| - out = contains( 'Hello World', 'Word' ); |
153 |
| - t.equal( out, false, 'returns false' ); |
154 |
| - |
155 |
| - t.end(); |
156 |
| -}); |
157 |
| - |
158 |
| -tape( 'the function returns `true` when a search value is contained in input array', function test( t ) { |
159 |
| - var out; |
160 |
| - |
161 |
| - out = contains( [ NaN, null, 3, 'abc' ], 'abc' ); |
162 |
| - t.equal( out, true, 'returns true' ); |
163 |
| - |
164 |
| - out = contains( [ NaN, null, 3, 'abc' ], NaN ); |
165 |
| - t.equal( out, true, 'returns true' ); |
166 |
| - |
167 |
| - out = contains( [ NaN, null, 3, 'abc' ], null ); |
168 |
| - t.equal( out, true, 'returns true' ); |
169 |
| - |
170 |
| - t.end(); |
171 |
| -}); |
172 |
| - |
173 |
| -tape( 'the function returns `false` when search value is not contained in input array', function test( t ) { |
174 |
| - var out; |
175 |
| - |
176 |
| - out = contains( [ NaN, null, 3, 'abc' ], 'ac' ); |
177 |
| - t.equal( out, false, 'returns false' ); |
178 |
| - |
179 |
| - out = contains( [ NaN, null, 3, 'abc' ], false ); |
180 |
| - t.equal( out, false, 'returns false' ); |
181 |
| - |
182 |
| - out = contains( [ NaN, null, 3, 'abc' ], 3.5 ); |
183 |
| - t.equal( out, false, 'returns false' ); |
184 |
| - |
185 |
| - t.end(); |
186 |
| -}); |
187 |
| - |
188 |
| -tape( 'the function supports beginning a search at the specified position', function test( t ) { |
189 |
| - var out; |
190 |
| - |
191 |
| - out = contains( 'ABCDEFG', 'A', 1 ); |
192 |
| - t.equal( out, false, 'returns false' ); |
193 |
| - |
194 |
| - out = contains( 'ABCDEFG', 'B', 1 ); |
195 |
| - t.equal( out, true, 'returns true' ); |
196 |
| - |
197 |
| - out = contains( 'ABCDEFG', 'A', -3 ); |
198 |
| - t.equal( out, true, 'returns true' ); |
199 |
| - |
200 |
| - out = contains( [ null, NaN, 2 ], 3, 1 ); |
201 |
| - t.equal( out, false, 'returns false' ); |
202 |
| - |
203 |
| - out = contains( [ null, NaN, 2 ], NaN, 1 ); |
204 |
| - t.equal( out, true, 'returns true' ); |
205 |
| - |
206 |
| - out = contains( [ null, NaN, 2 ], NaN, -3 ); |
207 |
| - t.equal( out, true, 'returns true' ); |
208 |
| - |
209 |
| - out = contains( [ null, NaN, 2 ], NaN, 2 ); |
210 |
| - t.equal( out, false, 'returns false' ); |
211 |
| - |
212 |
| - t.end(); |
213 |
| -}); |
214 |
| - |
215 |
| -tape( 'the function returns `true` if provided an input string and an empty string as the search value', function test( t ) { |
216 |
| - t.equal( contains( 'abc', '' ), true, 'returns true' ); |
217 |
| - t.equal( contains( '', '' ), true, 'returns true' ); |
218 |
| - t.end(); |
219 |
| -}); |
220 |
| - |
221 |
| -tape( 'the function returns `false` if provided an empty array-like value', function test( t ) { |
222 |
| - t.equal( contains( [], '' ), false, 'returns false' ); |
223 |
| - t.end(); |
224 |
| -}); |
225 |
| - |
226 |
| -tape( 'the function does not distinguish between positive and negative zero', function test( t ) { |
227 |
| - t.equal( contains( [ -0.0 ], +0.0 ), true, 'returns true' ); |
228 |
| - t.equal( contains( [ +0.0 ], -0.0 ), true, 'returns true' ); |
229 |
| - t.end(); |
230 |
| -}); |
231 |
| - |
232 |
| -tape( 'the function returns `false` if provided a position which exceeds the maximum index', function test( t ) { |
233 |
| - t.equal( contains( [ 1 ], 1, 1e5 ), false, 'returns false' ); |
234 |
| - t.equal( contains( 'abc', 'a', 1e5 ), false, 'returns false' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
235 | 32 | t.end();
|
236 | 33 | });
|
0 commit comments