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