From 96025af32e732fd604adfc06001787a18c47b8aa Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 26 Jun 2025 11:45:59 +0200 Subject: [PATCH 01/12] feat(developer): write output to in-memory artifact finished --- developer/src/kmc-convert/src/converter.ts | 5 +- .../keylayout-to-kmn-converter.ts | 113 ++++-------------- 2 files changed, 24 insertions(+), 94 deletions(-) diff --git a/developer/src/kmc-convert/src/converter.ts b/developer/src/kmc-convert/src/converter.ts index 0d886aab8f..f36530fcf8 100644 --- a/developer/src/kmc-convert/src/converter.ts +++ b/developer/src/kmc-convert/src/converter.ts @@ -65,7 +65,7 @@ export class Converter implements KeymanCompiler { // _S2 finds converter e.g.keylayout->kmn ( uses converter-class-factory) // _S2 factory uses/instanciates child class ( ~ in C++ virtual function in base class <-> use fun of derived class) // _S2 loads file - // _S2 creates a new converter (-object) + // _S2 creates a new (derived) converter (-object) // _S2 runs conversion for this object ( run-method of this converter of keylayout-to-kmn-tonverter.ts ) async run(inputFilename: string, outputFilename?: string): Promise { const converterOptions: CompilerOptions = { @@ -93,7 +93,8 @@ export class Converter implements KeymanCompiler { const converter = new ConverterClass(this.callbacks, converterOptions); const artifacts = await converter.run(inputFilename, outputFilename); // Note: any subsequent errors in conversion will have been reported by the converter - return artifacts ? { artifacts } : null; + //return artifacts ? { artifacts } : null; + return artifacts ? artifacts : null; } /** diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 7f27983c72..a9cb3af913 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -7,12 +7,20 @@ * */ -import { CompilerCallbacks, CompilerOptions } from "@keymanapp/developer-utils"; +import { CompilerCallbacks, CompilerOptions, KeymanCompilerResult, } from "@keymanapp/developer-utils"; import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; import { KmnFileWriter } from './kmn-file-writer.js'; import { KeylayoutFileReader } from './keylayout-file-reader.js'; import { ConverterMessages } from '../converter-messages.js'; +import { ConverterArtifacts } from "../converter-artifacts.js"; +export interface ConverterResult extends KeymanCompilerResult { + /** + * Internal in-memory build artifacts from a successful compilation. Caller + * can write these to disk with {@link Converter.write} + */ + artifacts: ConverterArtifacts; +}; export interface convert_object { keylayout_filename: string, @@ -49,7 +57,7 @@ export class KeylayoutToKmnConverter { * @param outputFilename the resulting keyman .kmn-file * @return null on success */ - async run(inputFilename: string, outputFilename?: string): Promise { + async run(inputFilename: string, outputFilename?: string): Promise { if (!inputFilename) { this.callbacks.reportMessage(ConverterMessages.Error_FileNotFound({ inputFilename })); @@ -71,108 +79,29 @@ export class KeylayoutToKmnConverter { const kmnFileWriter = new KmnFileWriter(this.callbacks, this.options); + // _S2 still write to file - may be removed later const out_text_ok: boolean = kmnFileWriter.write(outArray); if (!out_text_ok) { this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); return null; } - /*const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); - if (!out_Uint8) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); - return null; - }*/ - - /*const out_str: string = kmnFileWriter.writeToString(outArray); - if (!out_str) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); - return null; - }*/ - - - /* - const a: ConverterToKmnArtifacts = null; - const ddd= a.data - return a ? a : null; - - data of convert_object needs to be in ConverterToKmnArtifacts: - (ConverterToKmnArtifacts= outArray ???) - return ConverterToKmnArtifacts ? { ConverterToKmnArtifacts } : null; - --- - const converter = new ConverterClass(this.callbacks, converterOptions); - const artifacts = await converter.run(inputFilename, outputFilename); - return artifacts ? { artifacts } : null;*/ - - return null; - } - - async run_new(inputFilename: string, outputFilename?: string): Promise { - - if (!inputFilename) { - this.callbacks.reportMessage(ConverterMessages.Error_FileNotFound({ inputFilename })); - return null; - } - - const KeylayoutReader = new KeylayoutFileReader(this.callbacks/*, this.options*/); - const jsonO: object = KeylayoutReader.read(inputFilename); - if (!jsonO) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToRead({ inputFilename })); - return null; - } - - const outArray: convert_object = await this.convert(jsonO, outputFilename); - if (!outArray) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToConvert({ inputFilename })); - return null; - } - - const kmnFileWriter = new KmnFileWriter(this.callbacks, this.options); - - const out_text_ok: boolean = kmnFileWriter.write(outArray); - if (!out_text_ok) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); - return null; - } - - - // xxx write my data - const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); - if (!out_Uint8) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); - return null; - } - // xxx get my name + // write to object/ConverterResult outputFilename = outputFilename ?? inputFilename.replace(/\.keylayout$/, '.kmn'); - // xxx return filled artifact - /* return { + const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); + const Result_toBeReturned = { artifacts: { - kmx: { data: out_Uint8, filename: outputFilename }, + kmn: { data: out_Uint8, filename: outputFilename }, } }; - */ - /*const out_str: string = kmnFileWriter.writeToString(outArray); - if (!out_str) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); - return null; - }*/ + // _S2 does this still work? + if (!out_Uint8) { + this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); + return null; + } - - /* - const a: ConverterToKmnArtifacts = null; - const ddd= a.data - return a ? a : null; - - data of convert_object needs to be in ConverterToKmnArtifacts: - (ConverterToKmnArtifacts= outArray ???) - return ConverterToKmnArtifacts ? { ConverterToKmnArtifacts } : null; - --- - const converter = new ConverterClass(this.callbacks, converterOptions); - const artifacts = await converter.run(inputFilename, outputFilename); - return artifacts ? { artifacts } : null; - */ - - return null; + return Result_toBeReturned; } /** From 04a08a984c03402e578f64acbc5737537284b7a3 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 26 Jun 2025 11:47:50 +0200 Subject: [PATCH 02/12] feat(developer): type added for definition of result --- .../src/keylayout-to-kmn/keylayout-to-kmn-converter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index a9cb3af913..9029f466c8 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -89,9 +89,9 @@ export class KeylayoutToKmnConverter { // write to object/ConverterResult outputFilename = outputFilename ?? inputFilename.replace(/\.keylayout$/, '.kmn'); const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); - const Result_toBeReturned = { + const Result_toBeReturned: ConverterResult = { artifacts: { - kmn: { data: out_Uint8, filename: outputFilename }, + kmn: { data: out_Uint8, filename: outputFilename } } }; From e0a7d70d3a0e78d37ed39d733ac4d3baa72063d5 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 26 Jun 2025 14:26:39 +0200 Subject: [PATCH 03/12] feat(developer): typos --- .../src/keylayout-to-kmn/keylayout-to-kmn-converter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 9029f466c8..13879807f2 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -100,7 +100,6 @@ export class KeylayoutToKmnConverter { this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); return null; } - return Result_toBeReturned; } From c6da5468d0620c69bc60b7f213c06adc8dad5ca7 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 26 Jun 2025 14:26:39 +0200 Subject: [PATCH 04/12] feat(developer): remove import --- .../src/keylayout-to-kmn/keylayout-to-kmn-converter.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 9029f466c8..ad68b81e3e 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -8,7 +8,7 @@ */ import { CompilerCallbacks, CompilerOptions, KeymanCompilerResult, } from "@keymanapp/developer-utils"; -import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; +//import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; import { KmnFileWriter } from './kmn-file-writer.js'; import { KeylayoutFileReader } from './keylayout-file-reader.js'; import { ConverterMessages } from '../converter-messages.js'; @@ -100,7 +100,6 @@ export class KeylayoutToKmnConverter { this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); return null; } - return Result_toBeReturned; } From 615ebe6c0b7c69a1ab81e44844d8488022056424 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 26 Jun 2025 15:10:28 +0200 Subject: [PATCH 05/12] feat(developer):kmc-convert write ConverterToKmnResult instead of ConverterResult --- .../keylayout-to-kmn-converter.ts | 16 ++++++--- .../test/keylayout-to-kmn-converter.tests.ts | 36 ------------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index ad68b81e3e..e457ef150d 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -8,11 +8,11 @@ */ import { CompilerCallbacks, CompilerOptions, KeymanCompilerResult, } from "@keymanapp/developer-utils"; -//import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; import { KmnFileWriter } from './kmn-file-writer.js'; import { KeylayoutFileReader } from './keylayout-file-reader.js'; import { ConverterMessages } from '../converter-messages.js'; import { ConverterArtifacts } from "../converter-artifacts.js"; +import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; export interface ConverterResult extends KeymanCompilerResult { /** @@ -22,6 +22,14 @@ export interface ConverterResult extends KeymanCompilerResult { artifacts: ConverterArtifacts; }; +export interface ConverterToKmnResult extends ConverterResult { + /** + * Internal in-memory build artifacts from a successful compilation. Caller + * can write these to disk with {@link Converter.write} + */ + artifacts: ConverterToKmnArtifacts; +}; + export interface convert_object { keylayout_filename: string, kmn_filename: string, @@ -57,7 +65,7 @@ export class KeylayoutToKmnConverter { * @param outputFilename the resulting keyman .kmn-file * @return null on success */ - async run(inputFilename: string, outputFilename?: string): Promise { + async run(inputFilename: string, outputFilename?: string): Promise { if (!inputFilename) { this.callbacks.reportMessage(ConverterMessages.Error_FileNotFound({ inputFilename })); @@ -86,10 +94,10 @@ export class KeylayoutToKmnConverter { return null; } - // write to object/ConverterResult + // write to object/ConverterToKmnResult outputFilename = outputFilename ?? inputFilename.replace(/\.keylayout$/, '.kmn'); const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); - const Result_toBeReturned: ConverterResult = { + const Result_toBeReturned: ConverterToKmnResult = { artifacts: { kmn: { data: out_Uint8, filename: outputFilename } } diff --git a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts index daec2fbbb6..230d9cea4f 100644 --- a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts +++ b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts @@ -20,42 +20,6 @@ describe('KeylayoutToKmnConverter', function () { before(function () { compilerTestCallbacks.clear(); }); - // todo remove - describe('RunOneFile', function () { - const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); - const inputFilename = makePathToFixture('../data/Italian.keylayout'); - sut.run(inputFilename); - assert.isTrue(true); - }); - - // todo remove - describe('RunAllFiles', function () { - const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); - [ - [makePathToFixture('../data/Italian.keylayout')], - [makePathToFixture('../data/Italian_command.keylayout')], - [makePathToFixture('../data/Swiss_French.keylayout')], - [makePathToFixture('../data/Spanish.keylayout')], - [makePathToFixture('../data/Swiss_German.keylayout')], - [makePathToFixture('../data/US.keylayout')], - [makePathToFixture('../data/Polish.keylayout')], - [makePathToFixture('../data/French.keylayout')], - [makePathToFixture('../data/Latin_American.keylayout')], - [makePathToFixture('../data/German_complete.keylayout')], - /* [makePathToFixture('../data/German_complete_reduced.keylayout')], - [makePathToFixture('../data/German_Standard.keylayout')],*/ - ].forEach(function (files_) { - sut.run(files_[0]); - assert.isTrue(true); - }); - }); - // todo remove - describe('RunOneFile', function () { - const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); - const inputFilename = makePathToFixture('../data/Test.keylayout'); - sut.run(inputFilename); - assert.isTrue(true); - }); describe('run() ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); From e85c4564ef31769013f84d636424aa0b7ecc7b6c Mon Sep 17 00:00:00 2001 From: Sabine Date: Fri, 27 Jun 2025 14:07:04 +0200 Subject: [PATCH 06/12] feat(developer): change timeout for run() test --- .../src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts index 230d9cea4f..b980a7c742 100644 --- a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts +++ b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts @@ -22,6 +22,11 @@ describe('KeylayoutToKmnConverter', function () { }); describe('run() ', function () { + + // _S2 can I do this??? - some tests of the run() function might take longer than 2000 ms + // see https://pramod-mallick.medium.com/mocha-with-selenium-webdriver-exception-timeout-of-2000ms-exceeded-89df7b6230c6 + this.timeout(10000); + const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); it('run() should throw on null input file name and null output file name', async function () { From 952dba6a2f7404455ec1e4f314d63f98ea974411 Mon Sep 17 00:00:00 2001 From: Sabine Date: Mon, 7 Jul 2025 14:33:08 +0200 Subject: [PATCH 07/12] feat(developer): remove linebreak in Errormessages --- .../src/kmc-convert/src/converter-messages.ts | 17 ++++++----------- .../keylayout-to-kmn-converter.ts | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/developer/src/kmc-convert/src/converter-messages.ts b/developer/src/kmc-convert/src/converter-messages.ts index 8e2e60aee1..42b3bb825e 100644 --- a/developer/src/kmc-convert/src/converter-messages.ts +++ b/developer/src/kmc-convert/src/converter-messages.ts @@ -23,31 +23,26 @@ export class ConverterMessages { static ERROR_NoConverterFound = SevError | 0x0002; static Error_NoConverterFound = (o: { inputFilename: string, outputFilename: string; }) => m( - this.ERROR_NoConverterFound, - `No converter is available that can convert from '${def(o.inputFilename)}' to '${def(o.outputFilename)}'.`); + this.ERROR_NoConverterFound, `No converter is available that can convert from '${def(o.inputFilename)}' to '${def(o.outputFilename)}'.`); static ERROR_FileNotFound = SevError | 0x0003; static Error_FileNotFound = (o: { inputFilename: string; }) => m( - this.ERROR_FileNotFound, `Input filename '${def(o.inputFilename)} - ' does not exist or could not be loaded.`); + this.ERROR_FileNotFound, `Input filename '${def(o.inputFilename)} ' does not exist or could not be loaded.`); static ERROR_UnableToRead = SevError | 0x0004; static Error_UnableToRead = (o: { inputFilename: string; }) => m( - this.ERROR_UnableToRead, `Input file '${def(o.inputFilename)} - ' could not be read.`); + this.ERROR_UnableToRead, `Input file '${def(o.inputFilename)} ' could not be read.`); static ERROR_UnableToConvert = SevError | 0x0005; static Error_UnableToConvert = (o: { inputFilename: string; }) => m( - this.ERROR_UnableToConvert, `Input file '${def(o.inputFilename)} - ' could not be converted.`); + this.ERROR_UnableToConvert, `Input file '${def(o.inputFilename)} ' could not be converted.`); static ERROR_UnableToWrite = SevError | 0x0006; static Error_UnableToWrite = (o: { outputFilename: string; }) => m( - this.ERROR_UnableToWrite, `Output file for '${def(o.outputFilename)} - ' could not be written.`); + this.ERROR_UnableToWrite, `Output file for '${def(o.outputFilename)} ' could not be written.`); static ERROR_UnsupportedCharactersDetected = SevError | 0x0007; static Error_UnsupportedCharactersDetected = (o: { inputFilename: string, keymap_index: string, key: string, output: string; }) => m( this.ERROR_UnsupportedCharactersDetected, `Input file ${def(o.inputFilename)} contains unsupported character ('${def(o.output)}') on key (${def(o.key)}) at keyMap index ${def(o.keymap_index)}`); - } +} diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 3f3784a8a2..0dd61ae996 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -63,12 +63,13 @@ export class KeylayoutToKmnConverter { */ async run(inputFilename: string, outputFilename?: string): Promise { - if (!inputFilename) { this.callbacks.reportMessage(ConverterMessages.Error_FileNotFound({ inputFilename })); return null; } + outputFilename = outputFilename ?? inputFilename.replace(/\.keylayout$/, '.kmn'); + const KeylayoutReader = new KeylayoutFileReader(this.callbacks/*, this.options*/); const jsonO: object = KeylayoutReader.read(inputFilename); if (!jsonO) { @@ -87,12 +88,11 @@ export class KeylayoutToKmnConverter { // _S2 still write to file - may be removed later const out_text_ok: boolean = kmnFileWriter.write(outArray); if (!out_text_ok) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ inputFilename })); + this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ outputFilename })); return null; } // write to object/ConverterToKmnResult - outputFilename = outputFilename ?? inputFilename.replace(/\.keylayout$/, '.kmn'); const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); const Result_toBeReturned: ConverterToKmnResult = { artifacts: { @@ -133,7 +133,7 @@ export class KeylayoutToKmnConverter { data_object.arrayOf_Rules = rules; // _S2 ToDo remove this console.log - console.log("RUN kmc convert - input file: ",data_object.keylayout_filename, " --> output file: ", data_object.kmn_filename); + console.log("RUN kmc convert - input file: ", data_object.keylayout_filename, " --> output file: ", data_object.kmn_filename); // create an array of modifier combinations and store in data_object for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { From 87d6e07062473de9eb8f6d312994ea63973f1eaf Mon Sep 17 00:00:00 2001 From: Sabine Date: Wed, 9 Jul 2025 13:34:37 +0200 Subject: [PATCH 08/12] feat(developer): change path in makePathToFixture --- .../keylayout-to-kmn-converter.ts | 1 - .../src/keylayout-to-kmn/kmn-file-writer.ts | 6 +- .../test/keylayout-to-kmn-converter.tests.ts | 247 ++---------------- .../kmc-convert/test/kmn-file-reader.tests.ts | 6 +- .../kmc-convert/test/kmn-file-writer.tests.ts | 26 +- 5 files changed, 40 insertions(+), 246 deletions(-) diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 0dd61ae996..fdd14406d8 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -124,7 +124,6 @@ export class KeylayoutToKmnConverter { arrayOf_Rules: [] }; - // ToDo in a new PR: check tags ( issue # 13599) if ((jsonObj !== null) && (jsonObj.hasOwnProperty("keyboard"))) { data_object.keylayout_filename = outputfilename.replace(/\.kmn$/, '.keylayout'); diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts index 8fdeb377a1..705bd7b53e 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts @@ -37,7 +37,7 @@ export class KmnFileWriter { this.callbacks.fs.writeFileSync(data_ukelele.kmn_filename, new TextEncoder().encode(data)); return true; } catch (err) { - this.callbacks.reportMessage(ConverterMessages.Error_OutputFilenameIsRequired()); + this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({outputFilename: data_ukelele.kmn_filename})); return false; } } @@ -54,7 +54,7 @@ export class KmnFileWriter { try { return data; } catch (err) { - this.callbacks.reportMessage(ConverterMessages.Error_OutputFilenameIsRequired()); + this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({outputFilename: data_ukelele.kmn_filename})); return null; } } @@ -71,7 +71,7 @@ export class KmnFileWriter { try { return new TextEncoder().encode(data); } catch (err) { - this.callbacks.reportMessage(ConverterMessages.Error_OutputFilenameIsRequired()); + this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({outputFilename: data_ukelele.kmn_filename})); return null; } } diff --git a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts index d196efe11e..c37a9e8e8c 100644 --- a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts +++ b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts @@ -53,43 +53,41 @@ describe('KeylayoutToKmnConverter', function () { }); it('run() should throw on unavailable input file name and null output file name', async function () { - const inputFilename = makePathToFixture('../data/Unavailable.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Unavailable.keylayout'); const result = sut.run(inputFilename, null); assert.isNotNull(result); assert.equal(compilerTestCallbacks.messages.length, 2); assert.deepEqual(compilerTestCallbacks.messages[0], ConverterMessages.Error_FileNotFound({ inputFilename: inputFilename })); - assert.deepEqual(compilerTestCallbacks.messages[1], ConverterMessages.Error_UnableToRead({ inputFilename: inputFilename })); }); it('run() should return on correct input file name and empty output file name ', async function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, '')); }); it('run() should return on correct input file name and null output file name', async function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, null)); }); it('run() should return on correct input file name and given output file name ', async function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); - const outputFilename = makePathToFixture('../data/OutputName.kmn'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const outputFilename = makePathToFixture('../' + 'data' + '/OutputName.kmn'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, outputFilename)); }); it('run() should throw on incorrect input file extention and output file extention', async function () { - const inputFilename = makePathToFixture('../data/Test_command.A'); - const outputFilename = makePathToFixture('../data/data/OutputXName.B'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test_command.A'); + const outputFilename = makePathToFixture('../' + 'data' + '/data/OutputXName.B'); const result = sut.run(inputFilename, outputFilename); assert.isNotNull(result); assert.equal(compilerTestCallbacks.messages.length, 2); assert.deepEqual(compilerTestCallbacks.messages[0], ConverterMessages.Error_FileNotFound({ inputFilename: inputFilename })); - assert.deepEqual(compilerTestCallbacks.messages[1], ConverterMessages.Error_UnableToRead({ inputFilename: inputFilename })); }); it('run() return on correct input file extention and unsupperted output file extention', async function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); - const outputFilename = makePathToFixture('../data/OutputXName.B'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const outputFilename = makePathToFixture('../' + 'data' + '/OutputXName.B'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, outputFilename)); }); }); @@ -97,19 +95,19 @@ describe('KeylayoutToKmnConverter', function () { describe('convert() ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); - // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('X.keylayout'); + // convert_object from unavailable file name + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); - // empty convert_object from empty filename + // convert_object from empty filename const inputFilename_empty = makePathToFixture(''); const read_empty = sut_r.read(inputFilename_empty); - const converted_empty = sut.convert_bound.convert(read_empty, inputFilename_empty.replace(/\.keylayout$/, '.kmn')); + const converted_empty = sut.convert_bound.convert(read_empty, inputFilename_empty); it('should return converted array on correct input', async function () { assert.isTrue(converted.arrayOf_Rules.length !== 0); @@ -258,13 +256,12 @@ describe('KeylayoutToKmnConverter', function () { describe('get_Modifier_array__From__KeyModifier_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); [ [[['0', 0]], [['', 'shift? caps? ']]], - // Italian: [[['0', 1]], [['anyShift caps?', 'shift? rightShift caps? ', 'shift? leftShift caps? ', 'shift leftShift caps ']]], [[['0', 2]], [['shift? leftShift caps? ', 'anyShift caps?', 'shift leftShift caps ', 'shift? rightShift caps? ']]], [[['0', 999]], [null]], [[['999',]], [null]], @@ -294,17 +291,13 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyModifier_array__From__ActionID ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); [ - // Italian: ['a16', [['32', 3]]], - // Italian: ['a19', [['45', 3]]], - // Italian: ['a18', [['24', 0], ['24', 3]]], ['A_16', [['32', 5]]], ['A_19', [['45', 5]]], ['A_18', [['24', 0], ['24', 5]]], - ['unknown', []], [undefined, []], [null, []], @@ -327,22 +320,16 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionID__From__ActionNext ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); [ ['none', ''], - // Italian: ['a18', ''], ['0', ''], - // Italian: ['1', 'a16'], - // Italian: // Italian: ['2', 'a8'], - // Italian: ['3', 'a17'], - ['A_18', ''], ['1', 'A_16'], ['2', 'A_8'], ['3', 'A_17'], - ['', ''], [' ', ''], ['99', ''], @@ -360,14 +347,11 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionIndex__From__ActionId ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); [ ['none', 0], - // Italian: ['a16', 8], - // Italian: ['a18', 10], - // Italian: ['a19', 11], ['A_16', 8], ['A_18', 10], ['A_19', 11], @@ -388,15 +372,13 @@ describe('KeylayoutToKmnConverter', function () { describe('get_Output__From__ActionId_None ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); [ - // Italian: ['a14', 'u'], ['A_14', 'u'], ['', ''], [' ', ''], - // Italian: ['a18', undefined], ['A_18', undefined], ['unknown', ''], ].forEach(function (values) { @@ -421,76 +403,8 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); - /*Italian: - - const b1_keycode_arr = [ - ['49', 'K_SPACE', 'a0', '0', 'ˆ'], - ['49', 'K_SPACE', 'a0', '1', 'ˆ'], - ['49', 'K_SPACE', 'a0', '2', 'ˆ'], - ['6', 'K_Z', 'a0', '4', 'ˆ'], - ['25', 'K_9', 'a0', '4', 'ˆ'], - ['43', 'K_COMMA', 'a0', '4', 'ˆ'], - ['49', 'K_SPACE', 'a0', '7', 'ˆ'], - ['0', 'K_A', 'a1', '1', 'Â'], - ['0', 'K_A', 'a1', '2', 'Â'], - ['14', 'K_E', 'a10', '0', 'ê'], - ['34', 'K_I', 'a11', '0', 'î'], - ['31', 'K_O', 'a13', '0', 'ô'], - ['32', 'K_U', 'a14', '0', 'û'], - ['14', 'K_E', 'a2', '1', 'Ê'], - ['14', 'K_E', 'a2', '2', 'Ê'], - ['34', 'K_I', 'a3', '1', 'Î'], - ['34', 'K_I', 'a3', '2', 'Î'], - ['31', 'K_O', 'a5', '1', 'Ô'], - ['31', 'K_O', 'a5', '2', 'Ô'], - ['32', 'K_U', 'a6', '1', 'Û'], - ['32', 'K_U', 'a6', '2', 'Û'], - ['0', 'K_A', 'a9', '0', 'â'] - ]; - const b1_modifierKey_arr = [ - ['K_SPACE', 'a0', '0', 'NCAPS', 'ˆ'], - ['K_SPACE', 'a0', '1', 'NCAPS SHIFT', 'ˆ'], - ['K_SPACE', 'a0', '1', 'SHIFT CAPS', 'ˆ'], - ['K_SPACE', 'a0', '2', 'CAPS', 'ˆ'], - ['K_Z', 'a0', '4', 'NCAPS SHIFT RALT', 'ˆ'], - ['K_9', 'a0', '4', 'NCAPS SHIFT RALT', 'ˆ'], - ['K_COMMA', 'a0', '4', 'NCAPS SHIFT RALT', 'ˆ'], - ['K_SPACE', 'a0', '7', 'NCAPS CTRL', 'ˆ'], - ['K_SPACE', 'a0', '7', 'NCAPS RALT CTRL', 'ˆ'], - ['K_A', 'a1', '1', 'NCAPS SHIFT', 'Â'], - ['K_A', 'a1', '1', 'SHIFT CAPS', 'Â'], - ['K_A', 'a1', '2', 'CAPS', 'Â'], - ['K_E', 'a10', '0', 'NCAPS', 'ê'], - ['K_I', 'a11', '0', 'NCAPS', 'î'], - ['K_O', 'a13', '0', 'NCAPS', 'ô'], - ['K_U', 'a14', '0', 'NCAPS', 'û'], - ['K_E', 'a2', '1', 'NCAPS SHIFT', 'Ê'], - ['K_E', 'a2', '1', 'SHIFT CAPS', 'Ê'], - ['K_E', 'a2', '2', 'CAPS', 'Ê'], - ['K_I', 'a3', '1', 'NCAPS SHIFT', 'Î'], - ['K_I', 'a3', '1', 'SHIFT CAPS', 'Î'], - ['K_I', 'a3', '2', 'CAPS', 'Î'], - ['K_O', 'a5', '1', 'NCAPS SHIFT', 'Ô'], - ['K_O', 'a5', '1', 'SHIFT CAPS', 'Ô'], - ['K_O', 'a5', '2', 'CAPS', 'Ô'], - ['K_U', 'a6', '1', 'NCAPS SHIFT', 'Û'], - ['K_U', 'a6', '1', 'SHIFT CAPS', 'Û'], - ['K_U', 'a6', '2', 'CAPS', 'Û'], - ['K_A', 'a9', '0', 'NCAPS', 'â'] - ]; - - [[b1_keycode_arr, b1_modifierKey_arr], - [[['49', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', 'NCAPS', 'ˆ']]], - [[['49', 'K_SPACE', 'a0', '0', '']], [['K_SPACE', 'a0', '0', 'NCAPS', '']]], - [[['49', 'K_SPACE', 'a0', '', 'ˆ']], [['K_SPACE', 'a0', '', 'NCAPS', 'ˆ']]], - [[['49', 'K_SPACE', '', '0', 'ˆ']], [['K_SPACE', '', '0', 'NCAPS', 'ˆ']]], - [[['49', '', 'a0', '0', 'ˆ']], [['', 'a0', '0', 'NCAPS', 'ˆ']]], - [[['', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', 'NCAPS', 'ˆ']]], - [[['', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', 'NCAPS', 'ˆ']]], - [[['', '', '', '', '']], [['', '', '', 'NCAPS', '']]], - */ const b1_keycode_arr = [ ['49', 'K_SPACE', 'A_0', '0', 'ˆ'], @@ -570,12 +484,6 @@ describe('KeylayoutToKmnConverter', function () { }); }); - /* Italian: [[[['49', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', '', 'ˆ']]], - [[['49', 'K_SPACE', 'a0', '0', '']], [['K_SPACE', 'a0', '0', '', '']]], - [[['', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', '', 'ˆ']]], - [[['', '', '', '', '']], [['', '', '', '', '']]], - ].forEach(function (values) { */ - [[[['49', 'K_SPACE', 'A_0', '0', 'ˆ']], [['K_SPACE', 'A_0', '0', '', 'ˆ']]], [[['49', 'K_SPACE', 'A_0', '0', '']], [['K_SPACE', 'A_0', '0', '', '']]], [[['', 'K_SPACE', 'A_0', '0', 'ˆ']], [['K_SPACE', 'A_0', '0', '', 'ˆ']]], @@ -607,35 +515,9 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionStateOutput_array__From__ActionState ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); - /* - Italian:[['1', [ - ['a0', '1', 'ˆ'], - ['a1', '1', 'Â'], - ['a10', '1', 'ê'], - ['a11', '1', 'î'], - ['a13', '1', 'ô'], - ['a14', '1', 'û'], - ['a2', '1', 'Ê'], - ['a3', '1', 'Î'], - ['a5', '1', 'Ô'], - ['a6', '1', 'Û'], - ['a9', '1', 'â']],], - ['2', [ - ['a0', '2', '`'], - ['a1', '2', 'À'], - ['a10', '2', 'è'], - ['a11', '2', 'ì'], - ['a13', '2', 'ò'], - ['a14', '2', 'ù'], - ['a2', '2', 'È'], - ['a3', '2', 'Ì'], - ['a5', '2', 'Ò'], - ['a6', '2', 'Ù'], - ['a9', '2', 'à']],], - */ [['1', [ ['A_0', '1', 'ˆ'], ['A_1', '1', 'Â'], @@ -679,29 +561,9 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); - /* Italian: [ - ['a1', 'A', true, [ - ['a1', 'A', 'a1', '1', 'K_A', 'NCAPS SHIFT'], - ['a1', 'A', 'a1', '1', 'K_A', 'SHIFT CAPS'], - ['a1', 'A', 'a1', '2', 'K_A', 'CAPS']] - ], - ['a1', 'A', false, [ - ['a1', 'A', 'a1', '1', 'K_A', 'SHIFT'], - ['a1', 'A', 'a1', '1', 'K_A', 'SHIFT CAPS'], - ['a1', 'A', 'a1', '2', 'K_A', 'CAPS']] - ], - ['a9', 'a', true, [['a9', 'a', 'a9', '0', 'K_A', 'NCAPS']]], - ['a9', 'a', false, [['a9', 'a', 'a9', '0', 'K_A', '']]], - ['a9', 'a', , [['a9', 'a', 'a9', '0', 'K_A', '']]], - ['a9', '', true, [['a9', '', 'a9', '0', 'K_A', 'NCAPS']]], - ['a9', '', false, [['a9', '', 'a9', '0', 'K_A', '']]], - ['', 'a', true, []], - ['', 'a', false, []], - ['', '', , []], - */ [ ['A_1', 'A', true, [ @@ -737,47 +599,9 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyActionOutput_array__From__ActionStateOutput_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); - /* Italian: const b6_actionId_arr = [ - ['a0', '1', 'ˆ'], - ['a1', '1', 'Â'], - ['a10', '1', 'ê'], - ['a11', '1', 'î'], - ['a13', '1', 'ô'], - ['a14', '1', 'û'], - ['a2', '1', 'Ê'], - ['a3', '1', 'Î'], - ['a5', '1', 'Ô'], - ['a6', '1', 'Û'], - ['a9', '1', 'â'] - ]; - const b1_keycode_arr = [ - ['49', 'K_SPACE', 'a0', '0', 'ˆ'], - ['49', 'K_SPACE', 'a0', '1', 'ˆ'], - ['49', 'K_SPACE', 'a0', '2', 'ˆ'], - ['6', 'K_Z', 'a0', '4', 'ˆ'], - ['25', 'K_9', 'a0', '4', 'ˆ'], - ['43', 'K_COMMA', 'a0', '4', 'ˆ'], - ['49', 'K_SPACE', 'a0', '7', 'ˆ'], - ['0', 'K_A', 'a1', '1', 'Â'], - ['0', 'K_A', 'a1', '2', 'Â'], - ['14', 'K_E', 'a10', '0', 'ê'], - ['34', 'K_I', 'a11', '0', 'î'], - ['31', 'K_O', 'a13', '0', 'ô'], - ['32', 'K_U', 'a14', '0', 'û'], - ['14', 'K_E', 'a2', '1', 'Ê'], - ['14', 'K_E', 'a2', '2', 'Ê'], - ['34', 'K_I', 'a3', '1', 'Î'], - ['34', 'K_I', 'a3', '2', 'Î'], - ['31', 'K_O', 'a5', '1', 'Ô'], - ['31', 'K_O', 'a5', '2', 'Ô'], - ['32', 'K_U', 'a6', '1', 'Û'], - ['32', 'K_U', 'a6', '2', 'Û'], - ['0', 'K_A', 'a9', '0', 'â'] - ]; - */ const b6_actionId_arr = [ ['A_0', '1', 'ˆ'], ['A_1', '1', 'Â'], @@ -792,8 +616,6 @@ describe('KeylayoutToKmnConverter', function () { ['A_9', '1', 'â'] ]; const b1_keycode_arr = [ - - ['49', 'K_SPACE', 'A_0', '0', 'ˆ'], ['49', 'K_SPACE', 'A_0', '1', 'ˆ'], ['49', 'K_SPACE', 'A_0', '2', 'ˆ'], @@ -827,27 +649,6 @@ describe('KeylayoutToKmnConverter', function () { }); }); - //----------------- - /* Italian: const oneEntryResult = [ - ['49', 'K_SPACE', 'a0', '0', 'ˆ'], - ['49', 'K_SPACE', 'a0', '1', 'ˆ'], - ['49', 'K_SPACE', 'a0', '2', 'ˆ'], - ['6', 'K_Z', 'a0', '4', 'ˆ'], - ['25', 'K_9', 'a0', '4', 'ˆ'], - ['43', 'K_COMMA', 'a0', '4', 'ˆ'], - ['49', 'K_SPACE', 'a0', '7', 'ˆ'] - ]; - const oneEntryResultNoOutput = [ - ['49', 'K_SPACE', 'a0', '0', ''], - ['49', 'K_SPACE', 'a0', '1', ''], - ['49', 'K_SPACE', 'a0', '2', ''], - ['6', 'K_Z', 'a0', '4', ''], - ['25', 'K_9', 'a0', '4', ''], - ['43', 'K_COMMA', 'a0', '4', ''], - ['49', 'K_SPACE', 'a0', '7', ''] - ] ; - */ - const oneEntryResult = [ ['49', 'K_SPACE', 'A_0', '0', 'ˆ'], ['49', 'K_SPACE', 'A_0', '1', 'ˆ'], @@ -877,7 +678,6 @@ describe('KeylayoutToKmnConverter', function () { }); }); - //------------------------------------------------------------------------------------- [[[['', '1', 'ˆ']], []], [[['', '', '']], []], [[[' ', ' ', '']], []], @@ -888,7 +688,6 @@ describe('KeylayoutToKmnConverter', function () { }); }); - //------------------------------------------------------------------------------------- [[[], []], [undefined, []], [null, []], diff --git a/developer/src/kmc-convert/test/kmn-file-reader.tests.ts b/developer/src/kmc-convert/test/kmn-file-reader.tests.ts index c6bdcca108..42a626ccec 100644 --- a/developer/src/kmc-convert/test/kmn-file-reader.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-reader.tests.ts @@ -12,8 +12,6 @@ import { assert } from 'chai'; import { compilerTestCallbacks, makePathToFixture } from './helpers/index.js'; import { KeylayoutFileReader } from '../src/keylayout-to-kmn/keylayout-file-reader.js'; -//----------------------------------------------------------------------------------------------------------------------- - describe('KeylayoutFileReader', function () { before(function () { @@ -25,7 +23,7 @@ describe('KeylayoutFileReader', function () { const sut_r = new KeylayoutFileReader(compilerTestCallbacks); it('read() should return filled array on correct input', async function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const result = sut_r.read(inputFilename); assert.isNotEmpty(result); }); @@ -46,7 +44,7 @@ describe('KeylayoutFileReader', function () { }); it('read() should return empty array on unavailable file name', async function () { - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const result = sut_r.read(inputFilename_unavailable); assert.isNull(result); }); diff --git a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts index 17c810ed1a..ad350f967f 100644 --- a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts @@ -23,15 +23,15 @@ describe('KmnFileWriter', function () { }); describe("write() ", function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); const read = sut_r.read(inputFilename); - const converted = sut.convert_bound.convert(read, '/Test.keylayout'.replace(/\.keylayout$/, '.kmn')); + const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -49,7 +49,7 @@ describe('KmnFileWriter', function () { }); describe("writeToString() ", function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -72,8 +72,7 @@ describe('KmnFileWriter', function () { + "\n"; // empty convert_object from unavailable file name - //const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); - const inputFilename_unavailable = '/X.keylayout'; + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -89,8 +88,7 @@ describe('KmnFileWriter', function () { }); describe("writeToUint8Array() ", function () { - //const inputFilename = makePathToFixture('../data/Test.keylayout'); - const inputFilename = '/Test.keylayout'; + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -115,7 +113,7 @@ describe('KmnFileWriter', function () { // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); it('writeToUint8Array() should return header in case of missing inputfile', async function () { @@ -130,7 +128,7 @@ describe('KmnFileWriter', function () { }); describe("writeData_Rules() ", function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -138,7 +136,7 @@ describe('KmnFileWriter', function () { const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -158,19 +156,19 @@ describe('KmnFileWriter', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); - const inputFilename = makePathToFixture('../data/Test.keylayout'); + const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); // empty convert_object from empty filename const inputFilename_empty = makePathToFixture(''); const read_empty = sut_r.read(inputFilename_empty); - const converted_empty = sut.convert_bound.convert(read_empty, inputFilename_empty.replace(/\.keylayout$/, '.kmn')); + const converted_empty = sut.convert_bound.convert(read_empty, inputFilename_empty); const out_expected_first: string = "c ..................................................................................................................\n" From 4ddc7268a095ecbe162358fdbe968c9c3d8fe6fc Mon Sep 17 00:00:00 2001 From: Sabine Date: Wed, 9 Jul 2025 15:16:50 +0200 Subject: [PATCH 09/12] feat(developer): change path in makePathToFixture --- .../test/keylayout-to-kmn-converter.tests.ts | 40 +++++++++---------- .../kmc-convert/test/kmn-file-reader.tests.ts | 4 +- .../kmc-convert/test/kmn-file-writer.tests.ts | 20 +++++----- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts index c37a9e8e8c..a673c4c9e7 100644 --- a/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts +++ b/developer/src/kmc-convert/test/keylayout-to-kmn-converter.tests.ts @@ -53,7 +53,7 @@ describe('KeylayoutToKmnConverter', function () { }); it('run() should throw on unavailable input file name and null output file name', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Unavailable.keylayout'); + const inputFilename = makePathToFixture('../data/Unavailable.keylayout'); const result = sut.run(inputFilename, null); assert.isNotNull(result); assert.equal(compilerTestCallbacks.messages.length, 2); @@ -61,24 +61,24 @@ describe('KeylayoutToKmnConverter', function () { }); it('run() should return on correct input file name and empty output file name ', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, '')); }); it('run() should return on correct input file name and null output file name', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, null)); }); it('run() should return on correct input file name and given output file name ', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); - const outputFilename = makePathToFixture('../' + 'data' + '/OutputName.kmn'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); + const outputFilename = makePathToFixture('../data/OutputName.kmn'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, outputFilename)); }); it('run() should throw on incorrect input file extention and output file extention', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test_command.A'); - const outputFilename = makePathToFixture('../' + 'data' + '/data/OutputXName.B'); + const inputFilename = makePathToFixture('../data/Test_command.A'); + const outputFilename = makePathToFixture('../data/data/OutputXName.B'); const result = sut.run(inputFilename, outputFilename); assert.isNotNull(result); assert.equal(compilerTestCallbacks.messages.length, 2); @@ -86,8 +86,8 @@ describe('KeylayoutToKmnConverter', function () { }); it('run() return on correct input file extention and unsupperted output file extention', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); - const outputFilename = makePathToFixture('../' + 'data' + '/OutputXName.B'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); + const outputFilename = makePathToFixture('../data/OutputXName.B'); await NodeAssert.doesNotReject(async () => sut.run(inputFilename, outputFilename)); }); }); @@ -95,12 +95,12 @@ describe('KeylayoutToKmnConverter', function () { describe('convert() ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -256,7 +256,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_Modifier_array__From__KeyModifier_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); @@ -291,7 +291,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyModifier_array__From__ActionID ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); [ @@ -320,7 +320,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionID__From__ActionNext ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); [ @@ -347,7 +347,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionIndex__From__ActionId ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); [ @@ -372,7 +372,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_Output__From__ActionId_None ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); [ @@ -403,7 +403,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const b1_keycode_arr = [ @@ -515,7 +515,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionStateOutput_array__From__ActionState ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); [['1', [ @@ -561,7 +561,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); @@ -599,7 +599,7 @@ describe('KeylayoutToKmnConverter', function () { describe('get_KeyActionOutput_array__From__ActionStateOutput_array ', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const b6_actionId_arr = [ diff --git a/developer/src/kmc-convert/test/kmn-file-reader.tests.ts b/developer/src/kmc-convert/test/kmn-file-reader.tests.ts index 42a626ccec..61be6c667a 100644 --- a/developer/src/kmc-convert/test/kmn-file-reader.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-reader.tests.ts @@ -23,7 +23,7 @@ describe('KeylayoutFileReader', function () { const sut_r = new KeylayoutFileReader(compilerTestCallbacks); it('read() should return filled array on correct input', async function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const result = sut_r.read(inputFilename); assert.isNotEmpty(result); }); @@ -44,7 +44,7 @@ describe('KeylayoutFileReader', function () { }); it('read() should return empty array on unavailable file name', async function () { - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const result = sut_r.read(inputFilename_unavailable); assert.isNull(result); }); diff --git a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts index ad350f967f..9afaae5b7b 100644 --- a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts @@ -23,7 +23,7 @@ describe('KmnFileWriter', function () { }); describe("write() ", function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -31,7 +31,7 @@ describe('KmnFileWriter', function () { const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -49,7 +49,7 @@ describe('KmnFileWriter', function () { }); describe("writeToString() ", function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -72,7 +72,7 @@ describe('KmnFileWriter', function () { + "\n"; // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -88,7 +88,7 @@ describe('KmnFileWriter', function () { }); describe("writeToUint8Array() ", function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -113,7 +113,7 @@ describe('KmnFileWriter', function () { // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); it('writeToUint8Array() should return header in case of missing inputfile', async function () { @@ -128,7 +128,7 @@ describe('KmnFileWriter', function () { }); describe("writeData_Rules() ", function () { - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); @@ -136,7 +136,7 @@ describe('KmnFileWriter', function () { const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); @@ -156,12 +156,12 @@ describe('KmnFileWriter', function () { const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); - const inputFilename = makePathToFixture('../' + 'data' + '/Test.keylayout'); + const inputFilename = makePathToFixture('../data/Test.keylayout'); const read = sut_r.read(inputFilename); const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../' + 'data' + '/X.keylayout'); + const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); From e429923df6b90373449f100842f2110844a03434 Mon Sep 17 00:00:00 2001 From: Sabine Date: Fri, 11 Jul 2025 13:01:17 +0200 Subject: [PATCH 10/12] feat(developer): remove comments, rename write()->writeToFile(), writeToUint8Array()->write() --- .../src/converter-class-factory.ts | 3 - developer/src/kmc-convert/src/converter.ts | 10 --- .../keylayout-to-kmn-converter.ts | 10 +-- .../src/keylayout-to-kmn/kmn-file-writer.ts | 21 +------ .../kmc-convert/test/kmn-file-writer.tests.ts | 61 ++++--------------- 5 files changed, 16 insertions(+), 89 deletions(-) diff --git a/developer/src/kmc-convert/src/converter-class-factory.ts b/developer/src/kmc-convert/src/converter-class-factory.ts index a947626df7..2176b3df00 100644 --- a/developer/src/kmc-convert/src/converter-class-factory.ts +++ b/developer/src/kmc-convert/src/converter-class-factory.ts @@ -3,9 +3,6 @@ * * Lists all the available converters and finds matching converter */ -// _S2 const converters later holds several converters - each specified in diff module folder e.g. /keylayout-to-kmn,... -// _S2 this class will be used in each converter module -// _S2 class method returns/finds the right converter import { KeylayoutToKmnConverter } from './keylayout-to-kmn/keylayout-to-kmn-converter.js'; const converters = [ diff --git a/developer/src/kmc-convert/src/converter.ts b/developer/src/kmc-convert/src/converter.ts index f36530fcf8..8335c052db 100644 --- a/developer/src/kmc-convert/src/converter.ts +++ b/developer/src/kmc-convert/src/converter.ts @@ -29,9 +29,6 @@ export interface ConverterResult extends KeymanCompilerResult { * relies on callbacks for all external IO. */ -// _S2 this is Base class of all converters -// _S2 method init: uses Interface CompilerCallbacks( loadfile,...) -// _S2 method run: uses Interface CompilerCallbacks( loadfile,...) export class Converter implements KeymanCompiler { private callbacks: CompilerCallbacks; private options: CompilerOptions; @@ -43,7 +40,6 @@ export class Converter implements KeymanCompiler { * @param options - Compiler options * @returns false if initialization fails */ - // _S2 fills interface this.callbacks with array (holding our data), filesize ect async init(callbacks: CompilerCallbacks, options: CompilerOptions): Promise { this.options = { ...options }; this.callbacks = callbacks; @@ -61,12 +57,6 @@ export class Converter implements KeymanCompiler { * {@link Converter.write}. * @returns Source artifacts on success, null on failure. */ - // _S2 check for ( file available,...) then - // _S2 finds converter e.g.keylayout->kmn ( uses converter-class-factory) - // _S2 factory uses/instanciates child class ( ~ in C++ virtual function in base class <-> use fun of derived class) - // _S2 loads file - // _S2 creates a new (derived) converter (-object) - // _S2 runs conversion for this object ( run-method of this converter of keylayout-to-kmn-tonverter.ts ) async run(inputFilename: string, outputFilename?: string): Promise { const converterOptions: CompilerOptions = { ...defaultCompilerOptions, diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index fdd14406d8..6ce2911884 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -85,22 +85,21 @@ export class KeylayoutToKmnConverter { const kmnFileWriter = new KmnFileWriter(this.callbacks, this.options); - // _S2 still write to file - may be removed later - const out_text_ok: boolean = kmnFileWriter.write(outArray); + // _S2 still write to file - will be removed later + const out_text_ok: boolean = kmnFileWriter.writeToFile(outArray); if (!out_text_ok) { this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ outputFilename })); return null; } // write to object/ConverterToKmnResult - const out_Uint8: Uint8Array = kmnFileWriter.writeToUint8Array(outArray); + const out_Uint8: Uint8Array = kmnFileWriter.write(outArray); const Result_toBeReturned: ConverterToKmnResult = { artifacts: { kmn: { data: out_Uint8, filename: outputFilename } } }; - // _S2 does this still work? if (!out_Uint8) { this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({ outputFilename })); return null; @@ -131,9 +130,6 @@ export class KeylayoutToKmnConverter { data_object.arrayOf_Modifiers = modifierBehavior; // ukelele uses behaviours e.g. 18 modifiersCombinations in 8 KeyMapSelect(behaviors) data_object.arrayOf_Rules = rules; - // _S2 ToDo remove this console.log - console.log("RUN kmc convert - input file: ", data_object.keylayout_filename, " --> output file: ", data_object.kmn_filename); - // create an array of modifier combinations and store in data_object for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { const singleModifierSet: string[] = []; diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts index 5aeb4ecfd2..2c0daeab3a 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/kmn-file-writer.ts @@ -23,7 +23,7 @@ export class KmnFileWriter { * @param outputfilename the file that will be written; if no outputfilename is given an outputfilename will be created from data_ukelele.keylayout_filename * @return true if data has been written; false if not */ - public write(data_ukelele: convert_object): boolean { + public writeToFile(data_ukelele: convert_object): boolean { let data: string = "\n"; @@ -42,24 +42,7 @@ export class KmnFileWriter { } } - public writeToString(data_ukelele: convert_object): string { - let data: string = "\n"; - - // add top part of kmn file: STORES - data += this.writeData_Stores(data_ukelele); - - // add bottom part of kmn file: RULES - data += this.writeData_Rules(data_ukelele); - - try { - return data; - } catch (err) { - this.callbacks.reportMessage(ConverterMessages.Error_UnableToWrite({outputFilename: data_ukelele.kmn_filename})); - return null; - } - } - - public writeToUint8Array(data_ukelele: convert_object): Uint8Array { + public write(data_ukelele: convert_object): Uint8Array { let data: string = "\n"; // add top part of kmn file: STORES diff --git a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts index 9afaae5b7b..72113a17ae 100644 --- a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts @@ -22,7 +22,7 @@ describe('KmnFileWriter', function () { compilerTestCallbacks.clear(); }); - describe("write() ", function () { + describe("writeToFile()() ", function () { const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); @@ -35,59 +35,19 @@ describe('KmnFileWriter', function () { const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); - it('write() should return true (no error) if written', async function () { - - const result = sut_w.write(converted); + it('writeToFile()() should return true (no error) if written', async function () { + const result = sut_w.writeToFile(converted); assert.isTrue(result); }); - it('write() should return false if no inputfile', async function () { - const result = sut_w.write(converted_unavailable); + it('writeToFile()() should return false if no inputfile', async function () { + const result = sut_w.writeToFile(converted_unavailable); assert.isFalse(result); }); }); - describe("writeToString() ", function () { - const inputFilename = makePathToFixture('../data/Test.keylayout'); - const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); - const sut_r = new KeylayoutFileReader(compilerTestCallbacks); - const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); - const read = sut_r.read(inputFilename); - const converted = sut.convert_bound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); - - const out_expected_first: string = "c ..................................................................................................................\n" - + "c ..................................................................................................................\n" - + "c Keyman keyboard generated by kmn-convert version: " + KEYMAN_VERSION.VERSION + "\n" - + "c from Ukelele file: "; - - const out_expected_last: string = "\n" - + "c ..................................................................................................................\n" - + "c ..................................................................................................................\n" - + "\n" - + "store(&TARGETS) 'desktop'\n" - + "\n" - + "begin Unicode > use(main)\n\n" - + "group(main) using keys\n\n" - + "\n"; - - // empty convert_object from unavailable file name - const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); - const read_unavailable = sut_r.read(inputFilename_unavailable); - const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); - - it('writeToString() should return result', async function () { - const result = sut_w.writeToString(converted); - assert.isNotNull(result); - }); - - it('writeToString() should return header in case of missing inputfile', async function () { - const result = sut_w.writeToString(converted_unavailable); - assert.equal(result, ("\n" + out_expected_first + out_expected_last)); - }); - }); - - describe("writeToUint8Array() ", function () { + describe("write()() ", function () { const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); @@ -116,13 +76,14 @@ describe('KmnFileWriter', function () { const inputFilename_unavailable = makePathToFixture('../data/X.keylayout'); const read_unavailable = sut_r.read(inputFilename_unavailable); const converted_unavailable = sut.convert_bound.convert(read_unavailable, inputFilename_unavailable.replace(/\.keylayout$/, '.kmn')); - it('writeToUint8Array() should return header in case of missing inputfile', async function () { - const result = sut_w.writeToUint8Array(converted_unavailable); + + it('write()() should return header in case of missing inputfile', async function () { + const result = sut_w.write(converted_unavailable); assert.equal(new TextDecoder().decode(result), ("\n" + out_expected_first + out_expected_last)); }); - it('writeToUint8Array() should return result', async function () { - const result = sut_w.writeToUint8Array(converted); + it('write()() should return result', async function () { + const result = sut_w.write(converted); assert.isNotNull(result); }); }); From ff9b70ba0ab6b0b9c2beb924d304b69f036fe834 Mon Sep 17 00:00:00 2001 From: Sabine Date: Wed, 13 Aug 2025 12:46:04 +0200 Subject: [PATCH 11/12] feat(developer): kmc-convert nits from review: typo and Layout of ErrorMessages --- .../src/kmc-convert/src/converter-messages.ts | 24 ++++++++++++++----- .../kmc-convert/test/kmn-file-writer.tests.ts | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/developer/src/kmc-convert/src/converter-messages.ts b/developer/src/kmc-convert/src/converter-messages.ts index 42b3bb825e..f717f4dfde 100644 --- a/developer/src/kmc-convert/src/converter-messages.ts +++ b/developer/src/kmc-convert/src/converter-messages.ts @@ -23,26 +23,38 @@ export class ConverterMessages { static ERROR_NoConverterFound = SevError | 0x0002; static Error_NoConverterFound = (o: { inputFilename: string, outputFilename: string; }) => m( - this.ERROR_NoConverterFound, `No converter is available that can convert from '${def(o.inputFilename)}' to '${def(o.outputFilename)}'.`); + this.ERROR_NoConverterFound, + `No converter is available that can convert from '${def(o.inputFilename)}' to '${def(o.outputFilename)}'.`, + ); static ERROR_FileNotFound = SevError | 0x0003; static Error_FileNotFound = (o: { inputFilename: string; }) => m( - this.ERROR_FileNotFound, `Input filename '${def(o.inputFilename)} ' does not exist or could not be loaded.`); + this.ERROR_FileNotFound, + `Input filename '${def(o.inputFilename)} ' does not exist or could not be loaded.`, + ); static ERROR_UnableToRead = SevError | 0x0004; static Error_UnableToRead = (o: { inputFilename: string; }) => m( - this.ERROR_UnableToRead, `Input file '${def(o.inputFilename)} ' could not be read.`); + this.ERROR_UnableToRead, + `Input file '${def(o.inputFilename)} ' could not be read.`, + ); static ERROR_UnableToConvert = SevError | 0x0005; static Error_UnableToConvert = (o: { inputFilename: string; }) => m( - this.ERROR_UnableToConvert, `Input file '${def(o.inputFilename)} ' could not be converted.`); + this.ERROR_UnableToConvert, + `Input file '${def(o.inputFilename)} ' could not be converted.`, + ); static ERROR_UnableToWrite = SevError | 0x0006; static Error_UnableToWrite = (o: { outputFilename: string; }) => m( - this.ERROR_UnableToWrite, `Output file for '${def(o.outputFilename)} ' could not be written.`); + this.ERROR_UnableToWrite, + `Output file for '${def(o.outputFilename)} ' could not be written.`, + ); static ERROR_UnsupportedCharactersDetected = SevError | 0x0007; static Error_UnsupportedCharactersDetected = (o: { inputFilename: string, keymap_index: string, key: string, output: string; }) => m( - this.ERROR_UnsupportedCharactersDetected, `Input file ${def(o.inputFilename)} contains unsupported character ('${def(o.output)}') on key (${def(o.key)}) at keyMap index ${def(o.keymap_index)}`); + this.ERROR_UnsupportedCharactersDetected, + `Input file ${def(o.inputFilename)} contains unsupported character ('${def(o.output)}') on key ( ${def(o.key)}) at keyMap index ${def(o.keymap_index)}`, + ); } diff --git a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts index 72113a17ae..64dc832448 100644 --- a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts @@ -22,7 +22,7 @@ describe('KmnFileWriter', function () { compilerTestCallbacks.clear(); }); - describe("writeToFile()() ", function () { + describe("writeToFile() ", function () { const inputFilename = makePathToFixture('../data/Test.keylayout'); const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); const sut_r = new KeylayoutFileReader(compilerTestCallbacks); From d8be6966f5c63beb9c2b0928a7632ae2e64cde57 Mon Sep 17 00:00:00 2001 From: Sabine Date: Tue, 19 Aug 2025 17:35:03 +0200 Subject: [PATCH 12/12] feat(developer): import KeylayoutXMLSourceFile --- developer/src/kmc-convert/src/converter-messages.ts | 4 ++++ .../src/keylayout-to-kmn/keylayout-to-kmn-converter.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-convert/src/converter-messages.ts b/developer/src/kmc-convert/src/converter-messages.ts index 56045b4272..115315cc03 100644 --- a/developer/src/kmc-convert/src/converter-messages.ts +++ b/developer/src/kmc-convert/src/converter-messages.ts @@ -57,4 +57,8 @@ export class ConverterMessages { this.ERROR_UnsupportedCharactersDetected, `Input file ${def(o.inputFilename)} contains unsupported character ('${def(o.output)}') on key ( ${def(o.key)}) at keyMap index ${def(o.keymap_index)}`, ); + + static ERROR_InvalidFile = SevError | 0x0008; + static Error_InvalidFile = (o: { errorText: string; }) => m( + this.ERROR_InvalidFile, `The source file has an invalid structure: ${def(o.errorText)}`); } diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 92bdb6a93d..4e18cbc17b 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -12,7 +12,9 @@ import { KmnFileWriter } from './kmn-file-writer.js'; import { KeylayoutFileReader } from './keylayout-file-reader.js'; import { ConverterMessages } from '../converter-messages.js'; import { ConverterArtifacts } from "../converter-artifacts.js"; -import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; +import { ConverterToKmnArtifacts } from "../converter-artifacts.js" +import { KeylayoutXMLSourceFile } from '../../../common/web/utils/src/types/keylayout/keylayout-xml.js'; + export interface ConverterResult extends KeymanCompilerResult { /**