50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveCreatureName } from "../auto-number.js";
|
|
|
|
describe("resolveCreatureName", () => {
|
|
it("returns name as-is when no conflict exists", () => {
|
|
const result = resolveCreatureName("Goblin", ["Orc", "Dragon"]);
|
|
expect(result).toEqual({ newName: "Goblin", renames: [] });
|
|
});
|
|
|
|
it("returns name as-is when existing list is empty", () => {
|
|
const result = resolveCreatureName("Goblin", []);
|
|
expect(result).toEqual({ newName: "Goblin", renames: [] });
|
|
});
|
|
|
|
it("renames existing to 'Name 1' and new to 'Name 2' on first conflict", () => {
|
|
const result = resolveCreatureName("Goblin", ["Orc", "Goblin", "Dragon"]);
|
|
expect(result).toEqual({
|
|
newName: "Goblin 2",
|
|
renames: [{ from: "Goblin", to: "Goblin 1" }],
|
|
});
|
|
});
|
|
|
|
it("appends next number when numbered variants already exist", () => {
|
|
const result = resolveCreatureName("Goblin", ["Goblin 1", "Goblin 2"]);
|
|
expect(result).toEqual({ newName: "Goblin 3", renames: [] });
|
|
});
|
|
|
|
it("handles mixed exact and numbered matches", () => {
|
|
const result = resolveCreatureName("Goblin", [
|
|
"Goblin",
|
|
"Goblin 1",
|
|
"Goblin 2",
|
|
]);
|
|
expect(result).toEqual({ newName: "Goblin 3", renames: [] });
|
|
});
|
|
|
|
it("handles names with special regex characters", () => {
|
|
const result = resolveCreatureName("Goblin (Boss)", ["Goblin (Boss)"]);
|
|
expect(result).toEqual({
|
|
newName: "Goblin (Boss) 2",
|
|
renames: [{ from: "Goblin (Boss)", to: "Goblin (Boss) 1" }],
|
|
});
|
|
});
|
|
|
|
it("does not match partial name overlaps", () => {
|
|
const result = resolveCreatureName("Goblin", ["Goblin Boss"]);
|
|
expect(result).toEqual({ newName: "Goblin", renames: [] });
|
|
});
|
|
});
|