From 65429bd0896b27aab6d2b3c9b318f87bdc4f68c5 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 18 Apr 2024 10:26:41 +0100 Subject: [PATCH 1/4] chore(developer): replace some fixture paths with constants --- .../test-keyboard-info-compiler-messages.ts | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts index 610aa82133a..4bbcb24fc60 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts @@ -13,6 +13,10 @@ beforeEach(function() { callbacks.clear(); }); +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'); + describe('KeyboardInfoCompilerMessages', function () { it('should have a valid KeyboardInfoCompilerMessages object', function() { return verifyCompilerMessagesObject(KeyboardInfoCompilerMessages, CompilerErrorNamespace.KeyboardInfoCompiler); @@ -22,8 +26,8 @@ describe('KeyboardInfoCompilerMessages', function () { it('should generate ERROR_FileDoesNotExist error if .js file does not exist', async function() { const jsFilename = makePathToFixture('khmer_angkor', 'build', 'xxx.js'); - const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps'); - const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp'); + const kpsFilename = KHMER_ANGKOR_KPS; + const kmpFilename = KHMER_ANGKOR_KMP; const sources = { kmpFilename, @@ -87,9 +91,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_FileDoesNotExist (font file not in package) it('should generate ERROR_FileDoesNotExist error if font file is missing from package', 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, @@ -117,9 +121,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_FileDoesNotExist (font file not on disk) it('should generate ERROR_FileDoesNotExist error if font file is missing from disk', 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, @@ -147,9 +151,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsMissing it('should generate ERROR_LicenseFileIsMissing error if license file is missing from disk', 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, @@ -174,9 +178,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsDamaged (error on decode) it('should generate ERROR_LicenseFileIsDamaged error if license file throws error on decode', 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, @@ -204,9 +208,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsDamaged (null on decode) it('should generate ERROR_LicenseFileIsDamaged error if license file returns null on decode', 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, @@ -234,9 +238,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseIsNotValid it('should generate ERROR_LicenseIsNotValid error if license file is invalid', 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, From 5e14f009b9678e9f57f5049f8d6d57723433ceae Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 18 Apr 2024 10:48:48 +0100 Subject: [PATCH 2/4] chore(developer): replace khmer_angkor sources with constant --- .../test-keyboard-info-compiler-messages.ts | 86 ++++--------------- 1 file changed, 17 insertions(+), 69 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts index 4bbcb24fc60..62b75cd9979 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts @@ -17,6 +17,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, +}; + describe('KeyboardInfoCompilerMessages', function () { it('should have a valid KeyboardInfoCompilerMessages object', function() { return verifyCompilerMessagesObject(KeyboardInfoCompilerMessages, CompilerErrorNamespace.KeyboardInfoCompiler); @@ -33,7 +41,7 @@ describe('KeyboardInfoCompilerMessages', function () { kmpFilename, sourcePath: 'release/k/khmer_angkor', kpsFilename, - jsFilename: jsFilename, + jsFilename, forPublishing: true, }; @@ -65,7 +73,7 @@ describe('KeyboardInfoCompilerMessages', function () { kmpFilename, sourcePath: 'release/k/no-kmp', kpsFilename, - jsFilename: jsFilename, + jsFilename, forPublishing: true, }; @@ -91,27 +99,15 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_FileDoesNotExist (font file not in package) it('should generate ERROR_FileDoesNotExist error if font file is missing from package', 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})); const kmpJsonData: KmpJsonFile.KmpJsonFile = {system: {fileVersion: "7.0", keymanDeveloperVersion: "17.0.204"}, options: {}, files: []} const source = ["Mondulkiri-R.ttf"] - const result = await compiler['fontSourceToKeyboardInfoFont'](kpsFilename, kmpJsonData, source) + const result = await compiler['fontSourceToKeyboardInfoFont'](KHMER_ANGKOR_KPS, kmpJsonData, source) assert.isNull(result); - assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist), `ERROR_FileDoesNotExist not generated, instead got: `+JSON.stringify(callbacks.messages,null,2)); assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist).includes(source[0]), @@ -121,27 +117,15 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_FileDoesNotExist (font file not on disk) it('should generate ERROR_FileDoesNotExist error if font file is missing from disk', 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})); const kmpJsonData: KmpJsonFile.KmpJsonFile = {system: {fileVersion: "7.0", keymanDeveloperVersion: "17.0.204"}, options: {}, files: [{name: "../shared/fonts/khmer/mondulkiri/xxx.ttf", description: "Font not on disk"}]} const source = ["xxx.ttf"] - const result = await compiler['fontSourceToKeyboardInfoFont'](kpsFilename, kmpJsonData, source) + const result = await compiler['fontSourceToKeyboardInfoFont'](KHMER_ANGKOR_KPS, kmpJsonData, source) assert.isNull(result); - assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist), `ERROR_FileDoesNotExist not generated, instead got: `+JSON.stringify(callbacks.messages,null,2)); assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist).includes(kmpJsonData.files[0].name), @@ -151,24 +135,12 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsMissing it('should generate ERROR_LicenseFileIsMissing error if license file is missing from disk', 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})); const licenseFilename = makePathToFixture('khmer_angkor', 'xxx.md'); const result = compiler['isLicenseMIT'](licenseFilename) assert.isFalse(result); - assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsMissing), `ERROR_LicenseFileIsMissing not generated, instead got: `+JSON.stringify(callbacks.messages,null,2)); assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsMissing).includes(licenseFilename), @@ -178,18 +150,7 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsDamaged (error on decode) it('should generate ERROR_LicenseFileIsDamaged error if license file throws error on decode', 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})); const licenseFilename = makePathToFixture('khmer_angkor', 'LICENSE.md'); @@ -198,7 +159,6 @@ describe('KeyboardInfoCompilerMessages', function () { const result = compiler['isLicenseMIT'](licenseFilename) TextDecoder.prototype.decode = originalDecode assert.isFalse(result); - assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged), `ERROR_LicenseFileIsDamaged not generated, instead got: `+JSON.stringify(callbacks.messages,null,2)); assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged).includes(licenseFilename), @@ -208,18 +168,7 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseFileIsDamaged (null on decode) it('should generate ERROR_LicenseFileIsDamaged error if license file returns null on decode', 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})); const licenseFilename = makePathToFixture('khmer_angkor', 'LICENSE.md'); @@ -228,7 +177,6 @@ describe('KeyboardInfoCompilerMessages', function () { const result = compiler['isLicenseMIT'](licenseFilename) TextDecoder.prototype.decode = originalDecode assert.isFalse(result); - assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged), `ERROR_LicenseFileIsDamaged not generated, instead got: `+JSON.stringify(callbacks.messages,null,2)); assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged).includes(licenseFilename), From e6f40ad73a8481e00cf2cc9782b6a2f6f1dc26ad Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 18 Apr 2024 11:21:06 +0100 Subject: [PATCH 3/4] chore(developer): simplify a TextDecoder.decode stub --- .../test/test-keyboard-info-compiler-messages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts index 62b75cd9979..439839fe481 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts @@ -173,7 +173,7 @@ describe('KeyboardInfoCompilerMessages', function () { assert.isTrue(await compiler.init(callbacks, {sources})); const licenseFilename = makePathToFixture('khmer_angkor', 'LICENSE.md'); const originalDecode = TextDecoder.prototype.decode - TextDecoder.prototype.decode = () => { return null } + TextDecoder.prototype.decode = () => null; const result = compiler['isLicenseMIT'](licenseFilename) TextDecoder.prototype.decode = originalDecode assert.isFalse(result); From e742926dba0d9e09be6ecb463581b5ce82839de8 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 23 Apr 2024 11:58:04 +0100 Subject: [PATCH 4/4] chore(developer): some further elimination of code redundancy --- .../test-keyboard-info-compiler-messages.ts | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts index 439839fe481..8a9c2652ba0 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts @@ -34,22 +34,17 @@ describe('KeyboardInfoCompilerMessages', function () { it('should generate ERROR_FileDoesNotExist error if .js file does not exist', async function() { const jsFilename = makePathToFixture('khmer_angkor', 'build', 'xxx.js'); - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; const sources = { - kmpFilename, - sourcePath: 'release/k/khmer_angkor', - kpsFilename, + ...KHMER_ANGKOR_SOURCES, jsFilename, - forPublishing: true, }; const compiler = new KeyboardInfoCompiler(); assert.isTrue(await compiler.init(callbacks, {sources})); let result: KeyboardInfoCompilerResult = null; try { - result = await compiler.run(kmpFilename, null); + result = await compiler.run(KHMER_ANGKOR_KMP, null); } catch(e) { callbacks.printMessages(); throw e; @@ -186,16 +181,9 @@ describe('KeyboardInfoCompilerMessages', function () { // ERROR_LicenseIsNotValid it('should generate ERROR_LicenseIsNotValid error if license file is invalid', async function() { - const jsFilename = KHMER_ANGKOR_JS; - const kpsFilename = KHMER_ANGKOR_KPS; - const kmpFilename = KHMER_ANGKOR_KMP; - const sources = { - kmpFilename, + ...KHMER_ANGKOR_SOURCES, sourcePath: 'release/k/invalid-license', - kpsFilename, - jsFilename: jsFilename, - forPublishing: true, }; const compiler = new KeyboardInfoCompiler(); @@ -281,7 +269,7 @@ describe('KeyboardInfoCompilerMessages', function () { kmpFilename, sourcePath: 'release/k/font-meta-data-is-invalid', kpsFilename, - jsFilename: jsFilename, + jsFilename, forPublishing: true, };