Skip to content

Commit

Permalink
Merge pull request #12506 from keymanapp/feat/developer/12012-improve…
Browse files Browse the repository at this point in the history
…-support-for-bcp47

chore(developer): add baseline tests for bcp47 codes to kmc-package
  • Loading branch information
mcdurdin authored Dec 6, 2024
2 parents 7be5c62 + ee46a66 commit a78f03a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions developer/src/kmc-package/test/fixtures/bcp47/invalid_bcp47_1.kps
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Package>
<System>
<KeymanDeveloperVersion>10.0.700.0</KeymanDeveloperVersion>
<FileVersion>7.0</FileVersion>
</System>
<Info>
<Version>1.0</Version>
<Name>valid_bcp47</Name>
</Info>
<Files>
<File>
<Name>test.kmx</Name>
</File>
</Files>
<Keyboards>
<Keyboard>
<Name>Invalid BCP 47</Name>
<ID>test</ID>
<Version>1.0</Version>
<Languages>
<Language ID="km-mm-mm">Not a language tag</Language>
</Languages>
</Keyboard>
</Keyboards>
<Strings/>
</Package>
Binary file not shown.
39 changes: 39 additions & 0 deletions developer/src/kmc-package/test/fixtures/bcp47/valid_bcp47.kps
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Package>
<System>
<KeymanDeveloperVersion>10.0.700.0</KeymanDeveloperVersion>
<FileVersion>7.0</FileVersion>
</System>
<Options>
<ExecuteProgram></ExecuteProgram>
<MSIFileName></MSIFileName>
<MSIOptions></MSIOptions>
</Options>
<StartMenu>
<Folder></Folder>
<Items/>
</StartMenu>
<Info>
<Version URL="">1.0</Version>
<Name URL="">valid_bcp47</Name>
</Info>
<Files>
<File>
<Name>test.kmx</Name>
</File>
</Files>
<Keyboards>
<Keyboard>
<Name>Valid BCP 47</Name>
<ID>test</ID>
<Version>1.0</Version>
<Languages>
<Language ID="km">Central Khmer (Khmer, Cambodia)</Language>
<Language ID="str-x-sencoten">SENCOTEN</Language>
<Language ID="str-sencoten">Unregistered variant of Straits Salish</Language>
<Language ID="km-Khmr-KM-x-boran">Private variant of "Old" Khmer</Language>
</Languages>
</Keyboard>
</Keyboards>
<Strings/>
</Package>
24 changes: 24 additions & 0 deletions developer/src/kmc-package/test/package-compiler.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { makePathToFixture } from './helpers/index.js';

import { KmpCompiler } from '../src/compiler/kmp-compiler.js';
import { PackageCompilerMessages } from '../src/compiler/package-compiler-messages.js';
import { PackageValidation } from '../src/compiler/package-validation.js';

const debug = false;

Expand All @@ -29,6 +30,13 @@ describe('KmpCompiler', function () {
assert.isTrue(await kmpCompiler.init(callbacks, null));
});

this.afterEach(function() {
if(this.currentTest?.isFailed()) {
callbacks.printMessages();
}
callbacks.clear();
});

for (let modelID of MODELS) {
const kpsPath = modelID.includes('withfolders') ?
makePathToFixture(modelID, 'source', `${modelID}.model.kps`) : makePathToFixture(modelID, `${modelID}.model.kps`);
Expand Down Expand Up @@ -284,4 +292,20 @@ describe('KmpCompiler', function () {
assert.equal(kmpJson.keyboards[0].version, '4.0'); // picks up example.kmx's version
});

it(`should handle a range of valid BCP47 tags`, function () {
const inputFilename = makePathToFixture('bcp47', 'valid_bcp47.kps');
const kmpJson = kmpCompiler.transformKpsToKmpObject(inputFilename);
assert.isNotNull(kmpJson);
const validation = new PackageValidation(callbacks, {});
assert.isTrue(validation.validate(inputFilename, kmpJson));
});

it(`should reject an invalid BCP47 tag`, function () {
const inputFilename = makePathToFixture('bcp47', 'invalid_bcp47_1.kps');
const kmpJson = kmpCompiler.transformKpsToKmpObject(inputFilename);
assert.isNotNull(kmpJson);
const validation = new PackageValidation(callbacks, {});
assert.isFalse(validation.validate(inputFilename, kmpJson));
});

});

0 comments on commit a78f03a

Please sign in to comment.