import { describe, expect, test } from "vitest";
import { makeUniqueFileName, makeUniqueTitle } from "./naming";

describe("file-tree/naming", () => {
  test("makeUniqueTitle", () => {
    const existing = new Set<string>(["无标题", "无标题 副本"]);
    expect(makeUniqueTitle("无标题", existing)).toBe("无标题 副本 2");
    expect(makeUniqueTitle("Hello", existing)).toBe("Hello");
    expect(makeUniqueTitle("Hello", existing)).toBe("Hello 副本");
  });

  test("makeUniqueFileName keeps extension", () => {
    const existing = new Set<string>(["a.txt", "a 副本.txt"]);
    expect(makeUniqueFileName("a.txt", existing)).toBe("a 副本 2.txt");
    expect(makeUniqueFileName("图片.png", existing)).toBe("图片.png");
    expect(makeUniqueFileName("图片.png", existing)).toBe("图片 副本.png");
    expect(makeUniqueFileName("无扩展名", existing)).toBe("无扩展名");
    expect(makeUniqueFileName("无扩展名", existing)).toBe("无扩展名 副本");
  });
});

