|
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 proxyquire = require( 'proxyquire' ); |
25 |
| -var hasArrayBufferSupport = require( '@stdlib/assert-has-arraybuffer-support' ); |
26 |
| -var isFunction = require( '@stdlib/assert-is-function' ); |
27 |
| -var instanceOf = require( '@stdlib/assert-instance-of' ); |
28 |
| -var Float64Array = require( '@stdlib/array-float64' ); |
29 |
| -var MAX_SAFE_INTEGER = require( '@stdlib/constants-float64-max-safe-integer' ); |
30 |
| -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); |
31 |
| -var hasProp = require( '@stdlib/assert-has-property' ); |
32 |
| -var NODE_VERSION = require( '@stdlib/process-node-version' ); |
33 |
| -var polyfill = require( './../../dist/polyfill.js' ); |
34 |
| -var Ctor = require( './../../dist' ); |
35 |
| - |
36 |
| - |
37 |
| -// VARIABLES // |
38 |
| - |
39 |
| -var FLG = hasArrayBufferSupport(); |
40 |
| -var opts = { |
41 |
| - 'skip': ( NODE_VERSION && NODE_VERSION.slice( 0, 4 ) === '0.10' ) // FIXME: remove once polyfill is written |
42 |
| -}; |
| 24 | +var main = require( './../../dist' ); |
43 | 25 |
|
44 | 26 |
|
45 | 27 | // TESTS //
|
46 | 28 |
|
47 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
48 | 30 | t.ok( true, __filename );
|
49 |
| - t.strictEqual( typeof Ctor, 'function', 'main export is a function' ); |
50 |
| - t.end(); |
51 |
| -}); |
52 |
| - |
53 |
| -tape( 'if an environment supports `ArrayBuffer`, the export is an alias for `ArrayBuffer`', function test( t ) { |
54 |
| - var Foo = proxyquire( './../dist', { |
55 |
| - '@stdlib/assert-has-arraybuffer-support': isTrue, |
56 |
| - './main.js': Mock |
57 |
| - }); |
58 |
| - t.strictEqual( Foo, Mock, 'returns builtin' ); |
59 |
| - |
60 |
| - if ( FLG ) { |
61 |
| - t.strictEqual( Ctor, ArrayBuffer, 'is alias' ); // eslint-disable-line stdlib/require-globals |
62 |
| - } |
63 |
| - |
64 |
| - t.end(); |
65 |
| - |
66 |
| - function Mock() { |
67 |
| - return this; |
68 |
| - } |
69 |
| - |
70 |
| - function isTrue() { |
71 |
| - return true; |
72 |
| - } |
73 |
| -}); |
74 |
| - |
75 |
| -tape( 'if an environment does not support `ArrayBuffer`, the export is a polyfill', function test( t ) { |
76 |
| - var Foo = proxyquire( './../dist', { |
77 |
| - '@stdlib/assert-has-arraybuffer-support': isFalse |
78 |
| - }); |
79 |
| - |
80 |
| - t.strictEqual( Foo, polyfill, 'returns polyfill' ); |
81 |
| - t.end(); |
82 |
| - |
83 |
| - function isFalse() { |
84 |
| - return false; |
85 |
| - } |
86 |
| -}); |
87 |
| - |
88 |
| -tape( 'the main export is a constructor', opts, function test( t ) { |
89 |
| - var buf = new Ctor( 10 ); |
90 |
| - t.strictEqual( instanceOf( buf, Ctor ), true, 'returns an instance' ); |
91 |
| - t.end(); |
92 |
| -}); |
93 |
| - |
94 |
| -tape( 'the constructor has a static method for testing whether a value is a buffer view', opts, function test( t ) { |
95 |
| - var arr; |
96 |
| - |
97 |
| - t.strictEqual( isFunction( Ctor.isView ), true, 'has method' ); |
98 |
| - |
99 |
| - arr = new Float64Array( 10 ); |
100 |
| - t.strictEqual( Ctor.isView( arr ), true, 'returns expected value' ); |
101 |
| - t.strictEqual( Ctor.isView( [] ), false, 'returns expected value' ); |
102 |
| - |
103 |
| - t.end(); |
104 |
| -}); |
105 |
| - |
106 |
| -tape( 'the constructor length is equal to `1`', opts, function test( t ) { |
107 |
| - t.strictEqual( Ctor.length, 1, 'returns expected value' ); |
108 |
| - t.end(); |
109 |
| -}); |
110 |
| - |
111 |
| -tape( 'the constructor throws an error if provided a value exceeding `2^53-1`', opts, function test( t ) { |
112 |
| - t.throws( badValue, RangeError, 'throws an error' ); |
113 |
| - t.end(); |
114 |
| - |
115 |
| - function badValue() { |
116 |
| - return new Ctor( MAX_SAFE_INTEGER+1 ); |
117 |
| - } |
118 |
| -}); |
119 |
| - |
120 |
| -tape( 'the constructor returns an `ArrayBuffer` instance having a `byteLength` property, which returns the number of bytes in an `ArrayBuffer`', opts, function test( t ) { |
121 |
| - var buf; |
122 |
| - |
123 |
| - t.strictEqual( hasOwnProp( Ctor.prototype, 'byteLength' ), true, 'has prototype property' ); |
124 |
| - |
125 |
| - buf = new Ctor( 10 ); |
126 |
| - t.strictEqual( hasOwnProp( buf, 'byteLength' ), false, 'does not have own property' ); |
127 |
| - t.strictEqual( hasProp( buf, 'byteLength' ), true, 'has property' ); |
128 |
| - t.strictEqual( buf.byteLength, 10, 'returns expected value' ); |
129 |
| - |
130 |
| - t.end(); |
131 |
| -}); |
132 |
| - |
133 |
| -tape( 'the constructor returns an `ArrayBuffer` instance having a `slice` method, which copies the bytes of an `ArrayBuffer` to a new `ArrayBuffer`', opts, function test( t ) { |
134 |
| - var b1; |
135 |
| - var b2; |
136 |
| - |
137 |
| - t.strictEqual( hasOwnProp( Ctor.prototype, 'slice' ), true, 'has prototype property' ); |
138 |
| - t.strictEqual( isFunction( Ctor.prototype.slice ), true, 'has method' ); |
139 |
| - |
140 |
| - b1 = new Ctor( 10 ); |
141 |
| - t.strictEqual( hasOwnProp( b1, 'slice' ), false, 'does not have own property' ); |
142 |
| - t.strictEqual( hasProp( b1, 'slice' ), true, 'has property' ); |
143 |
| - |
144 |
| - b2 = b1.slice(); |
145 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
146 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
147 |
| - t.strictEqual( b2.byteLength, b1.byteLength, 'has same number of bytes' ); |
148 |
| - |
149 |
| - b2 = b1.slice( 2 ); |
150 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
151 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
152 |
| - t.strictEqual( b2.byteLength, 8, 'has expected number of bytes' ); |
153 |
| - |
154 |
| - b2 = b1.slice( b1.byteLength + 10 ); |
155 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
156 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
157 |
| - t.strictEqual( b2.byteLength, 0, 'has expected number of bytes' ); |
158 |
| - |
159 |
| - b2 = b1.slice( -2 ); |
160 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
161 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
162 |
| - t.strictEqual( b2.byteLength, 2, 'has expected number of bytes' ); |
163 |
| - |
164 |
| - b2 = b1.slice( -100 ); |
165 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
166 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
167 |
| - t.strictEqual( b2.byteLength, 10, 'has expected number of bytes' ); |
168 |
| - |
169 |
| - b2 = b1.slice( 0, 6 ); |
170 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
171 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
172 |
| - t.strictEqual( b2.byteLength, 6, 'has expected number of bytes' ); |
173 |
| - |
174 |
| - b2 = b1.slice( 2, 6 ); |
175 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
176 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
177 |
| - t.strictEqual( b2.byteLength, 4, 'has expected number of bytes' ); |
178 |
| - |
179 |
| - b2 = b1.slice( 0, -2 ); |
180 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
181 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
182 |
| - t.strictEqual( b2.byteLength, 8, 'has expected number of bytes' ); |
183 |
| - |
184 |
| - b2 = b1.slice( 0, -100 ); |
185 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
186 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
187 |
| - t.strictEqual( b2.byteLength, 0, 'has expected number of bytes' ); |
188 |
| - |
189 |
| - b2 = b1.slice( -4, -2 ); |
190 |
| - t.strictEqual( instanceOf( b2, Ctor ), true, 'returns an instance' ); |
191 |
| - t.notEqual( b2, b1, 'returns a new reference' ); |
192 |
| - t.strictEqual( b2.byteLength, 2, 'has expected number of bytes' ); |
193 |
| - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
194 | 32 | t.end();
|
195 | 33 | });
|
0 commit comments