|
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 hasSymbols = require( '@stdlib/assert-has-symbol-support' ); |
25 | | -var hasMap = require( '@stdlib/assert-has-map-support' ); |
26 | | -var hasSet = require( '@stdlib/assert-has-set-support' ); |
27 | | -var hasWeakMap = require( '@stdlib/assert-has-weakmap-support' ); |
28 | | -var hasWeakSet = require( '@stdlib/assert-has-weakset-support' ); |
29 | | -var Int8Array = require( '@stdlib/array-int8' ); |
30 | | -var Uint8Array = require( '@stdlib/array-uint8' ); |
31 | | -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); |
32 | | -var Int16Array = require( '@stdlib/array-int16' ); |
33 | | -var Uint16Array = require( '@stdlib/array-uint16' ); |
34 | | -var Int32Array = require( '@stdlib/array-int32' ); |
35 | | -var Uint32Array = require( '@stdlib/array-uint32' ); |
36 | | -var Float32Array = require( '@stdlib/array-float32' ); |
37 | | -var Float64Array = require( '@stdlib/array-float64' ); |
38 | | -var ArrayBuffer = require( '@stdlib/array-buffer' ); |
39 | | -var Symbol = require( '@stdlib/symbol-ctor' ); |
40 | | -var Number = require( '@stdlib/number-ctor' ); |
41 | | -var Boolean = require( '@stdlib/boolean-ctor' ); |
42 | | -var isObjectLike = require( './../../dist' ); |
43 | | - |
44 | | - |
45 | | -// VARIABLES // |
46 | | - |
47 | | -var opts; |
| 24 | +var main = require( './../../dist' ); |
48 | 25 |
|
49 | 26 |
|
50 | 27 | // TESTS // |
51 | 28 |
|
52 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
53 | 30 | t.ok( true, __filename ); |
54 | | - t.strictEqual( typeof isObjectLike, 'function', 'export is a function' ); |
55 | | - t.end(); |
56 | | -}); |
57 | | - |
58 | | -tape( 'attached to the main export is a function to test if a value is an array of object-like elements', function test( t ) { |
59 | | - t.equal( typeof isObjectLike.isObjectLikeArray, 'function', 'has method' ); |
60 | | - t.end(); |
61 | | -}); |
62 | | - |
63 | | -tape( 'the function returns a boolean indicating if a value is object-like', function test( t ) { |
64 | | - var expected; |
65 | | - var values; |
66 | | - var bool; |
67 | | - var i; |
68 | | - |
69 | | - values = [ |
70 | | - 'a', |
71 | | - new String( 'a' ), // eslint-disable-line no-new-wrappers |
72 | | - 5, |
73 | | - new Number( 5 ), // eslint-disable-line no-new-wrappers |
74 | | - NaN, |
75 | | - true, |
76 | | - new Boolean( true ), // eslint-disable-line no-new-wrappers |
77 | | - false, |
78 | | - new Boolean( false ), // eslint-disable-line no-new-wrappers |
79 | | - void 0, |
80 | | - null, |
81 | | - [], |
82 | | - {}, |
83 | | - function noop() {}, |
84 | | - /./, |
85 | | - new Date(), |
86 | | - Math, |
87 | | - JSON, |
88 | | - new Error(), |
89 | | - new TypeError(), |
90 | | - new SyntaxError(), |
91 | | - new URIError(), |
92 | | - new EvalError(), |
93 | | - new ReferenceError(), |
94 | | - new RangeError(), |
95 | | - new Int8Array(), |
96 | | - new Uint8Array(), |
97 | | - new Uint8ClampedArray(), |
98 | | - new Int16Array(), |
99 | | - new Uint16Array(), |
100 | | - new Int32Array(), |
101 | | - new Uint32Array(), |
102 | | - new Float32Array(), |
103 | | - new Float64Array(), |
104 | | - new ArrayBuffer() |
105 | | - ]; |
106 | | - |
107 | | - expected = [ |
108 | | - false, // 'a' |
109 | | - true, // String |
110 | | - false, // 5 |
111 | | - true, // Number |
112 | | - false, // NaN |
113 | | - false, // true |
114 | | - true, // Boolean |
115 | | - false, // false |
116 | | - true, // Boolean |
117 | | - false, // void 0 |
118 | | - false, // null |
119 | | - true, // [] |
120 | | - true, // {} |
121 | | - false, // function |
122 | | - true, // RegExp |
123 | | - true, // Date |
124 | | - true, |
125 | | - true, |
126 | | - true, |
127 | | - true, |
128 | | - true, |
129 | | - true, |
130 | | - true, |
131 | | - true, |
132 | | - true, |
133 | | - true, |
134 | | - true, |
135 | | - true, |
136 | | - true, |
137 | | - true, |
138 | | - true, |
139 | | - true, |
140 | | - true, |
141 | | - true, |
142 | | - true |
143 | | - ]; |
144 | | - |
145 | | - for ( i = 0; i < values.length; i++ ) { |
146 | | - bool = isObjectLike( values[i] ); |
147 | | - t.equal( bool, expected[i], 'returns '+expected[i]+' when provided '+values[i] ); |
148 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
149 | 32 | t.end(); |
150 | 33 | }); |
151 | | - |
152 | | -opts = { |
153 | | - 'skip': !hasMap() |
154 | | -}; |
155 | | -tape( 'the function supports Map objects', opts, function test( t ) { |
156 | | - var bool = isObjectLike( new Map() ); |
157 | | - t.equal( bool, true, 'returns true' ); |
158 | | - t.end(); |
159 | | -}); |
160 | | - |
161 | | -opts = { |
162 | | - 'skip': !hasWeakMap() |
163 | | -}; |
164 | | -tape( 'the function supports WeakMap objects', opts, function test( t ) { |
165 | | - var bool = isObjectLike( new WeakMap() ); |
166 | | - t.equal( bool, true, 'returns true' ); |
167 | | - t.end(); |
168 | | -}); |
169 | | - |
170 | | -opts = { |
171 | | - 'skip': !hasSet() |
172 | | -}; |
173 | | -tape( 'the function supports Set objects', opts, function test( t ) { |
174 | | - var bool = isObjectLike( new Set() ); |
175 | | - t.equal( bool, true, 'returns true' ); |
176 | | - t.end(); |
177 | | -}); |
178 | | - |
179 | | -opts = { |
180 | | - 'skip': !hasWeakSet() |
181 | | -}; |
182 | | -tape( 'the function supports WeakSet objects', opts, function test( t ) { |
183 | | - var bool = isObjectLike( new WeakSet() ); |
184 | | - t.equal( bool, true, 'returns true' ); |
185 | | - t.end(); |
186 | | -}); |
187 | | - |
188 | | -opts = { |
189 | | - 'skip': !hasSymbols() |
190 | | -}; |
191 | | -tape( 'the function supports Symbol objects', opts, function test( t ) { |
192 | | - var bool = isObjectLike( Symbol( 'beep' ) ); |
193 | | - t.equal( bool, false, 'returns false' ); |
194 | | - t.end(); |
195 | | -}); |
196 | | - |
197 | | -tape( 'the function supports custom objects', function test( t ) { |
198 | | - var bool; |
199 | | - function Person() {} |
200 | | - bool = isObjectLike( new Person() ); |
201 | | - t.equal( bool, true, 'returns true' ); |
202 | | - t.end(); |
203 | | -}); |
204 | | - |
205 | | -// TODO: add generator function test |
0 commit comments