[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var inspect = require('object-inspect');
|
---|
| 5 | var forEach = require('for-each');
|
---|
| 6 | var v = require('es-value-fixtures');
|
---|
| 7 | var availableTypedArrays = require('available-typed-arrays')();
|
---|
| 8 |
|
---|
| 9 | var isSharedArrayBuffer = require('..');
|
---|
| 10 |
|
---|
| 11 | test('isSharedArrayBuffer', function (t) {
|
---|
| 12 | t.equal(typeof isSharedArrayBuffer, 'function', 'is a function');
|
---|
| 13 |
|
---|
| 14 | // @ts-expect-error TS sucks with concat
|
---|
| 15 | var nonSABs = [].concat(v.primitives, v.objects);
|
---|
| 16 | forEach(nonSABs, function (nonSAB) {
|
---|
| 17 | t.equal(isSharedArrayBuffer(nonSAB), false, inspect(nonSAB) + ' is not a SharedArrayBuffer');
|
---|
| 18 | });
|
---|
| 19 |
|
---|
| 20 | t.test('actual SharedArrayBuffer instances', { skip: typeof SharedArrayBuffer === 'undefined' }, function (st) {
|
---|
| 21 | var sab = new SharedArrayBuffer(0);
|
---|
| 22 |
|
---|
| 23 | st.equal(isSharedArrayBuffer(sab), true, inspect(sab) + ' is a SharedArrayBuffer');
|
---|
| 24 |
|
---|
| 25 | st.end();
|
---|
| 26 | });
|
---|
| 27 |
|
---|
| 28 | t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
|
---|
| 29 | forEach(availableTypedArrays, function (TypedArray) {
|
---|
| 30 | var ta = new global[TypedArray](0);
|
---|
| 31 | st.equal(isSharedArrayBuffer(ta.buffer), false, inspect(ta.buffer) + ', the TA\'s buffer, is not a SharedArrayBuffer');
|
---|
| 32 | st.equal(isSharedArrayBuffer(ta), false, inspect(ta) + ' is not a SharedArrayBuffer');
|
---|
| 33 | });
|
---|
| 34 |
|
---|
| 35 | st.end();
|
---|
| 36 | });
|
---|
| 37 |
|
---|
| 38 | t.end();
|
---|
| 39 | });
|
---|