sdlc-hub/web/src/test/canon.test.ts

18 lines
883 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import vm from "node:vm";
import { describe, expect, it } from "vitest";
import { canon } from "./canon.ts";
describe("canon", () => {
it("сортирует ключи объектов и выбрасывает undefined", () => {
expect(JSON.stringify(canon({ b: 1, a: { d: undefined, c: [2, 1] } }))).toBe('{"a":{"c":[2,1]},"b":1}');
});
it("Set — отсортированный массив, в том числе из другого realm", () => {
const foreign = vm.runInNewContext('new Set(["b", "a"])');
expect(canon(foreign)).toEqual(["a", "b"]);
expect(canon(new Set([{ k: 2 }, { k: 1 }]))).toEqual([{ k: 1 }, { k: 2 }]);
});
it("порядок Set не зависит от локали: сравнение по кодам символов", () => {
expect(canon(new Set(["б", "Б", "b", "B"]))).toEqual(["B", "b", "Б", "б"]);
});
});