// typeddate.test.mjs — the date picker's typed dates answer what ⌘K's // do: every case in internal/mapa/testdata/typed_dates.json, which Go's // TestTypedDatesMatchTheSharedCases reads too (build note 83). import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { typedDate } from './typeddate.mjs' import { order } from './dates.mjs' const here = dirname(fileURLToPath(import.meta.url)) const shared = JSON.parse(readFileSync( join(here, '..', 'internal', 'mapa', 'testdata', 'typed_dates.json'), 'utf8')) const dates = JSON.parse(readFileSync( join(here, '..', 'internal', 'mapa', 'locale', 'dates.json'), 'utf8')) // A case naming a locale is read in its order; one naming none, in // every offered locale's (build note 85). test('the port answers every shared case as typeddate.go does', () => { assert.ok(shared.cases.length >= 100, `only ${shared.cases.length} cases`) const wrong = [] for (const { today, query, want, locale, strict } of shared.cases) { for (const code of locale ? [locale] : dates.offered) { const reading = dates.locales[code] const got = typedDate(query, today, order(reading), strict ? reading.separator : '') if (got !== want) wrong.push({ code, today, query, want, got }) } } assert.deepEqual(wrong, []) }) test('numbers follow the locale: 12/11 is November in en-IE, December in en-US', () => { assert.equal(typedDate('12/11', '2026-11-14', order(dates.locales['en-IE'])), '2026-11-12') assert.equal(typedDate('12/11', '2026-11-14', order(dates.locales['en-US'])), '2026-12-11') assert.equal(typedDate('12.11.', '2026-11-14', order(dates.locales.de)), '2026-11-12') })