mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
d102a10235
* refactor: import from `@std/assert` * update
34 lines
855 B
TypeScript
34 lines
855 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "@std/assert";
|
|
import { invertBy } from "./invert_by.ts";
|
|
|
|
function invertByTest<R extends Record<PropertyKey, PropertyKey>>(
|
|
input: [Readonly<R>, (key: PropertyKey) => PropertyKey],
|
|
expected: Record<PropertyKey, PropertyKey[]>,
|
|
) {
|
|
const actual = invertBy(...input);
|
|
assertEquals(actual, expected);
|
|
}
|
|
|
|
Deno.test("invertBy()", () => {
|
|
invertByTest(
|
|
[{ a: "x", b: "y", c: "z" }, (key) => String(key).toUpperCase()],
|
|
{ X: ["a"], Y: ["b"], Z: ["c"] },
|
|
);
|
|
});
|
|
|
|
Deno.test("invertBy() handles empty input", () => {
|
|
invertByTest(
|
|
[{}, (key) => key],
|
|
{},
|
|
);
|
|
});
|
|
|
|
Deno.test("invertBy() handles duplicate values", () => {
|
|
invertByTest(
|
|
[{ a: "x", b: "x", c: "z" }, (key) => key],
|
|
{ x: ["a", "b"], z: ["c"] },
|
|
);
|
|
});
|