mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add structural comparison
This commit is contained in:
39
inputs/passing/structureCmp.ts
Normal file
39
inputs/passing/structureCmp.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
//! test_output(24)
|
||||
|
||||
export default function () {
|
||||
let count = 0;
|
||||
|
||||
const cases: [unknown, unknown, { loose: boolean; strict: boolean }][] = [
|
||||
[[], [], { loose: true, strict: true }],
|
||||
[[], [1], { loose: false, strict: false }],
|
||||
[[1, 2, 3], [1, 2, 3], { loose: true, strict: true }],
|
||||
[[1, 2, 3], [1, "2", 3], { loose: true, strict: false }],
|
||||
[{}, {}, { loose: true, strict: true }],
|
||||
[{}, { x: 1 }, { loose: false, strict: false }],
|
||||
[{}, { [Symbol.iterator]: 1 }, { loose: false, strict: false }],
|
||||
[{ x: 1, y: 2, z: 3 }, { x: 1, y: 2, z: 3 }, { loose: true, strict: true }],
|
||||
[{ x: 1, y: 2, z: 3 }, { x: 1, y: "2", z: 3 }, {
|
||||
loose: true,
|
||||
strict: false,
|
||||
}],
|
||||
[[[[[[1]]]]], [[[[[1]]]]], { loose: true, strict: true }],
|
||||
[[[[[["1"]]]]], [[[[[1]]]]], { loose: true, strict: false }],
|
||||
[null, undefined, { loose: true, strict: false }],
|
||||
];
|
||||
|
||||
for (const [left, right, { loose, strict }] of cases) {
|
||||
if ((left == right) === loose) {
|
||||
count++;
|
||||
} else {
|
||||
throw new Error(`Expected ${left} == ${right} to be ${loose}`);
|
||||
}
|
||||
|
||||
if ((left === right) === strict) {
|
||||
count++;
|
||||
} else {
|
||||
throw new Error(`Expected ${left} === ${right} to be ${strict}`);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
Reference in New Issue
Block a user