CoreTextPlace/tests/character.test.ts
laosb 32534084df refactor: Migrate project from Deno to pnpm/Node
Replace Deno configs and workflows with pnpm/Node tooling Add
package.json, jsr.json, build.config.ts and pnpm-lock.yaml Remove
deno.json, deno.lock, Deno build scripts and workflow Move source files
into src/ and update imports and tests to vitest Add Test CI workflow
and adapt publish jobs for pnpm/node Update editor settings, tasks,
.gitignore and bump LICENSE year
2025-11-29 19:11:49 +08:00

40 lines
1.3 KiB
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 { it, expect } from "vitest";
import { getCharacterWidth } from "../src/mod.ts";
it("getCharacterWidth ASCII", () => {
expect(getCharacterWidth("a")).toBe(1);
expect(getCharacterWidth("A")).toBe(1);
expect(getCharacterWidth("1")).toBe(1);
expect(getCharacterWidth("@")).toBe(1);
expect(getCharacterWidth(" ")).toBe(1);
expect(() => getCharacterWidth("")).toThrow();
expect(() => getCharacterWidth("ab")).toThrow();
});
it("getCharacterWidth CJK", () => {
expect(getCharacterWidth("你")).toBe(2);
expect(getCharacterWidth("好")).toBe(2);
expect(getCharacterWidth("吗")).toBe(2);
expect(getCharacterWidth("ガ")).toBe(2);
expect(getCharacterWidth("ギ")).toBe(2);
expect(getCharacterWidth("グ")).toBe(2);
expect(getCharacterWidth("ソ")).toBe(2);
expect(getCharacterWidth("")).toBe(2);
expect(getCharacterWidth("")).toBe(2);
expect(() => getCharacterWidth("你好")).toThrow();
expect(() => getCharacterWidth("ヨスガノ")).toThrow();
});
it("getCharacterWidth Emoji", () => {
expect(getCharacterWidth("👋")).toBe(2);
expect(getCharacterWidth("🌲️")).toBe(2);
expect(getCharacterWidth("👨‍👩‍👧‍👦")).toBe(2);
});
it("getCharacterWidth previously faulty cases", () => {
expect(getCharacterWidth("𤲶")).toBe(2);
});