Skip to content

Commit

Permalink
CLDR-18318 test: update kbd abnf test
Browse files Browse the repository at this point in the history
- work on windows and improve output
  • Loading branch information
srl295 committed Feb 19, 2025
1 parent 6a5e512 commit 0c12ecd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0c12ecd

Please sign in to comment.