mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Adds unsafe<T>(), recursive<T>(), Validator.validate() (check plus errors, no coercion), bigint(), equal(), validation and coercion of TypeBox's Type.BigInt/Type.Undefined, and Static for TypeBox's Enum, Tuple, BigInt and Undefined. Also fixes a required property set to undefined being rejected when its schema accepts undefined, as TypeBox allows.
29 lines
694 B
TypeScript
29 lines
694 B
TypeScript
// equal(): JSON equality, a drop-in for TypeBox's Value.Equal.
|
|
|
|
import { Value } from "typebox/value";
|
|
import { describe, expect, it } from "vitest";
|
|
import { equal } from "../src/index.ts";
|
|
|
|
describe("equal", () => {
|
|
it("compares JSON values structurally, as TypeBox's Value.Equal does", () => {
|
|
const cases: [unknown, unknown][] = [
|
|
[1, 1],
|
|
["a", "b"],
|
|
[null, null],
|
|
[null, undefined],
|
|
[
|
|
{ a: 1, b: [1, { c: 2 }] },
|
|
{ b: [1, { c: 2 }], a: 1 },
|
|
],
|
|
[{ a: 1 }, { a: 1, b: 2 }],
|
|
[
|
|
[1, 2],
|
|
[2, 1],
|
|
],
|
|
[[1], { 0: 1 }],
|
|
[{}, []],
|
|
[{ a: undefined }, {}],
|
|
];
|
|
for (const [a, b] of cases) expect(equal(a, b)).toBe(Value.Equal(a, b));
|
|
});
|
|
});
|