From 0c12ecde7a4a45926f7ebf14e15ea3cac69580c5 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 19 Feb 2025 13:41:50 -0600 Subject: [PATCH] CLDR-18318 test: update kbd abnf test - work on windows and improve output --- .../keyboard-abnf-tests/test/datadriven.test.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs b/tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs index b655e80caff..4b0bcdefbe3 100644 --- a/tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs +++ b/tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs @@ -9,13 +9,24 @@ import * as assert from "node:assert"; import { forEachAbnf } from "../lib/util.mjs"; import { getParseFunction } from "../lib/index.mjs"; +function sanitize(str) { + return str.replace(/[\s]+/g, (s) => + [...s].map((s) => { + if (s === '\n') return '\\n'; + if (s === '\r') return '\\r'; + if (s === ' ') return ' '; + return `\\u{${s.codePointAt(0).toString(16)}}`; + })); +} + async function assertTest({ t, abnfPath, testText, expect }) { const parser = await getParseFunction(abnfPath); for (const str of testText + .replaceAll('\r\n', '\n') .trim() .split("\n") .filter((l) => !/^#/.test(l))) { - await t.test(`"${str}"`, async (t) => { + await t.test(`"${sanitize(str)}"`, async (t) => { if (!expect) { assert.throws( () => parser(str),