chat / client / test / i18n.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Catalog completeness and a byte snapshot — the CLJS replacement for the
// TS-era MsgKey type check, plus the transliteration gate: every Romanian and
// Hungarian string was moved by a throwaway line-by-line transliterator, and
// this test passing first try is the signal that not one character changed.
import test from "node:test";
import assert from "node:assert/strict";
import { installDom } from "./harness/dom.mjs";
import { mods, readVector } from "./helpers/load.mjs";

installDom();
const M = await mods();
const v = readVector("i18n");

test("EN is the key set of record, and ro/hu cover it exactly", () => {
  assert.deepEqual(M.catalogKeys("en"), v.keys.en);
  assert.ok(v.keys.en.length >= 100);
  for (const lang of ["ro", "hu"]) {
    assert.deepEqual(M.catalogKeys(lang), v.keys.en, `${lang} key set`);
    assert.deepEqual(M.catalogKeys(lang), v.keys[lang]);
  }
});

test("every catalog string is byte-identical to the TypeScript catalogs", () => {
  for (const lang of ["en", "ro", "hu"]) {
    for (const k of v.keys[lang]) {
      assert.deepEqual(M.catalogRaw(lang, k), v.snapshot[lang][k], `${lang} ${k}`);
    }
  }
});

test("plural sites keep their per-language variant sets", () => {
  assert.ok(Object.keys(v.plurals).length > 0);
  for (const [k, shapes] of Object.entries(v.plurals)) {
    for (const lang of ["en", "ro", "hu"]) {
      assert.deepEqual(M.catalogMsg(lang, k), shapes[lang], `${lang} ${k}`);
    }
  }
});

test("no catalog value carries a wire literal", () => {
  for (const lang of ["en", "ro", "hu"]) {
    for (const k of v.keys[lang]) {
      const m = M.catalogRaw(lang, k);
      if (typeof m !== "string") continue;
      assert.ok(!m.includes("/sueta/2/"), `${lang} ${k} contains a protocol prefix`);
      assert.ok(!m.includes("sueta-id|v2"), `${lang} ${k} contains a domain tag`);
    }
  }
});

test("the runtime interpolates and falls back to the key", () => {
  assert.equal(M.t("peers.here", { n: 3 }), v.snapshot.en["peers.here"].replace("{n}", "3"));
  assert.equal(M.t("no.such.key.at.all"), "no.such.key.at.all");
  const replies = v.snapshot.en["msg.replies"];
  assert.equal(M.tn("msg.replies", 1), replies.one.replace("{n}", "1"));
  assert.equal(M.tn("msg.replies", 5), replies.other.replace("{n}", "5"));
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/chat.git