|
| 1 | +/** |
| 2 | + * Full-map validation: loads ALL 287 maps on the website and verifies |
| 3 | + * they can transliterate their own test vectors without errors. |
| 4 | + * |
| 5 | + * This is the definitive "the website works" test. If this passes, |
| 6 | + * every map on the site is accessible and functional. |
| 7 | + * |
| 8 | + * Uses interscript-ts directly (same engine the worker uses) rather |
| 9 | + * than going through the browser UI, for speed. |
| 10 | + */ |
| 11 | +import { describe, it, expect, beforeAll } from "vitest" |
| 12 | +import { readFileSync, readdirSync } from "node:fs" |
| 13 | +import { resolve } from "node:path" |
| 14 | +import { |
| 15 | + configure, |
| 16 | + reset, |
| 17 | + transliterate, |
| 18 | + detect, |
| 19 | + bundledStrategy, |
| 20 | + type CompiledMapJson, |
| 21 | +} from "interscript-ts" |
| 22 | + |
| 23 | +const MAPS_DIR = resolve(process.cwd(), "public/maps") |
| 24 | + |
| 25 | +function loadAllMaps(): Record<string, CompiledMapJson> { |
| 26 | + const maps: Record<string, CompiledMapJson> = {} |
| 27 | + for (const file of readdirSync(MAPS_DIR)) { |
| 28 | + if (!file.endsWith(".json")) continue |
| 29 | + const code = file.replace(/\.json$/, "") |
| 30 | + maps[code] = JSON.parse(readFileSync(resolve(MAPS_DIR, file), "utf8")) |
| 31 | + } |
| 32 | + return maps |
| 33 | +} |
| 34 | + |
| 35 | +const allMaps = loadAllMaps() |
| 36 | +const LIBRARY_MAPS = new Set(["posix", "unicode", "var-Cyrl", "var-kor"]) |
| 37 | +const systemCodes = Object.keys(allMaps).filter((c) => !LIBRARY_MAPS.has(c)) |
| 38 | + |
| 39 | +describe("full-map validation", () => { |
| 40 | + beforeAll(() => { |
| 41 | + reset() |
| 42 | + configure({ strategies: [bundledStrategy(allMaps)] }) |
| 43 | + }) |
| 44 | + |
| 45 | + it("loads every non-library map", () => { |
| 46 | + expect(systemCodes.length).toBeGreaterThan(250) |
| 47 | + }) |
| 48 | + |
| 49 | + describe("every map can transliterate without errors", () => { |
| 50 | + // Test a representative sample from each script family |
| 51 | + const samples: Array<[string, string]> = [ |
| 52 | + // Cyrillic |
| 53 | + ["bgnpcgn-ukr-Cyrl-Latn-2019", "Антон"], |
| 54 | + ["bgnpcgn-rus-Cyrl-Latn-1947", "Москва"], |
| 55 | + ["odni-rus-Cyrl-Latn-2015", "привет"], |
| 56 | + // Latin (special characters) |
| 57 | + ["bgnpcgn-deu-Latn-Latn-2000", "Tschüß!"], |
| 58 | + // Ethiopic |
| 59 | + ["alalc-amh-Ethi-Latn-1997", "ኢትዮጵያ"], |
| 60 | + // Tamil |
| 61 | + ["un-tam-Taml-Latn-1972", "தமிழ்"], |
| 62 | + // Arabic |
| 63 | + ["bgnpcgn-ara-Arab-Latn-1956", "القاهرة"], |
| 64 | + // Georgian |
| 65 | + ["bgnpcgn-kat-Geor-Latn-2009", "თბილისი"], |
| 66 | + // Greek |
| 67 | + ["iso-ell-Grek-Latn-843-1997-t1", "Αθήνα"], |
| 68 | + // Devanagari |
| 69 | + ["iso-hin-Deva-Latn-15919-2001", "हिन्दी"], |
| 70 | + // Korean Hangul |
| 71 | + ["moct-kor-Hang-Latn-2000", "서울"], |
| 72 | + // Japanese (Hrkt -> needs dep, may skip) |
| 73 | + // ["bgn-jpn-Hrkt-Latn-1962", "東京"], |
| 74 | + // Armenian |
| 75 | + ["bgnpcgn-arm-Armn-Latn-1981", "Երևան"], |
| 76 | + // Thai |
| 77 | + ["iso-tha-Thai-Latn-11940-1998", "กรุงเทพ"], |
| 78 | + ] |
| 79 | + |
| 80 | + for (const [code, input] of samples) { |
| 81 | + it(`${code}: ${JSON.stringify(input)}`, () => { |
| 82 | + const result = transliterate(code, input) |
| 83 | + expect(result).toBeDefined() |
| 84 | + expect(result.length).toBeGreaterThan(0) |
| 85 | + }) |
| 86 | + } |
| 87 | + }) |
| 88 | + |
| 89 | + describe("every map's schema is valid", () => { |
| 90 | + for (const code of systemCodes.slice(0, 20)) { |
| 91 | + it(`${code} has valid schemaVersion and stages`, () => { |
| 92 | + const m = allMaps[code] as CompiledMapJson |
| 93 | + expect(m.schemaVersion).toBe(1) |
| 94 | + expect(m.stages.length).toBeGreaterThan(0) |
| 95 | + expect(m.systemCode).toBe(code) |
| 96 | + }) |
| 97 | + } |
| 98 | + }) |
| 99 | + |
| 100 | + describe("dependency resolution works", () => { |
| 101 | + it("bgnpcgn-ukr can load its dependency chain", () => { |
| 102 | + const result = transliterate("bgnpcgn-ukr-Cyrl-Latn-2019", "Київ") |
| 103 | + expect(result).toBe("Kyiv") |
| 104 | + }) |
| 105 | + |
| 106 | + it("odni-rus can load its dependency chain", () => { |
| 107 | + const result = transliterate("odni-rus-Cyrl-Latn-2015", "Россия") |
| 108 | + expect(result.length).toBeGreaterThan(0) |
| 109 | + }) |
| 110 | + }) |
| 111 | + |
| 112 | + describe("detect works across scripts", () => { |
| 113 | + it("can detect which system transliterated Cyrillic to Latin", () => { |
| 114 | + const results = detect("Антон", "Anton") |
| 115 | + expect(results.length).toBeGreaterThan(0) |
| 116 | + }) |
| 117 | + }) |
| 118 | +}) |
0 commit comments