From 7a9b47b394f0c4d0229e871ff7478fd5ee78035b Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 14 Mar 2024 13:35:05 +0000 Subject: [PATCH 01/32] chore(developer): add preinit test for keyboard info compiler --- .../src/keyboard-info-compiler.ts | 3 +- .../test/test-keyboard-info-compiler.ts | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts index f374d20844..c26b5f6839 100644 --- a/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts @@ -16,7 +16,7 @@ import { getFontFamily } from "./font-family.js"; const regionNames = new Intl.DisplayNames(['en'], { type: "region" }); const scriptNames = new Intl.DisplayNames(['en'], { type: "script" }); -const langtagsByTag = {}; +export const langtagsByTag = {}; /** * Build a dictionary of language tags from langtags.json @@ -608,4 +608,3 @@ export class KeyboardInfoCompiler implements KeymanCompiler { } } - diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index ab47b39871..ead1dec6c6 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -3,7 +3,8 @@ import { assert } from 'chai'; import 'mocha'; import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; import { makePathToFixture } from './helpers/index.js'; -import { KeyboardInfoCompiler, KeyboardInfoCompilerResult } from '../src/keyboard-info-compiler.js'; +import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, langtagsByTag } from '../src/keyboard-info-compiler.js'; +import langtags from "../src/imports/langtags.js"; const callbacks = new TestCompilerCallbacks(); @@ -11,6 +12,26 @@ beforeEach(function() { callbacks.clear(); }); +const ENLANGTAG = { + "full": "en-Latn-US", + "iana": [ "English" ], + "iso639_3": "eng", + "localname": "American English", + "localnames": [ "English" ], + "name": "English", + "names": [ "Anglais", "Angleščina", "Anglisy", "Angličtina", "Anglų", "Angol", "Angļu", "Engels", "Engelsk", "Engelska", "Engelski", "Englaisa", "Englanti", "Englesch", "Engleză", "Englisch", "Ingilizce", "Inglese", "Ingliż", "Inglés", "Inglês", "Język angielski", "Kiingereza", "anglais" ], + "region": "US", + "regionname": "United States", + "regions": [ "AD", "AF", "AR", "AS", "AW", "BD", "BG", "BH", "BL", "BN", "BQ", "BT", "BY", "CL", "CN", "CO", "CR", "CW", "CY", "CZ", "DO", "EC", "EE", "ES", "ET", "FM", "FR", "GQ", "GR", "GW", "HN", "HR", "HU", "ID", "IS", "IT", "JP", "KH", "KR", "KW", "LB", "LK", "LT", "LU", "LV", "LY", "MC", "ME", "MF", "MX", "NO", "NP", "OM", "PA", "PL", "PM", "PR", "PT", "RO", "RS", "RU", "SA", "SK", "SO", "SR", "ST", "SV", "TC", "TH", "TN", "TW", "UA", "UM", "UY", "VE", "VG", "VI" ], + "script": "Latn", + "sldr": true, + "suppress": true, + "tag": "en", + "tags": [ "en-Latn", "en-US" ], + "variants": [ "basiceng", "boont", "cornu", "emodeng", "oxendict", "scotland", "scouse", "spanglis", "unifon" ], + "windows": "en-US" +}; + describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); @@ -50,4 +71,13 @@ describe('keyboard-info-compiler', function () { assert.deepEqual(actual, expected); }); + + it('check preinit creates langtagsByTag correctly', async function() { + const enLangTag = langtags.find(({ tag }) => tag === 'en'); + assert.deepEqual(enLangTag, ENLANGTAG); + assert.deepEqual((langtagsByTag)['en'], ENLANGTAG); + assert.deepEqual((langtagsByTag)['en-Latn-US'], ENLANGTAG); + assert.deepEqual((langtagsByTag)['en-Latn'], ENLANGTAG); + assert.deepEqual((langtagsByTag)['en-US'], ENLANGTAG); + }); }); From c1b7f0053d762a3b5cd8e0e3c710992290994224 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 14 Mar 2024 13:50:00 +0000 Subject: [PATCH 02/32] chore(developer): use unitTestEndpoints to export langtagsByTag --- .../kmc-keyboard-info/src/keyboard-info-compiler.ts | 9 ++++++++- .../test/test-keyboard-info-compiler.ts | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts index c26b5f6839..aa0f84666a 100644 --- a/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts @@ -16,7 +16,7 @@ import { getFontFamily } from "./font-family.js"; const regionNames = new Intl.DisplayNames(['en'], { type: "region" }); const scriptNames = new Intl.DisplayNames(['en'], { type: "script" }); -export const langtagsByTag = {}; +const langtagsByTag = {}; /** * Build a dictionary of language tags from langtags.json @@ -608,3 +608,10 @@ export class KeyboardInfoCompiler implements KeymanCompiler { } } + +/** + * these are exported only for unit tests, do not use + */ +export const unitTestEndpoints = { + langtagsByTag, +}; \ No newline at end of file diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index ead1dec6c6..4b2d1dee7a 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import 'mocha'; import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; import { makePathToFixture } from './helpers/index.js'; -import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, langtagsByTag } from '../src/keyboard-info-compiler.js'; +import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, unitTestEndpoints } from '../src/keyboard-info-compiler.js'; import langtags from "../src/imports/langtags.js"; const callbacks = new TestCompilerCallbacks(); @@ -75,9 +75,9 @@ describe('keyboard-info-compiler', function () { it('check preinit creates langtagsByTag correctly', async function() { const enLangTag = langtags.find(({ tag }) => tag === 'en'); assert.deepEqual(enLangTag, ENLANGTAG); - assert.deepEqual((langtagsByTag)['en'], ENLANGTAG); - assert.deepEqual((langtagsByTag)['en-Latn-US'], ENLANGTAG); - assert.deepEqual((langtagsByTag)['en-Latn'], ENLANGTAG); - assert.deepEqual((langtagsByTag)['en-US'], ENLANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], ENLANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], ENLANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], ENLANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], ENLANGTAG); }); }); From badc47dbd47bdc4d38523b3f0856b6c242eb5def Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 14 Mar 2024 13:58:13 +0000 Subject: [PATCH 03/32] chore(developer): ensure preinit is called indirectly (maintaining test independence) --- .../kmc-keyboard-info/test/test-keyboard-info-compiler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 4b2d1dee7a..0d461d8d40 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -73,8 +73,9 @@ describe('keyboard-info-compiler', function () { }); it('check preinit creates langtagsByTag correctly', async function() { - const enLangTag = langtags.find(({ tag }) => tag === 'en'); - assert.deepEqual(enLangTag, ENLANGTAG); + const compiler = new KeyboardInfoCompiler(); // indirectly call preinit() + assert.isNotNull(compiler); + assert.deepEqual(langtags.find(({ tag }) => tag === 'en'), ENLANGTAG); assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], ENLANGTAG); assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], ENLANGTAG); assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], ENLANGTAG); From ca084c1e00508036f695e5a24339cf2a07c43cc4 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 12:35:52 +0000 Subject: [PATCH 04/32] chore(developer): add KeyboardInfoCompiler init test --- .../test/test-keyboard-info-compiler.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 0d461d8d40..ea268c6b05 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -81,4 +81,23 @@ describe('keyboard-info-compiler', function () { assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], ENLANGTAG); assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], ENLANGTAG); }); + + it('check init initialises KeyboardInfoCompiler correctly', async function() { + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + assert.deepEqual(compiler['callbacks'], callbacks); + assert.deepEqual(compiler['options'], {sources}); + }); }); From daa6384da5487243cad07e98ed21a1151c5920dd Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 15:48:21 +0000 Subject: [PATCH 05/32] chore(developer): add KeyboardInfoCompiler returns null if KmpCompiler.init fails test --- .../test/test-keyboard-info-compiler.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index ea268c6b05..203775884f 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -5,6 +5,8 @@ import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; import { makePathToFixture } from './helpers/index.js'; import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, unitTestEndpoints } from '../src/keyboard-info-compiler.js'; import langtags from "../src/imports/langtags.js"; +import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; +import { CompilerCallbacks } from '@keymanapp/common-types'; const callbacks = new TestCompilerCallbacks(); @@ -100,4 +102,27 @@ describe('keyboard-info-compiler', function () { assert.deepEqual(compiler['callbacks'], callbacks); assert.deepEqual(compiler['options'], {sources}); }); + + it('check run returns null if KmpCompiler.init fails', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const origKmpCompilerInit = KmpCompiler.prototype.init; + KmpCompiler.prototype.init = (callbacks: CompilerCallbacks, options: KmpCompilerOptions) => { return null; } + const result = await compiler.run(kpjFilename, null); + KmpCompiler.prototype.init = origKmpCompilerInit; + assert.isNull(result); + }); }); From 79cd02169c4f8b1c8ec1915315b3ef4dfd4bde3e Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 16:05:38 +0000 Subject: [PATCH 06/32] chore(developer): add KeyboardInfoCompiler returns null if KmpCompiler.transformKpsToKmpObject fails test --- .../test/test-keyboard-info-compiler.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 203775884f..3fdc6e1bd7 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -124,5 +124,28 @@ describe('keyboard-info-compiler', function () { const result = await compiler.run(kpjFilename, null); KmpCompiler.prototype.init = origKmpCompilerInit; assert.isNull(result); - }); + }); + + it('check run returns null if KmpCompiler.transformKpsToKmpObject fails', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const origKmpCompilerTransformKpsToKmpObject = KmpCompiler.prototype.transformKpsToKmpObject; + KmpCompiler.prototype.transformKpsToKmpObject = (kpsFilename: string) => { return null; } + const result = await compiler.run(kpjFilename, null); + KmpCompiler.prototype.transformKpsToKmpObject = origKmpCompilerTransformKpsToKmpObject; + assert.isNull(result); + }); }); From 8a43aa56eff19b60c86de79673a6263934c2c134 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 16:14:01 +0000 Subject: [PATCH 07/32] chore(developer): add KeyboardInfoCompiler returns null if loadJsFile fails test --- .../test/test-keyboard-info-compiler.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 3fdc6e1bd7..22839dc3fc 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -147,5 +147,26 @@ describe('keyboard-info-compiler', function () { const result = await compiler.run(kpjFilename, null); KmpCompiler.prototype.transformKpsToKmpObject = origKmpCompilerTransformKpsToKmpObject; assert.isNull(result); + }); + + it('check run returns null if loadJsFile fails', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['loadJsFile'] = (filename: string): string => { return null; } + const result = await compiler.run(kpjFilename, null); + assert.isNull(result); }); }); From dbc1e42ded05b7d026b5221223f2f5c4626ca10c Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 16:20:52 +0000 Subject: [PATCH 08/32] chore(developer): add KeyboardInfoCompiler returns null if license is not MIT test --- .../test/test-keyboard-info-compiler.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 22839dc3fc..fa7249bdf2 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -169,4 +169,25 @@ describe('keyboard-info-compiler', function () { const result = await compiler.run(kpjFilename, null); assert.isNull(result); }); + + it('check run returns null if license is not MIT', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['isLicenseMIT'] = (filename: string): boolean => { return false; } + const result = await compiler.run(kpjFilename, null); + assert.isNull(result); + }); }); From e2088fd65fda6004bc2225af7ff4ee6782139544 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 16:29:14 +0000 Subject: [PATCH 09/32] chore(developer): add KeyboardInfoCompiler returns null if fillLanguages fails test --- .../test/test-keyboard-info-compiler.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index fa7249bdf2..eba1b4c909 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -6,7 +6,8 @@ import { makePathToFixture } from './helpers/index.js'; import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, unitTestEndpoints } from '../src/keyboard-info-compiler.js'; import langtags from "../src/imports/langtags.js"; import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; -import { CompilerCallbacks } from '@keymanapp/common-types'; +import { CompilerCallbacks, KmpJsonFile } from '@keymanapp/common-types'; +import { KeyboardInfoFile } from './keyboard-info-file.js'; const callbacks = new TestCompilerCallbacks(); @@ -189,5 +190,26 @@ describe('keyboard-info-compiler', function () { compiler['isLicenseMIT'] = (filename: string): boolean => { return false; } const result = await compiler.run(kpjFilename, null); assert.isNull(result); + }); + + it('check run returns null if fillLanguages fails', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['fillLanguages'] = (kpsFilename: string, keyboard_info: KeyboardInfoFile, kmpJsonData: KmpJsonFile.KmpJsonFile): Promise => { return null; } + const result = await compiler.run(kpjFilename, null); + assert.isNull(result); }); }); From 5c1733e718ec810216d2a9708c4e1d680842f30b Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 18 Mar 2024 16:40:28 +0000 Subject: [PATCH 10/32] chore(developer): tighten up stub definitions in tests --- .../test/test-keyboard-info-compiler.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index eba1b4c909..77ae40f4c6 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -121,7 +121,7 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerInit = KmpCompiler.prototype.init; - KmpCompiler.prototype.init = (callbacks: CompilerCallbacks, options: KmpCompilerOptions) => { return null; } + KmpCompiler.prototype.init = async (_callbacks: CompilerCallbacks, _options: KmpCompilerOptions): Promise => false; const result = await compiler.run(kpjFilename, null); KmpCompiler.prototype.init = origKmpCompilerInit; assert.isNull(result); @@ -144,7 +144,7 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerTransformKpsToKmpObject = KmpCompiler.prototype.transformKpsToKmpObject; - KmpCompiler.prototype.transformKpsToKmpObject = (kpsFilename: string) => { return null; } + KmpCompiler.prototype.transformKpsToKmpObject = (_kpsFilename: string): KmpJsonFile.KmpJsonFile => null; const result = await compiler.run(kpjFilename, null); KmpCompiler.prototype.transformKpsToKmpObject = origKmpCompilerTransformKpsToKmpObject; assert.isNull(result); @@ -166,7 +166,7 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); - compiler['loadJsFile'] = (filename: string): string => { return null; } + compiler['loadJsFile'] = (_filename: string): string => null; const result = await compiler.run(kpjFilename, null); assert.isNull(result); }); @@ -187,7 +187,7 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); - compiler['isLicenseMIT'] = (filename: string): boolean => { return false; } + compiler['isLicenseMIT'] = (_filename: string): boolean => false; const result = await compiler.run(kpjFilename, null); assert.isNull(result); }); @@ -208,7 +208,7 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); - compiler['fillLanguages'] = (kpsFilename: string, keyboard_info: KeyboardInfoFile, kmpJsonData: KmpJsonFile.KmpJsonFile): Promise => { return null; } + compiler['fillLanguages'] = async (_kpsFilename: string, _keyboard_info: KeyboardInfoFile, _kmpJsonData: KmpJsonFile.KmpJsonFile): Promise => false; const result = await compiler.run(kpjFilename, null); assert.isNull(result); }); From 5d4a56f6d013ea85c4dc8492d3c9aafcb302eabf Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 19 Mar 2024 11:11:00 +0000 Subject: [PATCH 11/32] chore(developer): add write artifacts to disk test --- developer/src/kmc-keyboard-info/.gitignore | 3 +- .../test/test-keyboard-info-compiler.ts | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/.gitignore b/developer/src/kmc-keyboard-info/.gitignore index fb2891a0a2..f118f231af 100644 --- a/developer/src/kmc-keyboard-info/.gitignore +++ b/developer/src/kmc-keyboard-info/.gitignore @@ -1 +1,2 @@ -src/imports/ \ No newline at end of file +src/imports/ +test/fixtures/khmer_angkor/build/actual.keyboard_info \ No newline at end of file diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 77ae40f4c6..8708acceb6 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -212,4 +212,43 @@ describe('keyboard-info-compiler', function () { const result = await compiler.run(kpjFilename, null); assert.isNull(result); }); + + it('should write artifacts to disk', async function() { + const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); + const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const actualFilename = makePathToFixture('khmer_angkor', 'build', 'actual.keyboard_info'); + const expectedFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.keyboard_info'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/khmer_angkor', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const result = await compiler.run(kpjFilename, null); + assert.isNotNull(result); + + if(fs.existsSync(actualFilename)) { + fs.rmSync(actualFilename); + } + + result.artifacts.keyboard_info.filename = actualFilename; + assert.isTrue(await compiler.write(result.artifacts)); + assert(fs.existsSync(actualFilename)) + + const actual = JSON.parse(fs.readFileSync(actualFilename, 'utf-8')); + const expected = JSON.parse(fs.readFileSync(expectedFilename, 'utf-8')); + + // `lastModifiedDate` is dependent on time of run (not worth mocking) + delete actual['lastModifiedDate']; + delete expected['lastModifiedDate']; + + assert.deepEqual(actual, expected); + }); }); From 0e2ff2bdfe602b8cfd216c228a7443b179ffa300 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 19 Mar 2024 11:51:57 +0000 Subject: [PATCH 12/32] chore(developer): add mapKeymanTargetToPlatform returns correct platforms test --- .../test/test-keyboard-info-compiler.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 8708acceb6..2fe129f9f9 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -6,8 +6,8 @@ import { makePathToFixture } from './helpers/index.js'; import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, unitTestEndpoints } from '../src/keyboard-info-compiler.js'; import langtags from "../src/imports/langtags.js"; import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; -import { CompilerCallbacks, KmpJsonFile } from '@keymanapp/common-types'; -import { KeyboardInfoFile } from './keyboard-info-file.js'; +import { CompilerCallbacks, KeymanTargets, KmpJsonFile } from '@keymanapp/common-types'; +import { KeyboardInfoFile, KeyboardInfoFilePlatform } from './keyboard-info-file.js'; const callbacks = new TestCompilerCallbacks(); @@ -251,4 +251,25 @@ describe('keyboard-info-compiler', function () { assert.deepEqual(actual, expected); }); + + it('check mapKeymanTargetToPlatform returns correct platforms', async function() { + const compiler = new KeyboardInfoCompiler(); + const map: {[index in KeymanTargets.KeymanTarget]: KeyboardInfoFilePlatform[]} = { + any: [], + androidphone: ['android'], + androidtablet: ['android'], + desktop: [], + ipad: ['ios'], + iphone: ['ios'], + linux: ['linux'], + macosx: ['macos'], + mobile: [], + tablet: [], + web: ['desktopWeb'], + windows: ['windows'] + } + for (const [target, platform] of Object.entries(map)) { + assert.deepEqual(compiler['mapKeymanTargetToPlatform'](target), platform); + } + }); }); From 628ac27d08070864b071de2e1cf1098dc6a75306 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 19 Mar 2024 12:25:49 +0000 Subject: [PATCH 13/32] chore(developer): add kmxFileVersionToString returns correct strings test --- .../test/test-keyboard-info-compiler.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 2fe129f9f9..27163fe7c7 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -272,4 +272,18 @@ describe('keyboard-info-compiler', function () { assert.deepEqual(compiler['mapKeymanTargetToPlatform'](target), platform); } }); + + it('check kmxFileVersionToString returns correct strings', async function() { + const compiler = new KeyboardInfoCompiler(); + const convs = [ + {num: 0x0000, str: '0.0'}, + {num: 0x0001, str: '0.1'}, + {num: 0x0100, str: '1.0'}, + {num: 0x0101, str: '1.1'}, + {num: 0x0A0A, str: '10.10'}, + ]; + convs.forEach((conv) => { + assert.equal(compiler['kmxFileVersionToString'](conv.num), conv.str); + }); + }); }); From 9c3e55e5119d9daa670d13f4184ae7e5c0774154 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Wed, 20 Mar 2024 11:45:59 +0000 Subject: [PATCH 14/32] chore(developer): add loadKmxFiles returns empty array if .kmx file is missing from .kmp test --- .../test/test-keyboard-info-compiler.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 27163fe7c7..7513a7c5cc 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -6,7 +6,7 @@ import { makePathToFixture } from './helpers/index.js'; import { KeyboardInfoCompiler, KeyboardInfoCompilerResult, unitTestEndpoints } from '../src/keyboard-info-compiler.js'; import langtags from "../src/imports/langtags.js"; import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; -import { CompilerCallbacks, KeymanTargets, KmpJsonFile } from '@keymanapp/common-types'; +import { CompilerCallbacks, KMX, KeymanFileTypes, KeymanTargets, KmpJsonFile } from '@keymanapp/common-types'; import { KeyboardInfoFile, KeyboardInfoFilePlatform } from './keyboard-info-file.js'; const callbacks = new TestCompilerCallbacks(); @@ -285,5 +285,20 @@ describe('keyboard-info-compiler', function () { convs.forEach((conv) => { assert.equal(compiler['kmxFileVersionToString'](conv.num), conv.str); }); - }); + }); + + it('check loadKmxFiles returns empty array if .kmx file is missing from .kmp', async function() { + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const compiler = new KeyboardInfoCompiler(); + const kmpCompiler = new KmpCompiler(); + assert.isTrue(await kmpCompiler.init(callbacks, {})); + const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); + assert.isNotNull(kmpJsonData); + kmpJsonData.files = kmpJsonData.files.filter(file => !KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); + const kmxFiles: { + filename: string, + data: KMX.KEYBOARD + }[] = compiler['loadKmxFiles'](kpsFilename, kmpJsonData); + assert.deepEqual(kmxFiles, []); + }); }); From 7353c3049aedc1ac495f90b4829c8ecd821acac7 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Wed, 20 Mar 2024 12:24:03 +0000 Subject: [PATCH 15/32] chore(developer): add loadKmxFiles throws error if .kmx file is missing from disk test --- .../test/test-keyboard-info-compiler.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 7513a7c5cc..31e353e6bf 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -294,11 +294,26 @@ describe('keyboard-info-compiler', function () { assert.isTrue(await kmpCompiler.init(callbacks, {})); const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); assert.isNotNull(kmpJsonData); + // remove .kps file kmpJsonData.files = kmpJsonData.files.filter(file => !KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); const kmxFiles: { filename: string, data: KMX.KEYBOARD }[] = compiler['loadKmxFiles'](kpsFilename, kmpJsonData); assert.deepEqual(kmxFiles, []); - }); + }); + + it('check loadKmxFiles throws error if .kmx file is missing from disk', async function() { + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const compiler = new KeyboardInfoCompiler(); + const kmpCompiler = new KmpCompiler(); + assert.isTrue(await kmpCompiler.init(callbacks, {})); + const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); + assert.isNotNull(kmpJsonData); + // rename .kmx file in files list so it cannot be loaded from disk + const kmpIndex = kmpJsonData.files.findIndex(file => KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); + kmpJsonData.files[kmpIndex].name = '../build/throw_error.kmx'; + assert.throws(() => compiler['loadKmxFiles'](kpsFilename, kmpJsonData)); + //assert.deepEqual(kmxFiles, []); + }); }); From 8abe3f65830c6dce94f17784f15cefd7869cd4cf Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Wed, 20 Mar 2024 12:24:03 +0000 Subject: [PATCH 16/32] chore(developer): add loadKmxFiles throws error if .kmx file is missing from disk test --- .../test/test-keyboard-info-compiler.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 7513a7c5cc..c7cf755513 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -294,11 +294,25 @@ describe('keyboard-info-compiler', function () { assert.isTrue(await kmpCompiler.init(callbacks, {})); const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); assert.isNotNull(kmpJsonData); + // remove .kps file kmpJsonData.files = kmpJsonData.files.filter(file => !KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); const kmxFiles: { filename: string, data: KMX.KEYBOARD }[] = compiler['loadKmxFiles'](kpsFilename, kmpJsonData); assert.deepEqual(kmxFiles, []); - }); + }); + + it('check loadKmxFiles throws error if .kmx file is missing from disk', async function() { + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const compiler = new KeyboardInfoCompiler(); + const kmpCompiler = new KmpCompiler(); + assert.isTrue(await kmpCompiler.init(callbacks, {})); + const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); + assert.isNotNull(kmpJsonData); + // rename .kmx file in files list so it cannot be loaded from disk + const kmpIndex = kmpJsonData.files.findIndex(file => KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); + kmpJsonData.files[kmpIndex].name = '../build/throw_error.kmx'; + assert.throws(() => compiler['loadKmxFiles'](kpsFilename, kmpJsonData)); + }); }); From 305e6f54dc13c698e946507f8554065a67a574ea Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Wed, 20 Mar 2024 12:37:59 +0000 Subject: [PATCH 17/32] chore(developer): recover from failed merge --- .../src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 6578b8d91c..c7cf755513 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -314,9 +314,5 @@ describe('keyboard-info-compiler', function () { const kmpIndex = kmpJsonData.files.findIndex(file => KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); kmpJsonData.files[kmpIndex].name = '../build/throw_error.kmx'; assert.throws(() => compiler['loadKmxFiles'](kpsFilename, kmpJsonData)); -<<<<<<< HEAD -======= - //assert.deepEqual(kmxFiles, []); ->>>>>>> 7353c3049aedc1ac495f90b4829c8ecd821acac7 }); }); From b542a8d133081c6dba464143ef28033df14f6bd7 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 25 Mar 2024 15:12:15 +0000 Subject: [PATCH 18/32] chore(developer): add loadKmxFiles can handle two .kmx files test --- .../build/k_001___basic_input_unicodei.kmx | Bin 0 -> 440 bytes .../build/k_002___basic_input_unicode.kmx | Bin 0 -> 438 bytes .../test/test-keyboard-info-compiler.ts | 41 +++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 developer/src/kmc-keyboard-info/test/fixtures/two-kmx/build/k_001___basic_input_unicodei.kmx create mode 100644 developer/src/kmc-keyboard-info/test/fixtures/two-kmx/build/k_002___basic_input_unicode.kmx diff --git a/developer/src/kmc-keyboard-info/test/fixtures/two-kmx/build/k_001___basic_input_unicodei.kmx b/developer/src/kmc-keyboard-info/test/fixtures/two-kmx/build/k_001___basic_input_unicodei.kmx new file mode 100644 index 0000000000000000000000000000000000000000..82f60cd001d0ba9bf984253ea81e87a41d1a3df4 GIT binary patch literal 440 zcmZ9HF-t;G7=~X#s>MWBCP z8vP9}_MDHCLLWTmzVG{;^TMs)Hg2>fr4OQln3y{lBGVIk)(}~Ho@S}WHp|`6I;9h`%D+yj7?UpGZ{i4NH}A^0 tgkQh28bbxY>$3^|15WXKKAYk{p^8uWY=-}W(0t3zww>>f%4I09+K_tXM8lC(K z?S6npKZBF?+{3RLJn)?RzVG>+1GiMYtSBONuRr%ic|oIyOds=25Pnn0znZ#-yCkph z0(&rk9ze*tUJ}zGM^#ODXtXMNxN$52Hj-d(W4&F zSLh&Z>y~XPsj~9A&>8wbX}g@%6SI5UZ`tTQ0kDyNNzkUEQ)Gq!2 literal 0 HcmV?d00001 diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index c7cf755513..7cd1ea7a8e 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -8,6 +8,8 @@ import langtags from "../src/imports/langtags.js"; import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; import { CompilerCallbacks, KMX, KeymanFileTypes, KeymanTargets, KmpJsonFile } from '@keymanapp/common-types'; import { KeyboardInfoFile, KeyboardInfoFilePlatform } from './keyboard-info-file.js'; +//import { PackageVersionValidator } from '../../kmc-package/src/compiler/package-version-validator.js'; +//import { KeyboardMetadataCollection } from '../../kmc-package/src/compiler/package-metadata-collector.js'; const callbacks = new TestCompilerCallbacks(); @@ -304,7 +306,7 @@ describe('keyboard-info-compiler', function () { }); it('check loadKmxFiles throws error if .kmx file is missing from disk', async function() { - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); const compiler = new KeyboardInfoCompiler(); const kmpCompiler = new KmpCompiler(); assert.isTrue(await kmpCompiler.init(callbacks, {})); @@ -315,4 +317,41 @@ describe('keyboard-info-compiler', function () { kmpJsonData.files[kmpIndex].name = '../build/throw_error.kmx'; assert.throws(() => compiler['loadKmxFiles'](kpsFilename, kmpJsonData)); }); + + it('check loadKmxFiles can handle two .kmx files', async function() { + const jsFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.js'); + const kpsFilename = makePathToFixture('two-kmx', 'source', 'two-kmx.kps'); + const kmpFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/two-kmx', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const kmx_filename_001 = 'k_001___basic_input_unicodei.kmx'; + const kmx_filename_002 = 'k_002___basic_input_unicode.kmx'; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const kmpJsonData: KmpJsonFile.KmpJsonFile = { + system: { fileVersion: '', keymanDeveloperVersion: '' }, + options: null, + files: [ + { name: '../build/' + kmx_filename_001, description: 'Keyboard 001' }, + { name: '../build/' + kmx_filename_002, description: 'Keyboard 002' }, + ] + }; + const kmxFiles: { + filename: string, + data: KMX.KEYBOARD + }[] = compiler['loadKmxFiles'](kpsFilename, kmpJsonData); + assert.equal(kmxFiles.length, 2); + assert.deepEqual(kmxFiles[0].filename, kmx_filename_001); + assert.deepEqual(kmxFiles[1].filename, kmx_filename_002); + assert.isNotNull(kmxFiles[0].data); + assert.isNotNull(kmxFiles[1].data); + }); }); From 5a5877ae7e64a10fd280c78bc5fffa3f62e204d6 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 25 Mar 2024 17:20:49 +0000 Subject: [PATCH 19/32] chore(developer): add loadJsFile throws error if .js file is invalid test --- .../invalid-js-file/build/invalid_js_file.js | 1 + .../test/test-keyboard-info-compiler.ts | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js diff --git a/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js b/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js new file mode 100644 index 0000000000..816f909dfa --- /dev/null +++ b/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js @@ -0,0 +1 @@ +// This is a file used to test the loadJsFile throws error if .js file is invalid error (see keyboard-info-compiler.ts) \ No newline at end of file diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 7cd1ea7a8e..99f860d5b5 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -319,9 +319,9 @@ describe('keyboard-info-compiler', function () { }); it('check loadKmxFiles can handle two .kmx files', async function() { - const jsFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.js'); - const kpsFilename = makePathToFixture('two-kmx', 'source', 'two-kmx.kps'); - const kmpFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.kmp'); + const jsFilename = makePathToFixture('two-kmx', 'build', 'two_kmx.js'); + const kpsFilename = makePathToFixture('two-kmx', 'source', 'two_kmx.kps'); + const kmpFilename = makePathToFixture('two-kmx', 'build', 'two_kmx.kmp'); const sources = { kmpFilename, @@ -354,4 +354,25 @@ describe('keyboard-info-compiler', function () { assert.isNotNull(kmxFiles[0].data); assert.isNotNull(kmxFiles[1].data); }); + + it('check loadJsFile throws error if .js file is invalid', async function() { + const jsFilename = makePathToFixture('invalid-js-file', 'build', 'invalid_js_file.js'); + const kpsFilename = makePathToFixture('invalid-js-file', 'source', 'invalid_js_file.kps'); + const kmpFilename = makePathToFixture('invalid-js-file', 'build', 'invalid_js_file.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/invalid-js-file', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const origTextDecoderDecode = TextDecoder.prototype.decode; + TextDecoder.prototype.decode = () => { throw new TypeError(); } + assert.throws(() => compiler['loadJsFile'](jsFilename)); + TextDecoder.prototype.decode = origTextDecoderDecode; + }); }); From ce1eba6271efbe8c7015a0f2292b5cdb5bd1db6e Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Mar 2024 10:25:05 +0000 Subject: [PATCH 20/32] chore(developer): add const variables for khmer_angor fixtures --- .../test/test-keyboard-info-compiler.ts | 83 ++++++++++--------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 99f860d5b5..ae4dc81fde 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -17,7 +17,12 @@ beforeEach(function() { callbacks.clear(); }); -const ENLANGTAG = { +const KHMER_ANGKOR_KPJ = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); +const KHMER_ANGKOR_JS = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); +const KHMER_ANGKOR_KPS = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); +const KHMER_ANGKOR_KMP = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + +const EN_LANGTAG = { "full": "en-Latn-US", "iana": [ "English" ], "iso639_3": "eng", @@ -39,10 +44,10 @@ const ENLANGTAG = { describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const buildKeyboardInfoFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.keyboard_info'); const sources = { @@ -80,17 +85,17 @@ describe('keyboard-info-compiler', function () { it('check preinit creates langtagsByTag correctly', async function() { const compiler = new KeyboardInfoCompiler(); // indirectly call preinit() assert.isNotNull(compiler); - assert.deepEqual(langtags.find(({ tag }) => tag === 'en'), ENLANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], ENLANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], ENLANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], ENLANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], ENLANGTAG); + assert.deepEqual(langtags.find(({ tag }) => tag === 'en'), EN_LANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], EN_LANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], EN_LANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], EN_LANGTAG); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], EN_LANGTAG); }); it('check init initialises KeyboardInfoCompiler correctly', async function() { - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -107,10 +112,10 @@ describe('keyboard-info-compiler', function () { }); it('check run returns null if KmpCompiler.init fails', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -130,10 +135,10 @@ describe('keyboard-info-compiler', function () { }); it('check run returns null if KmpCompiler.transformKpsToKmpObject fails', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -153,10 +158,10 @@ describe('keyboard-info-compiler', function () { }); it('check run returns null if loadJsFile fails', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -174,10 +179,10 @@ describe('keyboard-info-compiler', function () { }); it('check run returns null if license is not MIT', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -195,10 +200,10 @@ describe('keyboard-info-compiler', function () { }); it('check run returns null if fillLanguages fails', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -216,10 +221,10 @@ describe('keyboard-info-compiler', function () { }); it('should write artifacts to disk', async function() { - const kpjFilename = makePathToFixture('khmer_angkor', 'khmer_angkor.kpj'); - const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpjFilename = KHMER_ANGKOR_KPJ; + const jsFilename = KHMER_ANGKOR_JS; + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const actualFilename = makePathToFixture('khmer_angkor', 'build', 'actual.keyboard_info'); const expectedFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.keyboard_info'); @@ -290,7 +295,7 @@ describe('keyboard-info-compiler', function () { }); it('check loadKmxFiles returns empty array if .kmx file is missing from .kmp', async function() { - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kpsFilename = KHMER_ANGKOR_KPS; const compiler = new KeyboardInfoCompiler(); const kmpCompiler = new KmpCompiler(); assert.isTrue(await kmpCompiler.init(callbacks, {})); @@ -306,7 +311,7 @@ describe('keyboard-info-compiler', function () { }); it('check loadKmxFiles throws error if .kmx file is missing from disk', async function() { - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); + const kpsFilename = KHMER_ANGKOR_KPS; const compiler = new KeyboardInfoCompiler(); const kmpCompiler = new KmpCompiler(); assert.isTrue(await kmpCompiler.init(callbacks, {})); From 41f5e7f5005a10cf635e30499c1774916de949cc Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Mar 2024 10:40:59 +0000 Subject: [PATCH 21/32] chore(developer): add const variable for khmer angkor sources --- .../test/test-keyboard-info-compiler.ts | 114 +++--------------- 1 file changed, 20 insertions(+), 94 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index ae4dc81fde..122ddd5cd2 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -22,6 +22,14 @@ const KHMER_ANGKOR_JS = makePathToFixture('khmer_angkor', 'build', 'khmer_angko const KHMER_ANGKOR_KPS = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); const KHMER_ANGKOR_KMP = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); +const KHMER_ANGKOR_SOURCES = { + kmpFilename: KHMER_ANGKOR_KMP, + sourcePath: 'release/k/khmer_angkor', + kpsFilename: KHMER_ANGKOR_KPS, + jsFilename: KHMER_ANGKOR_JS, + forPublishing: true, +}; + const EN_LANGTAG = { "full": "en-Latn-US", "iana": [ "English" ], @@ -45,18 +53,8 @@ const EN_LANGTAG = { describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; const buildKeyboardInfoFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.keyboard_info'); - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); @@ -93,18 +91,7 @@ describe('keyboard-info-compiler', function () { }); it('check init initialises KeyboardInfoCompiler correctly', async function() { - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); assert.deepEqual(compiler['callbacks'], callbacks); @@ -113,18 +100,7 @@ describe('keyboard-info-compiler', function () { it('check run returns null if KmpCompiler.init fails', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerInit = KmpCompiler.prototype.init; @@ -136,18 +112,7 @@ describe('keyboard-info-compiler', function () { it('check run returns null if KmpCompiler.transformKpsToKmpObject fails', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerTransformKpsToKmpObject = KmpCompiler.prototype.transformKpsToKmpObject; @@ -159,18 +124,7 @@ describe('keyboard-info-compiler', function () { it('check run returns null if loadJsFile fails', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); compiler['loadJsFile'] = (_filename: string): string => null; @@ -180,18 +134,7 @@ describe('keyboard-info-compiler', function () { it('check run returns null if license is not MIT', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); compiler['isLicenseMIT'] = (_filename: string): boolean => false; @@ -201,18 +144,7 @@ describe('keyboard-info-compiler', function () { it('check run returns null if fillLanguages fails', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; - + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); compiler['fillLanguages'] = async (_kpsFilename: string, _keyboard_info: KeyboardInfoFile, _kmpJsonData: KmpJsonFile.KmpJsonFile): Promise => false; @@ -222,19 +154,9 @@ describe('keyboard-info-compiler', function () { it('should write artifacts to disk', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; const actualFilename = makePathToFixture('khmer_angkor', 'build', 'actual.keyboard_info'); const expectedFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.keyboard_info'); - - const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, - }; + const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); @@ -257,6 +179,10 @@ describe('keyboard-info-compiler', function () { delete expected['lastModifiedDate']; assert.deepEqual(actual, expected); + + if(fs.existsSync(actualFilename)) { // tidy up + fs.rmSync(actualFilename); + } }); it('check mapKeymanTargetToPlatform returns correct platforms', async function() { From 484316c1bc19d6afd3145d50322398f6582411aa Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Mar 2024 10:44:35 +0000 Subject: [PATCH 22/32] chore(developer): remove two commented out imports --- .../src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 122ddd5cd2..fa6e732924 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -8,8 +8,6 @@ import langtags from "../src/imports/langtags.js"; import { KmpCompiler, KmpCompilerOptions } from '@keymanapp/kmc-package'; import { CompilerCallbacks, KMX, KeymanFileTypes, KeymanTargets, KmpJsonFile } from '@keymanapp/common-types'; import { KeyboardInfoFile, KeyboardInfoFilePlatform } from './keyboard-info-file.js'; -//import { PackageVersionValidator } from '../../kmc-package/src/compiler/package-version-validator.js'; -//import { KeyboardMetadataCollection } from '../../kmc-package/src/compiler/package-metadata-collector.js'; const callbacks = new TestCompilerCallbacks(); From 1e21b243351c8e95975a0e90f26d682f36d30f69 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Mar 2024 11:45:41 +0000 Subject: [PATCH 23/32] chore(developer): add check fillLanguages returns false for display font fail test --- .../test/test-keyboard-info-compiler.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index fa6e732924..0e25a4b80f 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -48,6 +48,28 @@ const EN_LANGTAG = { "windows": "en-US" }; +const KHMER_ANGKOR_KEYBOARD = { + displayFont: "Mondulkiri-R.ttf", + oskFont: "khmer_busra_kbd.ttf", + name: "Khmer Angkor", + id: "khmer_angkor", + version: "1.3", + languages: [ + { + name: "Central Khmer (Khmer, Cambodia)", + id: "km", + }, + ], + examples: [ + { + id: "km", + keys: "x j m E r", + text: "ខ្មែរ", + note: "Name of language", + }, + ], +}; + describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; @@ -304,4 +326,21 @@ describe('keyboard-info-compiler', function () { assert.throws(() => compiler['loadJsFile'](jsFilename)); TextDecoder.prototype.decode = origTextDecoderDecode; }); + + it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { + const kpsFilename = KHMER_ANGKOR_KPS; + const keyboard_info: KeyboardInfoFile = {}; + const kmpJsonData: KmpJsonFile.KmpJsonFile = { + system: { fileVersion: '', keymanDeveloperVersion: '' }, + options: null, + keyboards: [KHMER_ANGKOR_KEYBOARD], + }; + + const sources = KHMER_ANGKOR_SOURCES; + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => null; + const result = await compiler['fillLanguages'](kpsFilename, keyboard_info, kmpJsonData); + assert.isFalse(result); + }); }); From e70220e1f6260bd10103b5a5b36f02a2e66c477a Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Mar 2024 12:22:37 +0000 Subject: [PATCH 24/32] chore(developer): add check fillLanguages returns false for osk font fail test --- .../test/test-keyboard-info-compiler.ts | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 0e25a4b80f..2cb38a8477 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -48,9 +48,12 @@ const EN_LANGTAG = { "windows": "en-US" }; +const KHMER_ANGKOR_DISPLAY_FONT = "Mondulkiri-R.ttf"; +const KHMER_ANGKOR_OSK_FONT = "khmer_busra_kbd.ttf"; + const KHMER_ANGKOR_KEYBOARD = { - displayFont: "Mondulkiri-R.ttf", - oskFont: "khmer_busra_kbd.ttf", + displayFont: KHMER_ANGKOR_DISPLAY_FONT, + oskFont: KHMER_ANGKOR_OSK_FONT, name: "Khmer Angkor", id: "khmer_angkor", version: "1.3", @@ -328,8 +331,6 @@ describe('keyboard-info-compiler', function () { }); it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { - const kpsFilename = KHMER_ANGKOR_KPS; - const keyboard_info: KeyboardInfoFile = {}; const kmpJsonData: KmpJsonFile.KmpJsonFile = { system: { fileVersion: '', keymanDeveloperVersion: '' }, options: null, @@ -339,8 +340,35 @@ describe('keyboard-info-compiler', function () { const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); - compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => null; - const result = await compiler['fillLanguages'](kpsFilename, keyboard_info, kmpJsonData); + compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { + if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { + return null; + } else { // osk font + return { family: '', source: _source }; + } + } + const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, {}, kmpJsonData); + assert.isFalse(result); + }); + + it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for osk font', async function() { + const kmpJsonData: KmpJsonFile.KmpJsonFile = { + system: { fileVersion: '', keymanDeveloperVersion: '' }, + options: null, + keyboards: [KHMER_ANGKOR_KEYBOARD], + }; + + const sources = KHMER_ANGKOR_SOURCES; + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { + if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { + return { family: '', source: _source }; + } else { // osk font + return null; + } + } + const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, {}, kmpJsonData); assert.isFalse(result); }); }); From 48d516dd14b6de2468586d7de8a78f8804a2882f Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 1 Apr 2024 10:42:43 +0100 Subject: [PATCH 25/32] chore(developer): add check fillLanguages constructs keyboard_info.languages correctly test --- .../test/test-keyboard-info-compiler.ts | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 2cb38a8477..1808454cc4 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -73,6 +73,9 @@ const KHMER_ANGKOR_KEYBOARD = { ], }; +const KHMER_ANGKOR_DISPLAY_FONT_INFO = { family: "Khmer Mondulkiri", source: [ KHMER_ANGKOR_DISPLAY_FONT ] }; +const KHMER_ANGKOR_OSK_FONT_INFO = { family: "Khmer Busra Kbd", source: [ KHMER_ANGKOR_OSK_FONT ] }; + describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; @@ -330,6 +333,27 @@ describe('keyboard-info-compiler', function () { TextDecoder.prototype.decode = origTextDecoderDecode; }); + it('check fillLanguages constructs keyboard_info.languages correctly', async function() { + const kmpJsonData: KmpJsonFile.KmpJsonFile = { + system: { fileVersion: '', keymanDeveloperVersion: '' }, + options: null, + keyboards: [KHMER_ANGKOR_KEYBOARD], + }; + + const sources = KHMER_ANGKOR_SOURCES; + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { + if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { + return KHMER_ANGKOR_DISPLAY_FONT_INFO; + } else { // osk font + return KHMER_ANGKOR_OSK_FONT_INFO; + } + } + const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, {}, kmpJsonData); + assert.isTrue(result); + }); + it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { const kmpJsonData: KmpJsonFile.KmpJsonFile = { system: { fileVersion: '', keymanDeveloperVersion: '' }, @@ -344,7 +368,7 @@ describe('keyboard-info-compiler', function () { if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { return null; } else { // osk font - return { family: '', source: _source }; + return KHMER_ANGKOR_OSK_FONT_INFO; } } const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, {}, kmpJsonData); @@ -363,7 +387,7 @@ describe('keyboard-info-compiler', function () { assert.isTrue(await compiler.init(callbacks, {sources})); compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { - return { family: '', source: _source }; + return KHMER_ANGKOR_DISPLAY_FONT_INFO; } else { // osk font return null; } @@ -372,3 +396,29 @@ describe('keyboard-info-compiler', function () { assert.isFalse(result); }); }); + +// { +// examples: [ +// { +// keys: "x j m E r", +// note: "Name of language", +// text: "ខ្មែរ", +// }, +// ], +// font: { +// family: "Khmer Mondulkiri", +// source: [ +// "Mondulkiri-R.ttf", +// ], +// }, +// oskFont: { +// family: "Khmer Busra Kbd", +// source: [ +// "khmer_busra_kbd.ttf", +// ], +// }, +// languageName: "Khmer", +// regionName: undefined, +// scriptName: undefined, +// displayName: "Khmer", +// } \ No newline at end of file From a50b8214eaba8929074f9294ef3931654637aa84 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 1 Apr 2024 10:52:23 +0100 Subject: [PATCH 26/32] chore(developer): add keyboard_info.languages assert --- .../test/test-keyboard-info-compiler.ts | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 1808454cc4..37e594cadb 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -50,6 +50,7 @@ const EN_LANGTAG = { const KHMER_ANGKOR_DISPLAY_FONT = "Mondulkiri-R.ttf"; const KHMER_ANGKOR_OSK_FONT = "khmer_busra_kbd.ttf"; +const KHMER_ANGKOR_EXAMPLES_NO_ID = { keys: "x j m E r", text: "ខ្មែរ", note: "Name of language" }; const KHMER_ANGKOR_KEYBOARD = { displayFont: KHMER_ANGKOR_DISPLAY_FONT, @@ -57,20 +58,8 @@ const KHMER_ANGKOR_KEYBOARD = { name: "Khmer Angkor", id: "khmer_angkor", version: "1.3", - languages: [ - { - name: "Central Khmer (Khmer, Cambodia)", - id: "km", - }, - ], - examples: [ - { - id: "km", - keys: "x j m E r", - text: "ខ្មែរ", - note: "Name of language", - }, - ], + languages: [ { name: "Central Khmer (Khmer, Cambodia)", id: "km" } ], + examples: [ { id: "km", ...KHMER_ANGKOR_EXAMPLES_NO_ID } ] }; const KHMER_ANGKOR_DISPLAY_FONT_INFO = { family: "Khmer Mondulkiri", source: [ KHMER_ANGKOR_DISPLAY_FONT ] }; @@ -350,8 +339,18 @@ describe('keyboard-info-compiler', function () { return KHMER_ANGKOR_OSK_FONT_INFO; } } - const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, {}, kmpJsonData); + const keyboard_info: KeyboardInfoFile = {}; + const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, keyboard_info, kmpJsonData); assert.isTrue(result); + assert.deepEqual(keyboard_info.languages, {km: { + examples: [ KHMER_ANGKOR_EXAMPLES_NO_ID ], + font: KHMER_ANGKOR_DISPLAY_FONT_INFO, + oskFont: KHMER_ANGKOR_OSK_FONT_INFO, + languageName: "Khmer", + regionName: undefined, + scriptName: undefined, + displayName: "Khmer", + }}); }); it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { From f2fdee1ee1cde618b903a396d126fada791db9fa Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 1 Apr 2024 12:00:26 +0100 Subject: [PATCH 27/32] chore(developer): add check fillLanguages can handle two keyboards correctly test --- .../test/test-keyboard-info-compiler.ts | 78 ++++++++++++------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 37e594cadb..80c158aaad 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -65,6 +65,23 @@ const KHMER_ANGKOR_KEYBOARD = { const KHMER_ANGKOR_DISPLAY_FONT_INFO = { family: "Khmer Mondulkiri", source: [ KHMER_ANGKOR_DISPLAY_FONT ] }; const KHMER_ANGKOR_OSK_FONT_INFO = { family: "Khmer Busra Kbd", source: [ KHMER_ANGKOR_OSK_FONT ] }; +const SECOND_DISPLAY_FONT = "second.ttf"; +const SECOND_OSK_FONT = "second_osk.ttf"; +const SECOND_EXAMPLES_NO_ID = { keys: "t w o", text: "two", note: "The number 2" }; + +const SECOND_KEYBOARD = { + displayFont: SECOND_DISPLAY_FONT, + oskFont: SECOND_OSK_FONT, + name: "Second Lang", + id: "second_lang", + version: "0.1", + languages: [ { name: "Second Language", id: "en" } ], + examples: [ { id: "en", ...SECOND_EXAMPLES_NO_ID } ] +}; + +const SECOND_DISPLAY_FONT_INFO = { family: "Second", source: [ SECOND_DISPLAY_FONT ] }; +const SECOND_OSK_FONT_INFO = { family: "Second Kbd", source: [ SECOND_OSK_FONT ] }; + describe('keyboard-info-compiler', function () { it('compile a .keyboard_info file correctly', async function() { const kpjFilename = KHMER_ANGKOR_KPJ; @@ -353,6 +370,41 @@ describe('keyboard-info-compiler', function () { }}); }); + it('check fillLanguages can handle two keyboards correctly', async function() { + const kmpJsonData: KmpJsonFile.KmpJsonFile = { + system: { fileVersion: '', keymanDeveloperVersion: '' }, + options: null, + keyboards: [KHMER_ANGKOR_KEYBOARD, SECOND_KEYBOARD], + }; + + const sources = KHMER_ANGKOR_SOURCES; + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { + if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { + return KHMER_ANGKOR_DISPLAY_FONT_INFO; + } else if (_source[0] == KHMER_ANGKOR_OSK_FONT) { + return KHMER_ANGKOR_OSK_FONT_INFO; + } else if (_source[0] == SECOND_DISPLAY_FONT) { + return SECOND_DISPLAY_FONT_INFO; + }else { // second osk font + return SECOND_OSK_FONT_INFO; + } + } + const keyboard_info: KeyboardInfoFile = {}; + const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, keyboard_info, kmpJsonData); + assert.isTrue(result); + // assert.deepEqual(keyboard_info.languages, {km: { + // examples: [ KHMER_ANGKOR_EXAMPLES_NO_ID ], + // font: KHMER_ANGKOR_DISPLAY_FONT_INFO, + // oskFont: KHMER_ANGKOR_OSK_FONT_INFO, + // languageName: "Khmer", + // regionName: undefined, + // scriptName: undefined, + // displayName: "Khmer", + // }}); + }); + it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { const kmpJsonData: KmpJsonFile.KmpJsonFile = { system: { fileVersion: '', keymanDeveloperVersion: '' }, @@ -395,29 +447,3 @@ describe('keyboard-info-compiler', function () { assert.isFalse(result); }); }); - -// { -// examples: [ -// { -// keys: "x j m E r", -// note: "Name of language", -// text: "ខ្មែរ", -// }, -// ], -// font: { -// family: "Khmer Mondulkiri", -// source: [ -// "Mondulkiri-R.ttf", -// ], -// }, -// oskFont: { -// family: "Khmer Busra Kbd", -// source: [ -// "khmer_busra_kbd.ttf", -// ], -// }, -// languageName: "Khmer", -// regionName: undefined, -// scriptName: undefined, -// displayName: "Khmer", -// } \ No newline at end of file From 3eb8705e58ac3bcbb999c31512dcf8a448b6aca1 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 1 Apr 2024 13:54:26 +0100 Subject: [PATCH 28/32] chore(developer): add detailed assert for two keyboards --- .../test/test-keyboard-info-compiler.ts | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 80c158aaad..fb3156090b 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -380,29 +380,32 @@ describe('keyboard-info-compiler', function () { const sources = KHMER_ANGKOR_SOURCES; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); + let callCount = 0; compiler['fontSourceToKeyboardInfoFont'] = async (_kpsFilename: string, _kmpJsonData: KmpJsonFile.KmpJsonFile, _source: string[]) => { - if (_source[0] == KHMER_ANGKOR_DISPLAY_FONT) { - return KHMER_ANGKOR_DISPLAY_FONT_INFO; - } else if (_source[0] == KHMER_ANGKOR_OSK_FONT) { - return KHMER_ANGKOR_OSK_FONT_INFO; - } else if (_source[0] == SECOND_DISPLAY_FONT) { - return SECOND_DISPLAY_FONT_INFO; - }else { // second osk font - return SECOND_OSK_FONT_INFO; - } - } + callCount++; + const info = [KHMER_ANGKOR_DISPLAY_FONT_INFO, KHMER_ANGKOR_OSK_FONT_INFO, SECOND_DISPLAY_FONT_INFO, SECOND_OSK_FONT_INFO]; + return info[callCount-1]; + }; const keyboard_info: KeyboardInfoFile = {}; const result = await compiler['fillLanguages'](KHMER_ANGKOR_KPS, keyboard_info, kmpJsonData); assert.isTrue(result); - // assert.deepEqual(keyboard_info.languages, {km: { - // examples: [ KHMER_ANGKOR_EXAMPLES_NO_ID ], - // font: KHMER_ANGKOR_DISPLAY_FONT_INFO, - // oskFont: KHMER_ANGKOR_OSK_FONT_INFO, - // languageName: "Khmer", - // regionName: undefined, - // scriptName: undefined, - // displayName: "Khmer", - // }}); + assert.deepEqual(keyboard_info.languages, {km: { + examples: [ KHMER_ANGKOR_EXAMPLES_NO_ID ], + font: KHMER_ANGKOR_DISPLAY_FONT_INFO, + oskFont: KHMER_ANGKOR_OSK_FONT_INFO, + languageName: "Khmer", + regionName: undefined, + scriptName: undefined, + displayName: "Khmer", + },en: { + examples: [ SECOND_EXAMPLES_NO_ID ], + font: SECOND_DISPLAY_FONT_INFO, + oskFont: SECOND_OSK_FONT_INFO, + languageName: "English", + regionName: undefined, + scriptName: undefined, + displayName: "English", + }}); }); it('check fillLanguages returns false if fontSourceToKeyboardInfoFont fails for display font', async function() { From 688fe657bc0360e32ae8232309910e5470b22300 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 1 Apr 2024 15:08:16 +0100 Subject: [PATCH 29/32] chore(developer): adjust spacing on two keyboatds test expected result --- .../src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index fb3156090b..4100684e0f 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -397,7 +397,7 @@ describe('keyboard-info-compiler', function () { regionName: undefined, scriptName: undefined, displayName: "Khmer", - },en: { + }, en: { examples: [ SECOND_EXAMPLES_NO_ID ], font: SECOND_DISPLAY_FONT_INFO, oskFont: SECOND_OSK_FONT_INFO, From 707c7ee2927a52209652f080f86a7fd3b712f945 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 2 Apr 2024 13:27:29 +0100 Subject: [PATCH 30/32] chore(developer): remove EN_LANGTAG and replace with dynamic tag from langtags --- .../test/test-keyboard-info-compiler.ts | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 4100684e0f..5d7c518122 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -28,26 +28,6 @@ const KHMER_ANGKOR_SOURCES = { forPublishing: true, }; -const EN_LANGTAG = { - "full": "en-Latn-US", - "iana": [ "English" ], - "iso639_3": "eng", - "localname": "American English", - "localnames": [ "English" ], - "name": "English", - "names": [ "Anglais", "Angleščina", "Anglisy", "Angličtina", "Anglų", "Angol", "Angļu", "Engels", "Engelsk", "Engelska", "Engelski", "Englaisa", "Englanti", "Englesch", "Engleză", "Englisch", "Ingilizce", "Inglese", "Ingliż", "Inglés", "Inglês", "Język angielski", "Kiingereza", "anglais" ], - "region": "US", - "regionname": "United States", - "regions": [ "AD", "AF", "AR", "AS", "AW", "BD", "BG", "BH", "BL", "BN", "BQ", "BT", "BY", "CL", "CN", "CO", "CR", "CW", "CY", "CZ", "DO", "EC", "EE", "ES", "ET", "FM", "FR", "GQ", "GR", "GW", "HN", "HR", "HU", "ID", "IS", "IT", "JP", "KH", "KR", "KW", "LB", "LK", "LT", "LU", "LV", "LY", "MC", "ME", "MF", "MX", "NO", "NP", "OM", "PA", "PL", "PM", "PR", "PT", "RO", "RS", "RU", "SA", "SK", "SO", "SR", "ST", "SV", "TC", "TH", "TN", "TW", "UA", "UM", "UY", "VE", "VG", "VI" ], - "script": "Latn", - "sldr": true, - "suppress": true, - "tag": "en", - "tags": [ "en-Latn", "en-US" ], - "variants": [ "basiceng", "boont", "cornu", "emodeng", "oxendict", "scotland", "scouse", "spanglis", "unifon" ], - "windows": "en-US" -}; - const KHMER_ANGKOR_DISPLAY_FONT = "Mondulkiri-R.ttf"; const KHMER_ANGKOR_OSK_FONT = "khmer_busra_kbd.ttf"; const KHMER_ANGKOR_EXAMPLES_NO_ID = { keys: "x j m E r", text: "ខ្មែរ", note: "Name of language" }; @@ -115,11 +95,11 @@ describe('keyboard-info-compiler', function () { it('check preinit creates langtagsByTag correctly', async function() { const compiler = new KeyboardInfoCompiler(); // indirectly call preinit() assert.isNotNull(compiler); - assert.deepEqual(langtags.find(({ tag }) => tag === 'en'), EN_LANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], EN_LANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], EN_LANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], EN_LANGTAG); - assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], EN_LANGTAG); + const en_langtag = langtags.find(({ tag }) => tag === 'en'); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en'], en_langtag); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn-US'], en_langtag); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-Latn'], en_langtag); + assert.deepEqual((unitTestEndpoints.langtagsByTag)['en-US'], en_langtag); }); it('check init initialises KeyboardInfoCompiler correctly', async function() { From ebeef5f2a87223b21552ee7ff5f78b820ef75c63 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 2 Apr 2024 13:57:37 +0100 Subject: [PATCH 31/32] chore(developer): wrap two uses of stubs in try-catch-finally --- .../test/test-keyboard-info-compiler.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 5d7c518122..2956dbeb12 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -116,9 +116,15 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerInit = KmpCompiler.prototype.init; - KmpCompiler.prototype.init = async (_callbacks: CompilerCallbacks, _options: KmpCompilerOptions): Promise => false; - const result = await compiler.run(kpjFilename, null); - KmpCompiler.prototype.init = origKmpCompilerInit; + let result: KeyboardInfoCompilerResult; + try { + KmpCompiler.prototype.init = async (_callbacks: CompilerCallbacks, _options: KmpCompilerOptions): Promise => false; + result = await compiler.run(kpjFilename, null); + } catch(e) { + assert.fail(e); + } finally { + KmpCompiler.prototype.init = origKmpCompilerInit; + } assert.isNull(result); }); @@ -128,9 +134,15 @@ describe('keyboard-info-compiler', function () { const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); const origKmpCompilerTransformKpsToKmpObject = KmpCompiler.prototype.transformKpsToKmpObject; - KmpCompiler.prototype.transformKpsToKmpObject = (_kpsFilename: string): KmpJsonFile.KmpJsonFile => null; - const result = await compiler.run(kpjFilename, null); - KmpCompiler.prototype.transformKpsToKmpObject = origKmpCompilerTransformKpsToKmpObject; + let result: KeyboardInfoCompilerResult; + try { + KmpCompiler.prototype.transformKpsToKmpObject = (_kpsFilename: string): KmpJsonFile.KmpJsonFile => null; + result = await compiler.run(kpjFilename, null); + } catch(e) { + assert.fail(e); + } finally { + KmpCompiler.prototype.transformKpsToKmpObject = origKmpCompilerTransformKpsToKmpObject; + } assert.isNull(result); }); From 4aa950744cc6e89adce9ec4ab4d4aca4db23c416 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 2 Apr 2024 14:01:01 +0100 Subject: [PATCH 32/32] chore(developer): correct a comment --- .../src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 2956dbeb12..271e045785 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -251,7 +251,7 @@ describe('keyboard-info-compiler', function () { assert.isTrue(await kmpCompiler.init(callbacks, {})); const kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsFilename); assert.isNotNull(kmpJsonData); - // remove .kps file + // remove .kmx file kmpJsonData.files = kmpJsonData.files.filter(file => !KeymanFileTypes.filenameIs(file.name, KeymanFileTypes.Binary.Keyboard)); const kmxFiles: { filename: string,