import { describe, it, expect } from "vitest"; import { detectName } from "./name.js"; describe("Korean name detection", () => { it("detects common Korean names", () => { expect(detectName("김철수 님")).toHaveLength(1); expect(detectName("이영희 입니다")).toHaveLength(1); expect(detectName("박민수")).toHaveLength(1); }); it("detects names with various top surnames", () => { expect(detectName("최지원")).toHaveLength(1); expect(detectName("정하나")).toHaveLength(1); expect(detectName("강민호")).toHaveLength(1); }); it("detects 2-char names (surname + 1 char)", () => { expect(detectName("김솔")).toHaveLength(1); expect(detectName("이준")).toHaveLength(1); }); it("rejects single character (surname only)", () => { // "김" alone is just a surname, not a full name expect(detectName("김 입니다")).toHaveLength(0); }); it("detects multiple names in text", () => { const r = detectName("김철수와 이영희가 만났다"); expect(r).toHaveLength(2); }); it("has lower confidence than other PII types", () => { const r = detectName("김철수"); if (r.length > 0) { expect(r[0].confidence).toBeLessThan(0.8); } }); it("returns empty for non-Korean text", () => { expect(detectName("John Smith")).toHaveLength(0); expect(detectName("hello world")).toHaveLength(0); }); it("excludes common Korean words that start with surname chars", () => { // These words start with top surnames but are not names expect(detectName("오늘")).toHaveLength(0); expect(detectName("전화")).toHaveLength(0); expect(detectName("서버")).toHaveLength(0); expect(detectName("주소")).toHaveLength(0); expect(detectName("한국")).toHaveLength(0); expect(detectName("고객")).toHaveLength(0); expect(detectName("최근")).toHaveLength(0); expect(detectName("문제")).toHaveLength(0); expect(detectName("안내")).toHaveLength(0); expect(detectName("신청")).toHaveLength(0); }); it("still detects real names despite exclusion list", () => { // These are valid names, not in the exclusion list expect(detectName("오세진")).toHaveLength(1); expect(detectName("전지현")).toHaveLength(1); expect(detectName("서연우")).toHaveLength(1); }); });