Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/locales.test.mjs
blob: e02cd32d4eab759662670799bf1bda1c518164bf (plain)
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
// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
// SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1

import assert from "node:assert/strict";
import test from "node:test";

import {
  localeOfPrefix,
  localePath,
  locales,
  pageOfPath,
  textDirection,
} from "../app/content/locales.ts";

test("English has no prefix and the other languages have one", () => {
  assert.equal(localePath("en-US", "/"), "/");
  assert.equal(localePath("en-US", "/docs/reference/commands"), "/docs/reference/commands");
  assert.equal(localePath("de-DE", "/"), "/de");
  assert.equal(localePath("he-IL", "/docs/reference/commands"), "/he/docs/reference/commands");
});

test("a path names its page in every language", () => {
  for (const locale of locales) {
    for (const page of ["/", "/docs/getting-started/installation"]) {
      assert.equal(pageOfPath(localePath(locale, page)), page);
    }
  }
  assert.equal(pageOfPath("/ru/docs/reference/lockfile/"), "/docs/reference/lockfile");
  // A path that only starts like a prefix is an English page.
  assert.equal(pageOfPath("/design"), "/design");
});

test("a segment that is no prefix names no language", () => {
  assert.equal(localeOfPrefix(undefined), "en-US");
  assert.equal(localeOfPrefix(""), "en-US");
  assert.equal(localeOfPrefix("ru"), "ru-RU");
  assert.equal(localeOfPrefix("docs"), undefined);
  assert.equal(localeOfPrefix("en"), undefined);
});

test("only Hebrew runs from right to left", () => {
  assert.deepEqual(locales.map(textDirection), ["ltr", "ltr", "ltr", "rtl"]);
});