-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLDR-16836 kbd: ebnf: move tests to js out of shell, check XML files #4270
Open
srl295
wants to merge
3
commits into
unicode-org:main
Choose a base branch
from
srl295:srl295/kbd/cldr-18197/bnf-jstest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Keyboard-abnf-tests | ||
|
||
Tests for and against the ABNF files, written in Node.js | ||
|
||
## To use | ||
|
||
- `npm ci` | ||
- `npm t` | ||
|
||
## To update | ||
|
||
Note there are four files. There's a `.d` directory for each ABNF file in keyboards/abnf/. The "pass" files are expected to pass the ABNF and the "fail" to fail it. Lines beginning with # are comments and skipped. | ||
|
||
- transform-from-required.d/from-match.pass.txt | ||
- transform-from-required.d/from-match.fail.txt | ||
- transform-to-required.d/to-replacement.pass.txt | ||
- transform-to-required.d/to-replacement.fail.txt | ||
|
||
## Copyright | ||
|
||
Copyright © 1991-2025 Unicode, Inc. | ||
All rights reserved. | ||
[Terms of use](https://www.unicode.org/copyright.html) |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@unicode-org/keyboard-abnf-tests", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node --test" | ||
}, | ||
"keywords": [], | ||
"author": "Steven R. Loomis <[email protected]>", | ||
"license": "Unicode-3.0", | ||
"description": "Tests for the keyboard ABNF", | ||
"private": true, | ||
"dependencies": { | ||
"abnf": "^4.3.1", | ||
"peggy": "^4.2.0" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tools/scripts/keyboard-abnf-tests/test/abnf-valid.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2025 Unicode, Inc. | ||
// For terms of use, see http://www.unicode.org/copyright.html | ||
// SPDX-License-Identifier: Unicode-3.0 | ||
|
||
import * as abnf from "abnf"; | ||
import { test } from "node:test"; | ||
import * as assert from "node:assert"; | ||
import { forEachAbnf } from "./util.mjs"; | ||
|
||
function check_refs(parsed) { | ||
const errs = abnf.checkRefs(parsed); | ||
if (!errs) return 0; | ||
for (const err of errs) { | ||
console.error(err); | ||
} | ||
return 3; | ||
} | ||
|
||
await forEachAbnf(async ({ abnfFile, abnfText, abnfPath }) => { | ||
await test(`Test validity: ${abnfFile}`, async (t) => { | ||
const parsed = await abnf.parseFile(abnfPath); | ||
assert.equal(check_refs(parsed), 0); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
tools/scripts/keyboard-abnf-tests/test/datadriven.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2025 Unicode, Inc. | ||
// For terms of use, see http://www.unicode.org/copyright.html | ||
// SPDX-License-Identifier: Unicode-3.0 | ||
|
||
import * as abnf from "abnf"; | ||
import { existsSync, readFileSync, readdirSync } from "node:fs"; | ||
import { test } from "node:test"; | ||
import { basename, join } from "node:path"; | ||
import * as assert from "node:assert"; | ||
import { forEachAbnf } from "./util.mjs"; | ||
import peggy from "peggy"; | ||
|
||
async function assertTest({ t, abnfPath, testText, expect }) { | ||
const parsed = await abnf.parseFile(abnfPath); | ||
const opts = { | ||
grammarSource: abnfPath, | ||
trace: false, | ||
}; | ||
const text = parsed.toFormat({ format: "peggy" }); | ||
const parser = peggy.generate(text, opts); | ||
for (const str of testText | ||
.trim() | ||
.split("\n") | ||
.filter((l) => !/^#/.test(l))) { | ||
await t.test(`"${str}"`, async (t) => { | ||
const fn = () => parser.parse(str, opts); | ||
if (!expect) { | ||
assert.throws(fn, `Expected this expression to fail parsing`); | ||
} else { | ||
const results = fn(); | ||
assert.ok(results); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
await forEachAbnf(async ({ abnfFile, abnfText, abnfPath }) => { | ||
await test(`Test Data: ${abnfFile}`, async (t) => { | ||
const stub = basename(abnfFile, ".abnf"); | ||
const testDir = `./${stub}.d`; | ||
assert.ok(existsSync(testDir), `No test dir: ${testDir}`); | ||
const tests = readdirSync(testDir)?.filter((f) => | ||
/^.*\.(pass|fail)\.txt/.test(f) | ||
); | ||
assert.ok(tests && tests.length, `No tests in ${testDir}`); | ||
for (const testFile of tests) { | ||
if (testFile.endsWith(".pass.txt")) { | ||
await t.test(`${stub}/${testFile}`, async (t) => { | ||
await assertTest({ | ||
t, | ||
abnfPath, | ||
testText: readFileSync(join(testDir, testFile), "utf-8"), | ||
expect: true, | ||
}); | ||
}); | ||
} else if (testFile.endsWith(".fail.txt")) { | ||
await t.test(`${stub}/${testFile}`, async (t) => { | ||
await assertTest({ | ||
t, | ||
abnfPath, | ||
testText: readFileSync(join(testDir, testFile), "utf-8"), | ||
expect: false, | ||
}); | ||
}); | ||
} else throw Error(`Unknown testFile ${testFile}`); | ||
} | ||
// const parsed = await abnf.parseFile(abnfPath); | ||
// assert.equal(check_refs(parsed), 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2025 Unicode, Inc. | ||
// For terms of use, see http://www.unicode.org/copyright.html | ||
// SPDX-License-Identifier: Unicode-3.0 | ||
|
||
import { readFileSync, readdirSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
export const ABNF_DIR = "../../../keyboards/abnf"; | ||
|
||
/** | ||
* | ||
* @param {function} callback given abnfFile, abnfPath, abnfText | ||
*/ | ||
export async function forEachAbnf(callback) { | ||
return await Promise.all( | ||
readdirSync(ABNF_DIR).map((abnfFile) => { | ||
if (!/^.*\.abnf$/.test(abnfFile)) return; | ||
const abnfPath = join(ABNF_DIR, abnfFile); | ||
const abnfText = readFileSync(abnfPath); | ||
return callback({ abnfFile, abnfPath, abnfText }); | ||
}) | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are these files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are in that same directory (keyboard-abnf-tests) and were added in #4261
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that previous PR had a shell script (now deleted) to test the files, this changes it to JS