oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1// typeddate.test.mjs — the date picker's typed dates answer what ⌘K's
2// do: every case in internal/mapa/testdata/typed_dates.json, which Go's
3// TestTypedDatesMatchTheSharedCases reads too (build note 83).
4
5import { test } from 'node:test'
6import assert from 'node:assert/strict'
7import { readFileSync } from 'node:fs'
8import { dirname, join } from 'node:path'
9import { fileURLToPath } from 'node:url'
10import { typedDate } from './typeddate.mjs'
11import { order } from './dates.mjs'
12
13const here = dirname(fileURLToPath(import.meta.url))
14const shared = JSON.parse(readFileSync(
15 join(here, '..', 'internal', 'mapa', 'testdata', 'typed_dates.json'), 'utf8'))
16const dates = JSON.parse(readFileSync(
17 join(here, '..', 'internal', 'mapa', 'locale', 'dates.json'), 'utf8'))
18
19// A case naming a locale is read in its order; one naming none, in
20// every offered locale's (build note 85).
21test('the port answers every shared case as typeddate.go does', () => {
22 assert.ok(shared.cases.length >= 100, `only ${shared.cases.length} cases`)
23 const wrong = []
24 for (const { today, query, want, locale, strict } of shared.cases) {
25 for (const code of locale ? [locale] : dates.offered) {
26 const reading = dates.locales[code]
27 const got = typedDate(query, today, order(reading), strict ? reading.separator : '')
28 if (got !== want) wrong.push({ code, today, query, want, got })
29 }
30 }
31 assert.deepEqual(wrong, [])
32})
33
34test('numbers follow the locale: 12/11 is November in en-IE, December in en-US', () => {
35 assert.equal(typedDate('12/11', '2026-11-14', order(dates.locales['en-IE'])), '2026-11-12')
36 assert.equal(typedDate('12/11', '2026-11-14', order(dates.locales['en-US'])), '2026-12-11')
37 assert.equal(typedDate('12.11.', '2026-11-14', order(dates.locales.de)), '2026-11-12')
38})
39