[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 isArrayBuffer = require('..');
|
---|
| 10 |
|
---|
| 11 | test('isArrayBuffer', function (t) {
|
---|
| 12 | t.equal(typeof isArrayBuffer, 'function', 'is a function');
|
---|
| 13 |
|
---|
| 14 | /** @type {unknown[]} */
|
---|
| 15 | var nonABs = [].concat(
|
---|
| 16 | // @ts-expect-error TS sucks with [].concat
|
---|
| 17 | v.primitives,
|
---|
| 18 | v.objects,
|
---|
| 19 | typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(0) : []
|
---|
| 20 | );
|
---|
| 21 | forEach(nonABs, function (nonAB) {
|
---|
| 22 | t.equal(isArrayBuffer(nonAB), false, inspect(nonAB) + ' is not an ArrayBuffer');
|
---|
| 23 | });
|
---|
| 24 |
|
---|
| 25 | t.test('actual ArrayBuffer instances', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
|
---|
| 26 | // @ts-expect-error TS grumbles about 0 args
|
---|
| 27 | var ab = new ArrayBuffer();
|
---|
| 28 | st.equal(isArrayBuffer(ab), true, inspect(ab) + ' is an ArrayBuffer');
|
---|
| 29 |
|
---|
| 30 | var ab42 = new ArrayBuffer(42);
|
---|
| 31 | st.equal(isArrayBuffer(ab42), true, inspect(ab42) + ' is an ArrayBuffer');
|
---|
| 32 |
|
---|
| 33 | var dv = new DataView(ab42);
|
---|
| 34 | st.equal(isArrayBuffer(dv), false, inspect(dv) + ' is not an ArrayBuffer');
|
---|
| 35 |
|
---|
| 36 | st.end();
|
---|
| 37 | });
|
---|
| 38 |
|
---|
| 39 | t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
|
---|
| 40 | forEach(availableTypedArrays, function (TypedArray) {
|
---|
| 41 | var ta = new global[TypedArray](0);
|
---|
| 42 | st.equal(isArrayBuffer(ta.buffer), true, inspect(ta.buffer) + ', the TA\'s buffer, is an ArrayBuffer');
|
---|
| 43 | st.equal(isArrayBuffer(ta), false, inspect(ta) + ' is not an ArrayBuffer');
|
---|
| 44 | });
|
---|
| 45 |
|
---|
| 46 | st.end();
|
---|
| 47 | });
|
---|
| 48 |
|
---|
| 49 | t.end();
|
---|
| 50 | });
|
---|