Skip to content

Commit

Permalink
feat(developer): test local imports in kmc-ldml
Browse files Browse the repository at this point in the history
- also improve callback visibility when XML fails to load

Fixes: #10649
  • Loading branch information
srl295 committed Nov 29, 2024
1 parent e99f6ac commit 01fed4b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<keyboard3 xmlns="https://schemas.unicode.org/cldr/45/keyboard3" locale="mt" conformsTo="45">
<info name="keys-minimal"/>

<keys>
<import base="" path="keys-Zyyy-morepunctuation.xml"/>
</keys>

<layers formId="us">
<layer id="base">
<row keys="snail interrobang" />
</layer>
</layers>

</keyboard3>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<keys>
<!-- Special Symbols -->
<key id="interrobang" output="" />
<key id="snail" output="@" />
</keys>
9 changes: 8 additions & 1 deletion developer/src/kmc-ldml/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const compilerTestCallbacks = new TestCompilerCallbacks();

export const compilerTestOptions: LdmlCompilerOptions = {
readerOptions: {
importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL))
importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)),
localImportsPaths: [], // will be fixed up in loadSectionFixture
}
};

Expand All @@ -59,8 +60,14 @@ export async function loadSectionFixture(compilerClass: SectionCompilerNew, file
const data = callbacks.loadFile(inputFilename);
assert.isNotNull(data, `Failed to read file ${inputFilename}`);

compilerTestOptions.readerOptions.localImportsPaths = [ path.dirname(inputFilename) + path.sep ];

const reader = new LDMLKeyboardXMLSourceFileReader(compilerTestOptions.readerOptions, callbacks);
const source = reader.load(data);
if (!source) {
// print any callbacks here
assert.sameDeepMembers(callbacks.messages, [], `Errors loading ${inputFilename}`);
}
assert.isNotNull(source, `Failed to load XML from ${inputFilename}`);

if (!reader.validate(source)) {
Expand Down
13 changes: 13 additions & 0 deletions developer/src/kmc-ldml/test/keys.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ describe('keys', function () {
assert.equal(flickw.flicks[0].keyId.value, 'dd');
},
},
{
subpath: 'sections/keys/import-local.xml',
callback: (keys, subpath, callbacks) => {
assert.isNotNull(keys);
assert.equal((<Keys>keys).keys.length, 2 + KeysCompiler.reserved_count);
const [snail] = (<Keys>keys).keys.filter(({ id }) => id.value === 'snail');
assert.ok(snail,`Missing the snail`);
assert.equal(snail.to.value, `@`, `Snail's value`);
const [interrobang] = (<Keys>keys).keys.filter(({ id }) => id.value === 'interrobang');
assert.ok(interrobang,`Missing the interrobang`);
assert.equal(interrobang.to.value, `‽`, `Interrobang's value`);
},
},
], keysDependencies);
});

Expand Down

0 comments on commit 01fed4b

Please sign in to comment.