forked from rocicorp/replicache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.test.ts
More file actions
56 lines (50 loc) · 1.13 KB
/
Copy pathjson.test.ts
File metadata and controls
56 lines (50 loc) · 1.13 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
import {assert} from '@esm-bundle/chai';
import {deepEqual} from './json.js';
import type {JSONValue} from './json.js';
const {fail} = assert;
test('JSON deep equal', () => {
const t = (
a: JSONValue | undefined,
b: JSONValue | undefined,
expected = true,
) => {
const res = deepEqual(a, b);
if (res !== expected) {
fail(
JSON.stringify(a) + (expected ? ' === ' : ' !== ') + JSON.stringify(b),
);
}
};
const oneLevelOfData = [
0,
1,
2,
3,
456789,
true,
false,
null,
'',
'a',
'b',
'cdefefsfsafasdadsaas',
[],
{},
{x: 4, y: 5, z: 6},
[7, 8, 9],
] as const;
const testData = [
...oneLevelOfData,
[...oneLevelOfData],
Object.fromEntries(oneLevelOfData.map(v => [JSON.stringify(v), v])),
];
for (let i = 0; i < testData.length; i++) {
for (let j = 0; j < testData.length; j++) {
const a = testData[i];
// "clone" to ensure we do not end up with a and b being the same object.
const b = JSON.parse(JSON.stringify(testData[j]));
t(a, b, i === j);
}
}
t({a: 1, b: 2}, {b: 2, a: 1});
});