From 160f92a858d0c4027eb2d89cee17dad94bc44da8 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 4 Jun 2026 11:20:45 +0200 Subject: [PATCH] feat(developer): work on comments of PR review --- .../src/kmc-convert/src/converter-messages.ts | 2 +- .../keylayout-to-kmn/keylayout-file-reader.ts | 12 +-- .../keylayout-to-kmn-converter.ts | 4 +- .../src/keylayout-to-kmn/kmn-file-writer.ts | 55 +++++------- .../test/keylayout-file-reader.tests.ts | 16 ++-- .../test/keylayout-to-kmn-converter.tests.ts | 83 +++++++++---------- .../kmc-convert/test/kmn-file-writer.tests.ts | 69 ++++++++------- 7 files changed, 117 insertions(+), 124 deletions(-) diff --git a/developer/src/kmc-convert/src/converter-messages.ts b/developer/src/kmc-convert/src/converter-messages.ts index 7c8b0d3a3e..b234c1c073 100644 --- a/developer/src/kmc-convert/src/converter-messages.ts +++ b/developer/src/kmc-convert/src/converter-messages.ts @@ -20,7 +20,7 @@ export class ConverterMessages { static ERROR_FileNotFound = SevError | 0x0003; static Error_FileNotFound = (o: { inputFilename: string | null; }) => m( this.ERROR_FileNotFound, - `Input filename '${def(o.inputFilename)}' does not exist or could not be loaded.` + `Input filename '${def(o?.inputFilename)}' does not exist or could not be loaded.` ); static ERROR_InvalidFile = SevError | 0x0004; diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-file-reader.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-file-reader.ts index 099193e32b..d35e32de56 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-file-reader.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-file-reader.ts @@ -18,9 +18,9 @@ export class KeylayoutFileReader { constructor(private callbacks: CompilerCallbacks /*,private options: CompilerOptions*/) { }; /** - * @brief helper function to check if a specific keyMap index exists in a keyMapSet - * neccessary because the amount of must correspond to - * the amount of + * @brief Helper function to check if a specific keyMap index exists in a keyMapSet. + * This is neccessary because the amount of must correspond to + * the amount of . * @param jsonObj the read keylayout data to be checked * @param keyMapSelect the keyMapSelect element to find in keyMapSet * @return true if the keyMapSet element is found, false if not @@ -37,9 +37,9 @@ export class KeylayoutFileReader { } /** - * @brief helper function to check if a specific keyMapSelect index exists in a modifierMap - * neccessary because the amount of must correspond to - * the amount of + * @brief Helper function to check if a specific keyMapSelect index exists in a modifierMap. + * This is neccessary because the amount of must correspond to + * the amount of . * @param jsonObj the read keylayout data to be checked * @param keyMap the keyMap element to find in modifierMap * @return true if the keyMap element is found, false if not 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 c91905b290..6e85da7d74 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 @@ -52,7 +52,7 @@ export interface KeylayoutFileData { key?: string; behavior: string; modifier?: string; - outchar?: string | undefined; + outchar?: string; }; /** @@ -492,7 +492,7 @@ export class KeylayoutToKmnConverter { } else { this.callbacks.reportMessage(ConverterMessages.Error_UnsupportedCharactersDetected({ keymapIndex: jsonObj.keyboard.keyMapSet[0].keyMap[i]['index'], - output: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['output'] ?? '' as string, + output: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['output'] ?? '', key: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['code'], KeyName: this.mapUkeleleKeycodeToVK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['code'])) })); 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 68cc0be382..e66db3623f 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 @@ -149,7 +149,6 @@ export class KmnFileWriter { // use of Unicode Character vs Unicode Codepoint; // If it`s a ctrl character we print out the Unicode Codepoint else we print out the Unicode Character - let versionOutputCharacter; const warnText = this.reviewRules(uniqueDataRules, k); const outputCharacter = new TextDecoder().decode(uniqueDataRules[k].output); @@ -157,16 +156,9 @@ export class KmnFileWriter { // const outputUnicodeCharacter = util.convertToUnicodeCharacter(outputCharacter); // const outputUnicodeCodePoint = util.convertToUnicodeCodePoint(outputCharacter); - // in case writeCharacterOrUnicode() returns null, the fallback is empty strings for characterMessage.character - // and characterMessage.message. Then versionOutputCharacter could be "" and would be written into the kmn file - // as ... > '', producing an invalid kmn rule. - if ((outputCharacter !== undefined) && (outputCharacter !== "")) { - const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); - - versionOutputCharacter = characterMessage?.character ?? ""; - warnText[2] = characterMessage?.message ?? ""; - - } + const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); + const versionOutputCharacter = characterMessage.character; + warnText[2] = characterMessage.message; // add a warning in front of rules in case unavailable modifiers or ambiguous rules are used // if warning contains duplicate rules we do not write out the entire rule @@ -219,7 +211,6 @@ export class KmnFileWriter { // use of Unicode Character vs Unicode Codepoint; // If it`s a ctrl character we print out the Unicode Codepoint else we print out the Unicode Character - let versionOutputCharacter; const warnText = this.reviewRules(uniqueDataRules, k); const outputCharacter = new TextDecoder().decode(uniqueDataRules[k].output); @@ -227,14 +218,9 @@ export class KmnFileWriter { // const outputUnicodeCharacter = util.convertToUnicodeCharacter(outputCharacter); // const outputUnicodeCodePoint = util.convertToUnicodeCodePoint(outputCharacter); - // in case writeCharacterOrUnicode() returns null, the fallback is empty strings for characterMessage.character - // and characterMessage.message. Then versionOutputCharacter could be "" and would be written into the kmn file - // as ... > '', producing an invalid kmn rule. - if ((outputCharacter !== undefined) && (outputCharacter !== "")) { - const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); - versionOutputCharacter = characterMessage?.character ?? ""; - warnText[2] = characterMessage?.message ?? ""; - } + const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); + const versionOutputCharacter = characterMessage.character; + warnText[2] = characterMessage.message; // add a warning in front of rules in case unavailable modifiers or ambiguous rules are used // if warning contains duplicate rules we do not write out the entire rule @@ -309,20 +295,14 @@ export class KmnFileWriter { // use of Unicode Character vs Unicode Codepoint; // If it`s a ctrl character we print out the Unicode Codepoint else we print out the Unicode Character - let versionOutputCharacter; const warnText = this.reviewRules(uniqueDataRules, k); const outputCharacter = new TextDecoder().decode(uniqueDataRules[k].output); // TODO-kmc-convert: after merge of PR 14569 use functions from util instead of the ones in this class - // in case writeCharacterOrUnicode() returns null, the fallback is empty strings for characterMessage.character - // and characterMessage.message. Then versionOutputCharacter could be "" and would be written into the kmn file - // as ... > '', producing an invalid kmn rule. - if ((outputCharacter !== undefined) && (outputCharacter !== "")) { - const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); - versionOutputCharacter = characterMessage?.character ?? ""; - warnText[2] = characterMessage?.message ?? ""; - } + const characterMessage = this.writeCharacterOrUnicode(outputCharacter, warnText[2]); + const versionOutputCharacter = characterMessage.character; + warnText[2] = characterMessage.message; // add a warning in front of rules in case unavailable modifiers or ambiguous rules are used // if warning contains duplicate rules we do not write out the entire rule @@ -1636,10 +1616,10 @@ export class KmnFileWriter { * a non-control character will be written as itself ( 'A', '1', '፩', '😎') * null in case of an empty string or null or undefined input */ - public writeCharacterOrUnicode(ctr: string, msg: string = ""): MessageCharacter | null { + public writeCharacterOrUnicode(ctr: string, msg: string = ""): MessageCharacter { if ((ctr === null) || (ctr === undefined) || (ctr.length === 0)) { - return null; + return { character: '', message: '' }; } let versionOutputCharacter; @@ -1653,8 +1633,14 @@ export class KmnFileWriter { const m_dec = /^&#([0-9]{1,7});$/.exec(ctr); // find the value of output character which may be specified in unicode, html hex or html dec format ( e.g. U+1234 -> 1234; ሴ -> 1234; ሴ -> 1234) - const ctr_val = ((m_uni || m_hex || m_dec) ? - m_uni ? parseInt(m_uni[1], 16) : m_hex ? parseInt(m_hex[1], 16) : m_dec ? parseInt(m_dec[1], 10) : KeylayoutToKmnConverter.MAX_CTRL_CHARACTER : KeylayoutToKmnConverter.MAX_CTRL_CHARACTER + const ctr_val = ( + m_uni + ? parseInt(m_uni[1], 16) + : m_hex + ? parseInt(m_hex[1], 16) + : m_dec + ? parseInt(m_dec[1], 10) + : KeylayoutToKmnConverter.MAX_CTRL_CHARACTER ); // for control characters in 'U+...', '&#x...' or '&#...' format as well as in "" format @@ -1693,8 +1679,7 @@ export class KmnFileWriter { */ public convertToUnicodeCharacter(inputString: string): string | undefined { - - // null, undefined will later be refused for conversion + // null, undefined will later be treated as '' in conversion if (inputString == null || inputString == undefined) { return undefined; } diff --git a/developer/src/kmc-convert/test/keylayout-file-reader.tests.ts b/developer/src/kmc-convert/test/keylayout-file-reader.tests.ts index a5c4bccb55..f9abe65d9c 100644 --- a/developer/src/kmc-convert/test/keylayout-file-reader.tests.ts +++ b/developer/src/kmc-convert/test/keylayout-file-reader.tests.ts @@ -157,7 +157,7 @@ describe('KeylayoutFileReader', function () { it(("findMapIndexinKeymap(keyMapSelect.mapIndex = '" + values[0] + "')").padEnd(40, " ") + "should return " + "'" + values[1] + "'", async function () { keyMapSelect.mapIndex = values[0] as string; const result = sutR.findMapIndexinKeymap(jsonO as Keylayout.KeylayoutXMLSourceFile, keyMapSelect); - assert.isTrue(result === values[1]); + assert.equal(result, values[1]); }); }); }); @@ -187,7 +187,7 @@ describe('KeylayoutFileReader', function () { it(("findIndexinKeymapSelect(keyMap.index = '" + values[0] + "')").padEnd(40, " ") + "should return " + "'" + values[1] + "'", async function () { keyMap.index = values[0] as string; const result = sutR.findIndexinKeymapSelect(jsonO as Keylayout.KeylayoutXMLSourceFile, keyMap); - assert.isTrue(result === values[1]); + assert.equal(result, values[1]); }); }); }); @@ -204,7 +204,7 @@ describe('KeylayoutFileReader', function () { it(("checkForCorrespondingElements in " + values[0]).padEnd(40, " ") + "should return " + "'" + values[1] + "'", async function () { const jsonO: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(makePathToFixture(values[0] as string))); const result = sutR.checkForCorrespondingElements(jsonO as Keylayout.KeylayoutXMLSourceFile); - assert.isTrue(result === values[1]); + assert.equal(result, values[1]); }); }); }); @@ -219,7 +219,7 @@ describe('KeylayoutFileReader', function () { const result: Keylayout.KeylayoutXMLSourceFile = sutR.read(binaryData); assert.isNotNull(result); - assert.isTrue(result.keyboard !== null); + assert.notEqual(result.keyboard, null); for (let i = 0; i < result.keyboard.layouts.length; i++) { assert.isTrue(result.keyboard.layouts[i].layout.length > 0); @@ -231,8 +231,8 @@ describe('KeylayoutFileReader', function () { for (let j = 0; j < result.keyboard.keyMapSet[i].keyMap.length; j++) { assert.isTrue(result.keyboard.keyMapSet[i].keyMap[j].key.length > 0); for (let k = 0; k < result.keyboard.keyMapSet[i].keyMap[j].key.length; k++) { - assert.isTrue(result.keyboard.keyMapSet[i].keyMap[j].key[k]['action'] !== null - || result.keyboard.keyMapSet[i].keyMap[j].key[k]['output'] !== null); + assert.isNotNull(result.keyboard.keyMapSet[i].keyMap[j].key[k]['action']); + assert.isNotNull(result.keyboard.keyMapSet[i].keyMap[j].key[k]['output']); } } } @@ -247,8 +247,8 @@ describe('KeylayoutFileReader', function () { for (let i = 0; i < result.keyboard.modifierMap.length; i++) { assert.isTrue(result.keyboard.modifierMap[i].keyMapSelect.length > 0); for (let j = 0; j < result.keyboard.keyMapSet.length; j++) { - assert.isTrue(result.keyboard.keyMapSet[j].keyMap.length - === result.keyboard.modifierMap[i].keyMapSelect.length); + assert.equal(result.keyboard.keyMapSet[j].keyMap.length, + result.keyboard.modifierMap[i].keyMapSelect.length); } } }); 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 b4443a6f9f..e7afbf3fc6 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 @@ -47,8 +47,8 @@ describe('KeylayoutToKmnConverter', function () { ['../data/Test_ExtraWarning.keylayout'], ].forEach(function (files) { it(files + " should give no errors ", async function () { - sut.run(makePathToFixture(files[0])); - assert.isTrue(compilerTestCallbacks.messages.length === 0); + await sut.run(makePathToFixture(files[0])); + assert.equal(compilerTestCallbacks.messages.length, 0); }); }); }); @@ -70,7 +70,7 @@ describe('KeylayoutToKmnConverter', function () { ['../data/Test_characters.keylayout'], ].forEach(function (files) { it(files + " should give an error ", async function () { - sut.run(makePathToFixture(files[0])); + await sut.run(makePathToFixture(files[0])); assert.isTrue(compilerTestCallbacks.messages.length > 0); }); }); @@ -83,8 +83,8 @@ describe('KeylayoutToKmnConverter', function () { ['../data/Test_undefinedAction.keylayout'], ].forEach(function (files) { it(files + " should give Error: undefined action detected", async function () { - sut.run(makePathToFixture(files[0])); - assert.isTrue(compilerTestCallbacks.messages.length === 1); + await sut.run(makePathToFixture(files[0])); + assert.equal(compilerTestCallbacks.messages.length, 1); assert.equal(compilerTestCallbacks.messages[0].code, 5292040); }); }); @@ -95,10 +95,9 @@ 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 result = sut.run(inputFilename, undefined); - assert.isNotNull(result); + const result = await sut.run(inputFilename, undefined); + assert.isNull(result); assert.equal(compilerTestCallbacks.messages.length, 2); - //assert.deepEqual(compilerTestCallbacks.messages[0], ConverterMessages.Error_UnableToRead()); assert.isTrue(compilerTestCallbacks.hasMessage(ConverterMessages.ERROR_UnableToRead)); assert.equal(compilerTestCallbacks.messages[1].code, 5292037); }); @@ -115,43 +114,44 @@ describe('KeylayoutToKmnConverter', function () { ['../data/OutputXName.bb'], ].forEach(function (files) { it(infile + " should run ", async function () { - await NodeAssert.doesNotReject(async () => sut.run(makePathToFixture(infile), makePathToFixture(files[0])?? undefined)); + await NodeAssert.doesNotReject(async () => await sut.run(makePathToFixture(infile), makePathToFixture(files[0]) ?? undefined)); assert.equal(compilerTestCallbacks.messages.length, 0); }); }); }); describe('convert() ', function () { - const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); - const sutR = new KeylayoutFileReader(compilerTestCallbacks); - // ProcessedData from usable file - const inputFilename = makePathToFixture('../data/Test.keylayout'); - const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename)); + let sut: KeylayoutToKmnConverter; + let sutR: KeylayoutFileReader; - const converted = sut.unitTestEndpoints.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn')); - - - // ProcessedData from unavailable file - const inputFilenameUnavailable = makePathToFixture('../data/X.keylayout'); - const readUnavailable = sutR.read(compilerTestCallbacks.loadFile(inputFilenameUnavailable)); - - const convertedUnavailable = sut.unitTestEndpoints.convert(readUnavailable as KeylayoutXMLSourceFile, inputFilenameUnavailable.replace(/\.keylayout$/, '.kmn')); - - // ProcessedData from empty file - const inputFilenameEmpty = makePathToFixture(''); - const readEmpty = sutR.read(compilerTestCallbacks.loadFile(inputFilenameEmpty)); - const convertedEmpty = sut.unitTestEndpoints.convert(readEmpty as KeylayoutXMLSourceFile, inputFilenameEmpty); - - it('should return converted array on correct input', async function () { - assert.isTrue(converted?.rules.length !== 0); + beforeEach(function () { + sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions); + sutR = new KeylayoutFileReader(compilerTestCallbacks); }); + // ProcessedData from usable file + it('should return converted array on correct input', async function () { + const inputFilename = makePathToFixture('../data/Test.keylayout'); + const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename)); + const converted = sut.unitTestEndpoints.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn')); + assert.isNotNull(converted); + assert.notEqual(converted.rules.length, 0); + }); + + // ProcessedData from unavailable file it('should return null on empty name as input', async function () { + const inputFilenameUnavailable = makePathToFixture('../data/X.keylayout'); + const readUnavailable = sutR.read(compilerTestCallbacks.loadFile(inputFilenameUnavailable)); + const convertedUnavailable = sut.unitTestEndpoints.convert(readUnavailable as KeylayoutXMLSourceFile, inputFilenameUnavailable.replace(/\.keylayout$/, '.kmn')); assert.isNull(convertedUnavailable); }); + // ProcessedData from empty file it('should return null on empty input', async function () { + const inputFilenameEmpty = makePathToFixture(''); + const readEmpty = sutR.read(compilerTestCallbacks.loadFile(inputFilenameEmpty)); + const convertedEmpty = sut.unitTestEndpoints.convert(readEmpty as KeylayoutXMLSourceFile, inputFilenameEmpty); assert.isNull(convertedEmpty); }); @@ -281,7 +281,7 @@ describe('KeylayoutToKmnConverter', function () { ].forEach(function (values) { it(("checkIfCapsIsUsed(" + values[0] + ")").padEnd(40, " ") + "should return " + "'" + values[1] + "'", async function () { const result = sut.checkIfCapsIsUsed(values[0] as string[][]); - assert.isTrue(result === values[1]); + assert.equal(result, values[1]); }); }); }); @@ -308,7 +308,6 @@ describe('KeylayoutToKmnConverter', function () { it((values[1] !== null) ? ("getModifierArrayFromKeyModifierArray('" + JSON.stringify(values[0]) + "')").padEnd(68, " ") + " should return '" + JSON.stringify(values[1]) + "'" : ("getModifierArrayFromKeyModifierArray('" + JSON.stringify(values[0]) + "')").padEnd(68, " ") + " should return '" + "null" + "'", async function () { - const result = sut.getModifierArrayFromKeyModifierArray(converted?.modifiers as string[][], values[0] as unknown as KeylayoutFileData[]); assert.deepStrictEqual(JSON.stringify(result), JSON.stringify(values[1])); }); @@ -605,14 +604,13 @@ describe('KeylayoutToKmnConverter', function () { ['', 'a', false, []], ['', '', , []], ].forEach(function (values) { - if (converted) { - it((JSON.stringify(values[3]).length > 35) ? - ("getActionOutputbehaviorKeyModiFromActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return an array of objects' : - ("getActionOutputbehaviorKeyModiFromActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return ' + "'" + JSON.stringify(values[3]) + "'", async function () { - const result = sut.getActionOutputBehaviorKeyModiFromActionIDStateOutput(read as KeylayoutXMLSourceFile, converted.modifiers, String(values[0]), String(values[1]), Boolean(values[2])); - assert.equal(JSON.stringify(result), JSON.stringify(values[3])); - }); - } + assert.isNotNull(read); + it((JSON.stringify(values[3]).length > 35) ? + ("getActionOutputbehaviorKeyModiFromActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return an array of objects' : + ("getActionOutputbehaviorKeyModiFromActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return ' + "'" + JSON.stringify(values[3]) + "'", async function () { + const result = sut.getActionOutputBehaviorKeyModiFromActionIDStateOutput(read as KeylayoutXMLSourceFile, converted.modifiers, String(values[0]), String(values[1]), Boolean(values[2])); + assert.equal(JSON.stringify(result), JSON.stringify(values[3])); + }); }); }); @@ -775,8 +773,9 @@ describe('KeylayoutToKmnConverter', function () { it('data of \'' + values[0] + "' passed into createRuleData() " + 'should create an array of rules', async function () { const inputFilename = makePathToFixture(values[0][0]); const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename)); - const processedData = sut.unitTestEndpoints.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn')); - assert.deepEqual(processedData?.rules[0], values[1][0]); + const processedData = sut.unitTestEndpoints.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn')); + assert.isNotNull(processedData); + assert.deepEqual(processedData.rules[0], values[1][0]); }); }); }); 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 caa21faf65..c90ea3f095 100644 --- a/developer/src/kmc-convert/test/kmn-file-writer.tests.ts +++ b/developer/src/kmc-convert/test/kmn-file-writer.tests.ts @@ -64,7 +64,8 @@ describe('KmnFileWriter', function () { it(('writeKmnFileHeader should return store text with filename ').padEnd(62, " ") + 'on correct input', async function () { const writtenCorrectName = sutW.writeKmnFileHeader(converted); - assert.equal(writtenCorrectName, (outExpectedFirst + (converted?.keylayoutFilename ?? "") + outExpectedLast)); + assert.isNotNull(converted); + assert.equal(writtenCorrectName, (outExpectedFirst + (converted.keylayoutFilename ?? "") + outExpectedLast)); }); it(('writeKmnFileHeader should return no text with null filename ').padEnd(62, " ") + 'on correct input', async function () { const writtenEmptytName = sutW.writeKmnFileHeader(null); @@ -120,34 +121,42 @@ describe('KmnFileWriter', function () { }); }); - describe('writeCharacterOrUnicode ', function () { + describe('writeCharacterOrUnicode and return values', function () { const sutW = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); [ - ["A", "Msg", "A", "Msg"], - ["ሴ", "Msg", "ሴ", "Msg"], - ["πŸ˜€", "Msg", "πŸ˜€", "Msg"], - ["ẘ", "Msg", "ẘ", "Msg"], - ["U+0001", "Msg", "U+0001", "Msg; Use of a control character "], - ["U+0061", "Msg", "a", "Msg"], - ["", "Msg", "U+0002", "Msg; Use of a control character "], - ["ሴ", "Msg", 'ሴ', "Msg",], - ["", "Msg", "U+0003", "Msg; Use of a control character "], - ["ሺ", "Msg", "ሺ", "Msg",], - [null, "Msg", null, null], - [undefined, "Msg", null, null], - ["", "Msg", null, null], - ["", "Msg", "U+0006", "Msg; Use of a control character "], + ["A", "A", "Msg"], + ["ሴ", "ሴ", "Msg"], + ["πŸ˜€", "πŸ˜€", "Msg"], + ["ẘ", "ẘ", "Msg"], + ["U+0001", "U+0001", "Msg; Use of a control character "], + ["U+0061", "a", "Msg"], + ["", "U+0002", "Msg; Use of a control character "], + ["ሴ", 'ሴ', "Msg"], + ["", "U+0003", "Msg; Use of a control character "], + ["ሺ", "ሺ", "Msg"], + ["", "U+0006", "Msg; Use of a control character "], ].forEach(function (values) { - it(('should convert "' + values[0] + '"').padEnd(25, " ") + 'to "' + values[2] + '"', async function () { - const result = sutW.writeCharacterOrUnicode(values[0] as string, values[1] as string); - if (result) { - assert.equal(result.character, values[2]); - assert.equal(result.message, values[3]); - } - else { - assert.isNull(values[2]); - assert.isNull(values[3]); - } + it(('should convert "' + values[0] + '"').padEnd(25, " ") + 'to "' + values[1] + '"', async function () { + const result = sutW.writeCharacterOrUnicode(values[0] as string, "Msg"); + assert.isNotNull(result); + assert.equal(result.character, values[1]); + assert.equal(result.message, values[2]); + }); + }); + }); + + describe('writeCharacterOrUnicode and return empty string for result.message and result.character', function () { + const sutW = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions); + [ + [null, '', ''], + [undefined,'', ''], + ['', '', ''], + ].forEach(function (values) { + it(('should convert "' + values[0] + '"').padEnd(25, " ") + 'to "' + values[1] + '"', async function () { + const result = sutW.writeCharacterOrUnicode(values[0] as string, "Msg"); + assert.isNotNull(result); + assert.equal(result.character, values[1]); + assert.equal(result.message, values[2]); }); }); }); @@ -488,14 +497,14 @@ describe('KmnFileWriter', function () { rules: values[0] as Rule[] }; const result1 = sutW.writeDataRules(data); - assert.isTrue(result1 === values[1][0]); + assert.equal(result1, values[1][0]); }); }); it(('null should create empty string '), async function () { - const result1 = sutW.writeDataRules(null); - assert.isTrue(result1 === ''); - }); + const result1 = sutW.writeDataRules(null); + assert.equal(result1, ''); + }); }); });