forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-assert-typedarray-deepequal.js
More file actions
150 lines (142 loc) · 5.6 KB
/
Copy pathtest-assert-typedarray-deepequal.js
File metadata and controls
150 lines (142 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
require('../common');
const assert = require('assert');
const { test, suite } = require('node:test');
function makeBlock(f) {
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return f.apply(this, args);
};
}
suite('equalArrayPairs', () => {
const equalArrayPairs = [
[new Uint8Array(1e5), new Uint8Array(1e5)],
[new Uint16Array(1e5), new Uint16Array(1e5)],
[new Uint32Array(1e5), new Uint32Array(1e5)],
[new Uint8ClampedArray(1e5), new Uint8ClampedArray(1e5)],
[new Int8Array(1e5), new Int8Array(1e5)],
[new Int16Array(1e5), new Int16Array(1e5)],
[new Int32Array(1e5), new Int32Array(1e5)],
[new Float16Array(1e5), new Float16Array(1e5)],
[new Float32Array(1e5), new Float32Array(1e5)],
[new Float64Array(1e5), new Float64Array(1e5)],
[new Float32Array([+0.0]), new Float32Array([+0.0])],
[new Uint8Array([1, 2, 3, 4]).subarray(1), new Uint8Array([2, 3, 4])],
[new Uint16Array([1, 2, 3, 4]).subarray(1), new Uint16Array([2, 3, 4])],
[new Uint32Array([1, 2, 3, 4]).subarray(1, 3), new Uint32Array([2, 3])],
[new ArrayBuffer(3), new ArrayBuffer(3)],
[new SharedArrayBuffer(3), new SharedArrayBuffer(3)],
];
for (const arrayPair of equalArrayPairs) {
test('', () => {
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(arrayPair[0], arrayPair[1]);
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(arrayPair[1], arrayPair[0]);
assert.deepStrictEqual(arrayPair[0], arrayPair[1]);
assert.deepStrictEqual(arrayPair[1], arrayPair[0]);
assert.partialDeepStrictEqual(arrayPair[0], arrayPair[1]);
assert.partialDeepStrictEqual(arrayPair[1], arrayPair[0]);
});
}
});
suite('looseEqualArrayPairs', () => {
const looseEqualArrayPairs = [
[new Float16Array([+0.0]), new Float16Array([-0.0])],
[new Float32Array([+0.0]), new Float32Array([-0.0])],
[new Float64Array([+0.0]), new Float64Array([-0.0])],
];
for (const arrayPair of looseEqualArrayPairs) {
test('', () => {
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(arrayPair[0], arrayPair[1]);
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(arrayPair[1], arrayPair[0]);
assert.throws(
makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.deepStrictEqual, arrayPair[1], arrayPair[0]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.partialDeepStrictEqual, arrayPair[0], arrayPair[1]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.partialDeepStrictEqual, arrayPair[1], arrayPair[0]),
assert.AssertionError
);
});
}
});
suite('notEqualArrayPairs', () => {
const notEqualArrayPairs = [
[new ArrayBuffer(3), new SharedArrayBuffer(3)],
[new Int16Array(256), new Uint16Array(256)],
[new Int16Array([256]), new Uint16Array([256])],
[new Float64Array([+0.0]), new Float32Array([-0.0])],
[new Uint8Array(2), new Uint8Array(3), 'unequal length'],
[new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
[new Uint8ClampedArray([300, 2, 3]), new Uint8Array([300, 2, 3])],
[new Uint16Array([2]), new Uint16Array([3])],
[new Uint16Array([0]), new Uint16Array([256])],
[new Int16Array([0]), new Uint16Array([256])],
[new Int16Array([-256]), new Uint16Array([0xff00])], // same bits
[new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto
[new Float16Array([0.1]), new Float16Array([0.0])],
[new Float16Array([0.1]), new Float16Array([0.1, 0.2]), 'unequal length'],
[new Float32Array([0.1]), new Float32Array([0.0])],
[new Float32Array([0.1]), new Float32Array([0.1, 0.2]), 'unequal length'],
[new Float64Array([0.1]), new Float64Array([0.0])],
[new Uint8Array([1, 2, 3]).buffer, new Uint8Array([4, 5, 6]).buffer],
[
new Uint8Array(new SharedArrayBuffer(3)).fill(1).buffer,
new Uint8Array(new SharedArrayBuffer(3)).fill(2).buffer,
],
[new ArrayBuffer(2), new ArrayBuffer(3), 'unequal length'],
[new SharedArrayBuffer(2), new SharedArrayBuffer(3), 'unequal length'],
[new ArrayBuffer(2), new SharedArrayBuffer(3)],
[
new Uint8Array(new ArrayBuffer(3)).fill(1).buffer,
new Uint8Array(new SharedArrayBuffer(3)).fill(2).buffer,
],
[new ArrayBuffer(3), new SharedArrayBuffer(3)],
[new SharedArrayBuffer(2), new ArrayBuffer(2)],
];
for (const arrayPair of notEqualArrayPairs) {
test('', () => {
assert.throws(
// eslint-disable-next-line no-restricted-properties
makeBlock(assert.deepEqual, arrayPair[0], arrayPair[1]),
assert.AssertionError
);
assert.throws(
// eslint-disable-next-line no-restricted-properties
makeBlock(assert.deepEqual, arrayPair[1], arrayPair[0]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.deepStrictEqual, arrayPair[1], arrayPair[0]),
assert.AssertionError
);
assert.throws(
makeBlock(assert.partialDeepStrictEqual, arrayPair[0], arrayPair[1]),
assert.AssertionError
);
if (arrayPair[2]) {
assert.partialDeepStrictEqual(arrayPair[1], arrayPair[0]);
} else {
assert.throws(
makeBlock(assert.partialDeepStrictEqual, arrayPair[1], arrayPair[0]),
assert.AssertionError
);
}
});
}
});