|
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. |
|
20 | 20 |
|
21 | 21 | // MODULES // |
22 | 22 |
|
23 | | -var vm = require( 'vm' ); // TODO: handle in-browser tests |
24 | 23 | var tape = require( 'tape' ); |
25 | | -var proxyquire = require( 'proxyquire' ); |
26 | | -var inherit = require( '@stdlib/utils-inherit' ); |
27 | | -var Int8Array = require( '@stdlib/array-int8' ); |
28 | | -var Uint8Array = require( '@stdlib/array-uint8' ); |
29 | | -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); |
30 | | -var Int16Array = require( '@stdlib/array-int16' ); |
31 | | -var Uint16Array = require( '@stdlib/array-uint16' ); |
32 | | -var Int32Array = require( '@stdlib/array-int32' ); |
33 | | -var Uint32Array = require( '@stdlib/array-uint32' ); |
34 | | -var Float32Array = require( '@stdlib/array-float32' ); |
35 | | -var Float64Array = require( '@stdlib/array-float64' ); |
36 | | -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); |
37 | | -var isTypedArray = require( './../../dist' ); |
38 | | - |
39 | | - |
40 | | -// VARIABLES // |
41 | | - |
42 | | -var opts = { |
43 | | - 'skip': IS_BROWSER |
44 | | -}; |
| 24 | +var main = require( './../../dist' ); |
45 | 25 |
|
46 | 26 |
|
47 | 27 | // TESTS // |
48 | 28 |
|
49 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
50 | 30 | t.ok( true, __filename ); |
51 | | - t.strictEqual( typeof isTypedArray, 'function', 'main export is a function' ); |
52 | | - t.end(); |
53 | | -}); |
54 | | - |
55 | | -tape( 'the function returns `true` if provided a typed array', function test( t ) { |
56 | | - var values; |
57 | | - var i; |
58 | | - |
59 | | - values = [ |
60 | | - new Int8Array( 10 ), |
61 | | - new Uint8Array( 10 ), |
62 | | - new Uint8ClampedArray( 10 ), |
63 | | - new Int16Array( 10 ), |
64 | | - new Uint16Array( 10 ), |
65 | | - new Int32Array( 10 ), |
66 | | - new Uint32Array( 10 ), |
67 | | - new Float32Array( 10 ), |
68 | | - new Float64Array( 10 ) |
69 | | - ]; |
70 | | - |
71 | | - for ( i = 0; i < values.length; i++ ) { |
72 | | - t.strictEqual( isTypedArray( values[i] ), true, 'returns true when provided '+values[i] ); |
73 | | - } |
74 | | - t.end(); |
75 | | -}); |
76 | | - |
77 | | -tape( 'the function returns `true` if provided a typed array (older environments)', function test( t ) { |
78 | | - var isTypedArray; |
79 | | - var values; |
80 | | - var i; |
81 | | - |
82 | | - isTypedArray = proxyquire( './../dist/main.js', { |
83 | | - '@stdlib/assert-has-float64array-support': hasSupport |
84 | | - }); |
85 | | - |
86 | | - values = [ |
87 | | - new Int8Array( 10 ), |
88 | | - new Uint8Array( 10 ), |
89 | | - new Uint8ClampedArray( 10 ), |
90 | | - new Int16Array( 10 ), |
91 | | - new Uint16Array( 10 ), |
92 | | - new Int32Array( 10 ), |
93 | | - new Uint32Array( 10 ), |
94 | | - new Float32Array( 10 ), |
95 | | - new Float64Array( 10 ) |
96 | | - ]; |
97 | | - |
98 | | - for ( i = 0; i < values.length; i++ ) { |
99 | | - t.strictEqual( isTypedArray( values[i] ), true, 'returns true when provided '+values[i] ); |
100 | | - } |
101 | | - t.end(); |
102 | | - |
103 | | - function hasSupport() { |
104 | | - return false; |
105 | | - } |
106 | | -}); |
107 | | - |
108 | | -tape( 'the function returns `true` if an environment does not support the abstract TypedArray class (e.g., IE 11)', function test( t ) { |
109 | | - var isTypedArray; |
110 | | - var values; |
111 | | - var i; |
112 | | - |
113 | | - isTypedArray = proxyquire( './../dist/main.js', { |
114 | | - '@stdlib/utils-get-prototype-of': getPrototypeOf |
115 | | - }); |
116 | | - |
117 | | - values = [ |
118 | | - new Int8Array( 10 ), |
119 | | - new Uint8Array( 10 ), |
120 | | - new Uint8ClampedArray( 10 ), |
121 | | - new Int16Array( 10 ), |
122 | | - new Uint16Array( 10 ), |
123 | | - new Int32Array( 10 ), |
124 | | - new Uint32Array( 10 ), |
125 | | - new Float32Array( 10 ), |
126 | | - new Float64Array( 10 ) |
127 | | - ]; |
128 | | - |
129 | | - for ( i = 0; i < values.length; i++ ) { |
130 | | - t.strictEqual( isTypedArray( values[i] ), true, 'returns true when provided '+values[i] ); |
131 | | - } |
132 | | - t.end(); |
133 | | - |
134 | | - function getPrototypeOf() { |
135 | | - // Return an anonymous function: |
136 | | - return function () {}; // eslint-disable-line func-names |
137 | | - } |
138 | | -}); |
139 | | - |
140 | | -tape( 'the function returns `true` if provided an object inheriting from a typed array', function test( t ) { |
141 | | - function CustomArray( data ) { |
142 | | - var i; |
143 | | - for ( i = 0; i < data.length; i++ ) { |
144 | | - this[ i ] = data[ i ]; |
145 | | - } |
146 | | - return this; |
147 | | - } |
148 | | - |
149 | | - inherit( CustomArray, Float64Array ); |
150 | | - |
151 | | - t.strictEqual( isTypedArray( new CustomArray( [ 5.0, 3.0 ] ) ), true, 'returns true when provided a value which inherits from a typed array' ); |
152 | | - t.end(); |
153 | | -}); |
154 | | - |
155 | | -tape( 'the function returns `true` if provided a typed array from a different realm', opts, function test( t ) { |
156 | | - var arr = vm.runInNewContext( 'new Float64Array( [ 5.0, 3.0 ] )' ); |
157 | | - t.strictEqual( isTypedArray( arr ), true, 'returns true' ); |
158 | | - t.end(); |
159 | | -}); |
160 | | - |
161 | | -tape( 'the function returns `true` if provided an object from a different realm which inherits from a typed array', opts, function test( t ) { |
162 | | - var arr = vm.runInNewContext( 'function Arr() { return this; }; Arr.prototype = Object.create( Float64Array.prototype ); Arr.prototype.constructor = Arr; new Arr( [ 5.0, 3.0 ] );' ); |
163 | | - t.strictEqual( isTypedArray( arr ), true, 'returns true' ); |
164 | | - t.end(); |
165 | | -}); |
166 | | - |
167 | | -tape( 'the function returns `false` if not provided a typed array', function test( t ) { |
168 | | - var values; |
169 | | - var i; |
170 | | - |
171 | | - values = [ |
172 | | - '5', |
173 | | - 5, |
174 | | - NaN, |
175 | | - null, |
176 | | - void 0, |
177 | | - true, |
178 | | - false, |
179 | | - [], |
180 | | - {}, |
181 | | - function noop() {} |
182 | | - ]; |
183 | | - |
184 | | - for ( i = 0; i < values.length; i++ ) { |
185 | | - t.strictEqual( isTypedArray( values[i] ), false, 'returns false when provided '+values[i] ); |
186 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
187 | 32 | t.end(); |
188 | 33 | }); |
0 commit comments