1 | 'use strict';
|
---|
2 |
|
---|
3 | var test = require('tape');
|
---|
4 | var isDataView = require('../');
|
---|
5 |
|
---|
6 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
7 | var generators = require('make-generator-function')();
|
---|
8 | var arrowFns = require('make-arrow-function').list();
|
---|
9 | var forEach = require('for-each');
|
---|
10 | var v = require('es-value-fixtures');
|
---|
11 | var inspect = require('object-inspect');
|
---|
12 | var availableTypedArrays = require('available-typed-arrays')();
|
---|
13 |
|
---|
14 | test('not DataViews', function (t) {
|
---|
15 | forEach([].concat(
|
---|
16 | // @ts-expect-error TS sucks at [].concat
|
---|
17 | v.primitives,
|
---|
18 | v.objects,
|
---|
19 | function () {},
|
---|
20 | generators,
|
---|
21 | arrowFns,
|
---|
22 | []
|
---|
23 | ), /** @type {(nonDV: unknown) => void} */ function (nonDV) {
|
---|
24 | t.equal(
|
---|
25 | isDataView(nonDV),
|
---|
26 | false,
|
---|
27 | inspect(nonDV) + ' is not a DataView'
|
---|
28 | );
|
---|
29 | });
|
---|
30 |
|
---|
31 | forEach(availableTypedArrays, function (typedArray) {
|
---|
32 | var TA = global[typedArray];
|
---|
33 | var ta = new TA(8);
|
---|
34 | t.equal(isDataView(ta), false, inspect(ta) + ' is not a DataView');
|
---|
35 | });
|
---|
36 |
|
---|
37 | t.end();
|
---|
38 | });
|
---|
39 |
|
---|
40 | test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
|
---|
41 | forEach(availableTypedArrays, function (typedArray) {
|
---|
42 | // @ts-expect-error
|
---|
43 | var fakeTypedArray = [];
|
---|
44 | // @ts-expect-error
|
---|
45 | fakeTypedArray[Symbol.toStringTag] = typedArray;
|
---|
46 | // @ts-expect-error
|
---|
47 | t.notOk(isDataView(fakeTypedArray), 'faked ' + typedArray + ' is not typed array');
|
---|
48 | });
|
---|
49 |
|
---|
50 | t.end();
|
---|
51 | });
|
---|
52 |
|
---|
53 | test('Data Views', { skip: typeof DataView !== 'function' }, function (t) {
|
---|
54 | var ab = new ArrayBuffer(1);
|
---|
55 | var dv = new DataView(ab);
|
---|
56 |
|
---|
57 | t.equal(isDataView(dv), true, inspect(dv) + ' is a DataView');
|
---|
58 |
|
---|
59 | t.end();
|
---|
60 | });
|
---|