mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-11 10:07:42 +00:00
feat(developer): add returntypes
Some checks are pending
Keyman Build Summary / Summarize build status checks (push) Waiting to run
Some checks are pending
Keyman Build Summary / Summarize build status checks (push) Waiting to run
This commit is contained in:
parent
16e0570bb2
commit
1d3d53e2e7
4 changed files with 62 additions and 59 deletions
|
|
@ -81,7 +81,7 @@ export class KeylayoutFileReader {
|
|||
/**
|
||||
* @returns true if valid, false if invalid
|
||||
*/
|
||||
public validate(source: Keylayout.KeylayoutXMLSourceFile|null): boolean {
|
||||
public validate(source: Keylayout.KeylayoutXMLSourceFile, inputFilename: string): boolean {
|
||||
if (!source) {
|
||||
this.callbacks.reportMessage(ConverterMessages.Error_UnableToRead());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ export class KeylayoutToKmnConverter {
|
|||
const KeylayoutReader = new KeylayoutFileReader(this.callbacks/*, this.options*/);
|
||||
|
||||
const binaryData = this.callbacks.loadFile(inputFilename);
|
||||
const jsonO: Keylayout.KeylayoutXMLSourceFile|null = KeylayoutReader.read(binaryData);
|
||||
const jsonO: Keylayout.KeylayoutXMLSourceFile | null = KeylayoutReader.read(binaryData);
|
||||
|
||||
if (!jsonO) {
|
||||
this.callbacks.reportMessage(ConverterMessages.Error_UnableToReadFile({ inputFilename: inputFilename }));
|
||||
|
|
@ -157,7 +157,7 @@ export class KeylayoutToKmnConverter {
|
|||
* @param jsonObj containing filename, behaviorand rules of a json object
|
||||
* @return an ProcessedData containing all data ready to print out
|
||||
*/
|
||||
private convert(jsonObj: Keylayout.KeylayoutXMLSourceFile, inputfilename: string, outputFilename?: string): ProcessedData {
|
||||
private convert(jsonObj: Keylayout.KeylayoutXMLSourceFile, inputfilename: string, outputFilename?: string): ProcessedData | null {
|
||||
// modifiers for each behavior
|
||||
const modifierBehavior: string[][] = [];
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ export class KeylayoutToKmnConverter {
|
|||
* @param jsonObj: json Object containing all data read from a keylayout file
|
||||
* @return an object containing the name of the input file, an array of behaviors and a populated array of Rules[]
|
||||
*/
|
||||
public createRuleData(dataUkelele: ProcessedData, jsonObj: Keylayout.KeylayoutXMLSourceFile): ProcessedData {
|
||||
public createRuleData(dataUkelele: ProcessedData, jsonObj: Keylayout.KeylayoutXMLSourceFile): ProcessedData | null {
|
||||
|
||||
const rules: Rule[] = [];
|
||||
let dkCounterC3: number = 0;
|
||||
|
|
@ -346,7 +346,7 @@ export class KeylayoutToKmnConverter {
|
|||
// with present actionId (a18) find all keycode-behavior-pairs that use this action (a18) => (keymapIndex 0/keycode 24 and keymapIndex 3/keycode 24) ....................................
|
||||
// from these create an array of modifier combinations e.g. [['','caps?'], ['Caps']] .....................................................................................................
|
||||
/* eg: [['24', 0], ['24', 3]] */ const b4DeadkeyObj: KeylayoutFileData[] = this.getKeyModifierArrayFromActionID(jsonObj, actionId);
|
||||
/* e.g. [['','caps?'], ['Caps']]*/ const b4DeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b4DeadkeyObj);
|
||||
/* e.g. [['','caps?'], ['Caps']]*/ const b4DeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b4DeadkeyObj) as string[][];
|
||||
// ........................................................................................................................................................................................
|
||||
|
||||
|
||||
|
|
@ -410,21 +410,22 @@ export class KeylayoutToKmnConverter {
|
|||
|
||||
// with actionId from above loop all 'action' and search for a state-next-pair ...................................................................................................................
|
||||
// e.g. in Block 5: find <when state="3" next="1"/> for action id a16 .............................................................................................................................
|
||||
for (let l = 0; l < jsonObj.keyboard.actions.action[b1ActionIndex].when.length; l++) {
|
||||
if ((jsonObj.keyboard.actions.action[b1ActionIndex].when[l]['state'] !== "none")
|
||||
&& (jsonObj.keyboard.actions.action[b1ActionIndex].when[l]['next'] !== undefined)) {
|
||||
if (jsonObj.keyboard.actions?.action?.[b1ActionIndex]?.when) {
|
||||
for (const when of jsonObj.keyboard.actions.action[b1ActionIndex].when) {
|
||||
if ((when['state'] !== "none")
|
||||
&& (when['next'] !== undefined)) {
|
||||
|
||||
// Data of Block Nr 5 ........................................................................................................................................................................
|
||||
// of this state-next-pair get value of next (next="1") and state="3" ........................................................................................................................
|
||||
/* e.g. state = 3 */ const b5ValueState: string = jsonObj.keyboard.actions.action[b1ActionIndex].when[l]['state'];
|
||||
/* e.g. next = 1 */ const b5ValueNext: string = jsonObj.keyboard.actions.action[b1ActionIndex].when[l]['next'];
|
||||
/* e.g. state = 3 */ const b5ValueState: string = when['state'] as string;
|
||||
/* e.g. next = 1 */ const b5ValueNext: string = when['next'];
|
||||
// ...........................................................................................................................................................................................
|
||||
|
||||
// Data of Block Nr 4 ........................................................................................................................................................................
|
||||
// with present actionId (a16) find all keycode-behavior-pairs that use this action (a16) => (keymapIndex 3/keycode 32) ....................................................................
|
||||
// from these create an array of modifier combinations e.g. [ [ 'anyOption', 'Caps' ] ] .....................................................................................................
|
||||
/* e.g. [['32', 3]] */ const b4DeadkeyObj: KeylayoutFileData[] = this.getKeyModifierArrayFromActionID(jsonObj, actionId);
|
||||
/* e.g. [ [ 'anyOption', 'Caps' ] ]*/ const b4DeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b4DeadkeyObj);
|
||||
/* e.g. [ [ 'anyOption', 'Caps' ] ]*/ const b4DeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b4DeadkeyObj) as string[][];
|
||||
// ...........................................................................................................................................................................................
|
||||
|
||||
// Data of Block Nr 3 ........................................................................................................................................................................
|
||||
|
|
@ -436,7 +437,7 @@ export class KeylayoutToKmnConverter {
|
|||
// with present actionId (a17) find all key names and behaviors that use this action (a17) => (keymapIndex 3/keycode 28) ....................................................................
|
||||
// from these create an array of modifier combinations e.g. [ [ 'anyOption', 'Caps' ] ] .....................................................................................................
|
||||
/* eg: index=3 */ const b2PrevDeadkeyObj: KeylayoutFileData[] = this.getKeyModifierArrayFromActionID(jsonObj, b3ActionId);
|
||||
/* e.g. [ [ 'anyOption', 'Caps' ] ] */ const b2PrevDeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b2PrevDeadkeyObj);
|
||||
/* e.g. [ [ 'anyOption', 'Caps' ] ] */ const b2PrevDeadkeyModifierObj: string[][] = this.getModifierArrayFromKeyModifierArray(dataUkelele.modifiers, b2PrevDeadkeyObj) as string[][];
|
||||
// ...........................................................................................................................................................................................
|
||||
// Data of Block Nr 6 ........................................................................................................................................................................
|
||||
// create an array[action id,state,output] from all state-output-pairs that use state = b5ValueNext (e.g. use 1 in <when state="1" output="â"/> ) .........................................
|
||||
|
|
@ -447,17 +448,17 @@ export class KeylayoutToKmnConverter {
|
|||
// create array[Keycode,Keyname,action id,actionIndex,output] and array[Keyname,action id,behavior,modifier,output] .........................................................................
|
||||
/* eg: ['49','K_SPACE','a0','0','Â'] */ const b1KeycodeObj: KeylayoutFileData[] = this.getKeyActionOutputArrayFromActionStateOutputArray(jsonObj, b6ActionIdObj);
|
||||
/* eg: ['K_SPACE','a0','0','NCAPS','Â'] */ const b1ModifierKeyObj: KeylayoutFileData[] = this.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(jsonObj, b1KeycodeObj, isCapsused);
|
||||
// ...........................................................................................................................................................................................
|
||||
// ...........................................................................................................................................................................................
|
||||
|
||||
for (let n1 = 0; n1 < b2PrevDeadkeyModifierObj.length; n1++) {
|
||||
for (let n2 = 0; n2 < b2PrevDeadkeyModifierObj[n1].length; n2++) {
|
||||
for (let n3 = 0; n3 < b2PrevDeadkeyObj.length; n3++) {
|
||||
for (let n4 = 0; n4 < b4DeadkeyModifierObj.length; n4++) {
|
||||
for (let n5 = 0; n5 < b4DeadkeyModifierObj[n4].length; n5++) {
|
||||
for (let n6 = 0; n6 < b4DeadkeyObj.length; n6++) {
|
||||
for (let n7 = 0; n7 < b1ModifierKeyObj.length; n7++) {
|
||||
for (let n1 = 0; n1 < b2PrevDeadkeyModifierObj.length; n1++) {
|
||||
for (let n2 = 0; n2 < b2PrevDeadkeyModifierObj[n1].length; n2++) {
|
||||
for (let n3 = 0; n3 < b2PrevDeadkeyObj.length; n3++) {
|
||||
for (let n4 = 0; n4 < b4DeadkeyModifierObj.length; n4++) {
|
||||
for (let n5 = 0; n5 < b4DeadkeyModifierObj[n4].length; n5++) {
|
||||
for (let n6 = 0; n6 < b4DeadkeyObj.length; n6++) {
|
||||
for (let n7 = 0; n7 < b1ModifierKeyObj.length; n7++) {
|
||||
|
||||
ruleObj = new Rule(
|
||||
ruleObj = new Rule(
|
||||
/* ruleType */ "C3",
|
||||
/* modifierPrevDeadkey*/ this.createKmnModifier(b2PrevDeadkeyModifierObj[n1][n2], isCapsused),
|
||||
/* prevDeadkey */ this.mapUkeleleKeycodeToVK(Number(b2PrevDeadkeyObj[n3].key)),
|
||||
|
|
@ -472,11 +473,12 @@ export class KeylayoutToKmnConverter {
|
|||
/* modifierKey*/ b1ModifierKeyObj[n7].modifier ?? "",
|
||||
/* key */ b1ModifierKeyObj[n7].key ?? "",
|
||||
/* output */ new TextEncoder().encode(b1ModifierKeyObj[n7].outchar),
|
||||
);
|
||||
if ((b1ModifierKeyObj[n7].outchar !== undefined)
|
||||
&& (b1ModifierKeyObj[n7].outchar !== "undefined")
|
||||
&& (b1ModifierKeyObj[n7].outchar !== "")) {
|
||||
rules.push(ruleObj);
|
||||
);
|
||||
if ((b1ModifierKeyObj[n7].outchar !== undefined)
|
||||
&& (b1ModifierKeyObj[n7].outchar !== "undefined")
|
||||
&& (b1ModifierKeyObj[n7].outchar !== "")) {
|
||||
rules.push(ruleObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -492,7 +494,7 @@ export class KeylayoutToKmnConverter {
|
|||
this.callbacks.reportMessage(ConverterMessages.Error_UnsupportedCharactersDetected({
|
||||
inputFilename: jsonObj.keyboard['name'] + ".keylayout",
|
||||
keymapIndex: jsonObj.keyboard.keyMapSet[0].keyMap[i]['index'],
|
||||
output: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['output'],
|
||||
output: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['output'] as string,
|
||||
key: jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['code'],
|
||||
KeyName: this.mapUkeleleKeycodeToVK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['code']))
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { compilerTestCallbacks, compilerTestOptions, makePathToFixture } from '.
|
|||
import { ActionStateOutput, KeylayoutFileData, KeylayoutToKmnConverter, Rule } from '../src/keylayout-to-kmn/keylayout-to-kmn-converter.js';
|
||||
import { KeylayoutFileReader } from '../src/keylayout-to-kmn/keylayout-file-reader.js';
|
||||
import { ConverterMessages } from '../src/converter-messages.js';
|
||||
import { KeylayoutXMLSourceFile } from '../../common/web/utils/src/types/keylayout/keylayout-xml.js';
|
||||
|
||||
describe('KeylayoutToKmnConverter', function () {
|
||||
|
||||
|
|
@ -155,17 +156,17 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
// ProcessedData from usable file
|
||||
const inputFilename = makePathToFixture('../data/Test.keylayout');
|
||||
const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const converted = sut.convertBound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
const converted = sut.convertBound.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.convertBound.convert(readUnavailable, inputFilenameUnavailable.replace(/\.keylayout$/, '.kmn'));
|
||||
const convertedUnavailable = sut.convertBound.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.convertBound.convert(readEmpty, inputFilenameEmpty);
|
||||
const convertedEmpty = sut.convertBound.convert(readEmpty as KeylayoutXMLSourceFile, inputFilenameEmpty);
|
||||
|
||||
it('should return converted array on correct input', async function () {
|
||||
assert.isTrue(converted?.rules.length !== 0);
|
||||
|
|
@ -180,7 +181,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
});
|
||||
|
||||
it('should return empty array of rules on null input', async function () {
|
||||
const convertedRule = sut.convertBound.convert(null, 'ABC.kmn');
|
||||
const convertedRule = sut.convertBound.convert(null , 'ABC.kmn');
|
||||
assert.isNull(convertedRule);
|
||||
});
|
||||
});
|
||||
|
|
@ -317,7 +318,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test.keylayout');
|
||||
const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const converted = sut.convertBound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
const converted = sut.convertBound.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
[
|
||||
[[{ key: '0', behavior: 0 }], [['', 'shift? caps? ']]],
|
||||
[[{ key: '0', behavior: 2 }], [['shift? leftShift caps? ', 'anyShift caps?', 'shift leftShift caps ', 'shift? rightShift caps? ']]],
|
||||
|
|
@ -332,7 +333,7 @@ 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, values[0] as KeylayoutFileData[]);
|
||||
const result = sut.getModifierArrayFromKeyModifierArray(converted?.modifiers as string[][], values[0] as unknown as KeylayoutFileData[]);
|
||||
assert.deepStrictEqual(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -360,7 +361,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
}
|
||||
}
|
||||
it(("getKeyModifierArrayFromActionID('" + values[0] + "')").padEnd(57, " ") + ' should return ' + outstring.substring(0, outstring.lastIndexOf(']') + 2) + " ]", async function () {
|
||||
const result = sut.getKeyModifierArrayFromActionID(read, String(values[0]));
|
||||
const result = sut.getKeyModifierArrayFromActionID(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -386,7 +387,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
['unknown', ''],
|
||||
].forEach(function (values) {
|
||||
it(("getActionIdFromActionNext('" + values[0] + "')").padEnd(49, " ") + ' should return ' + "'" + values[1] + "'", async function () {
|
||||
const result = sut.getActionIdFromActionNext(read, String(values[0]));
|
||||
const result = sut.getActionIdFromActionNext(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -410,7 +411,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
['unknown', -1],
|
||||
].forEach(function (values) {
|
||||
it(("getActionIndexFromActionId('" + values[0] + "')").padEnd(50, " ") + ' should return ' + values[1], async function () {
|
||||
const result = sut.getActionIndexFromActionId(read, String(values[0]));
|
||||
const result = sut.getActionIndexFromActionId(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -430,7 +431,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(
|
||||
("getOutputFromActionIdNone('" + values[0] + "')").padEnd(56, " ") + ' should return ' + "'" + values[1] + "'", async function () {
|
||||
const result = sut.getOutputFromActionIdNone(read, String(values[0]));
|
||||
const result = sut.getOutputFromActionIdNone(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -440,7 +441,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[99, ''],
|
||||
].forEach(function (values) {
|
||||
it(("getOutputFromActionIdNone('" + values[0] + "')").padEnd(56, " ") + ' should return ' + values[1], async function () {
|
||||
const result = sut.getOutputFromActionIdNone(read, String(values[0]));
|
||||
const result = sut.getOutputFromActionIdNone(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -523,7 +524,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
|
||||
it((JSON.stringify(values[1]).length > 60) ? 'an array of objects should return an array of objects' :
|
||||
stringIn.padEnd(74, " ") + ' should return ' + stringOut, async function () {
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read, values[0], isCapsUsed);
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read as KeylayoutXMLSourceFile, values[0], isCapsUsed);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -537,7 +538,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
const stringOut = "['" + values[1].actionId + "', '" + "', '" + values[1].modifier + "', '" + values[1].key + "', '" + values[1].outchar + "']";
|
||||
|
||||
it(stringIn.padEnd(74, " ") + ' should return ' + stringOut, async function () {
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read, [values[0]], isCapsUsed);
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read as KeylayoutXMLSourceFile, [values[0]], isCapsUsed);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify([values[1]]));
|
||||
});
|
||||
});
|
||||
|
|
@ -548,7 +549,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
const isCaps = true;
|
||||
it(("getKeybehaviorModOutputArrayFromKeyActionbehaviorOutputArray([" + values[0] + "])").padEnd(74, " ") + ' should return ' + "[" + values[1] + "]", async function () {
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read, values[0] ?? [], isCaps);
|
||||
const result = sut.getKeyBehaviorModOutputArrayFromKeyActionBehaviorOutputArray(read as KeylayoutXMLSourceFile, values[0] ?? [], isCaps);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -595,7 +596,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
it((JSON.stringify(values[1]).length > 30) ?
|
||||
("getActionStateOutputArrayFromActionState('" + values[0] + "')").padEnd(60, " ") + ' should return an array of objects' :
|
||||
("getActionStateOutputArrayFromActionState('" + values[0] + "')").padEnd(60, " ") + ' should return ' + "'" + JSON.stringify(values[1]) + "'", async function () {
|
||||
const result = sut.getActionStateOutputArrayFromActionState(read, String(values[0]));
|
||||
const result = sut.getActionStateOutputArrayFromActionState(read as KeylayoutXMLSourceFile, String(values[0]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -606,7 +607,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test.keylayout');
|
||||
const read = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const converted = sut.convertBound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
const converted = sut.convertBound.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
[
|
||||
['A_1', 'A', true,
|
||||
[{ "outchar": "A", "actionId": "A_1", "behavior": "1", "key": "K_A", "modifier": "CAPS" },
|
||||
|
|
@ -631,7 +632,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
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, converted.modifiers, String(values[0]), String(values[1]), Boolean(values[2]));
|
||||
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]));
|
||||
});
|
||||
}
|
||||
|
|
@ -686,7 +687,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[[b6ActionIdArr, b1KeycodeArr],
|
||||
].forEach(function (values) {
|
||||
it(("getKeyActionOutputArrayFromActionStateOutputArray([['" + JSON.stringify(values[0]) + "'],..])").padEnd(73, " ") + '1 should return an array of objects', async function () {
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read, values[0] as ActionStateOutput[]);
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read as KeylayoutXMLSourceFile, values[0] as ActionStateOutput[]);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -716,7 +717,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[[{ "id": "A_0", "state": "", "output": "ˆ" }], oneEntryResult],
|
||||
].forEach(function (values) {
|
||||
it(("getKeyActionOutputArrayFromActionStateOutputArray(['" + JSON.stringify(values[0]) + "'])").padEnd(73, " ") + ' should return an array of objects', async function () {
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read, values[0] as ActionStateOutput[]);
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read as KeylayoutXMLSourceFile, values[0] as ActionStateOutput[]);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -727,7 +728,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
|
||||
].forEach(function (values) {
|
||||
it(("getKeyActionOutputArrayFromActionStateOutputArray(" + JSON.stringify(values[0]) + ")").padEnd(73, " ") + ' should return ' + "'[" + JSON.stringify(values[1]) + "]'", async function () {
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read, values[0] as ActionStateOutput[]);
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read as KeylayoutXMLSourceFile, values[0] as ActionStateOutput[]);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -737,7 +738,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[null, []],
|
||||
].forEach(function (values) {
|
||||
it(("getKeyActionOutputArrayFromActionStateOutputArray(" + JSON.stringify(values[0]) + ")").padEnd(73, " ") + ' should return ' + "'[" + JSON.stringify(values[1]) + "]'", async function () {
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read, values[0] as ActionStateOutput[]);
|
||||
const result = sut.getKeyActionOutputArrayFromActionStateOutputArray(read as KeylayoutXMLSourceFile, values[0] as ActionStateOutput[]);
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
|
@ -797,7 +798,7 @@ 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.convertBound.convert(read, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
const processedData = sut.convertBound.convert(read as KeylayoutXMLSourceFile, inputFilename.replace(/\.keylayout$/, '.kmn'));
|
||||
assert.deepEqual(processedData?.rules[0], values[1][0]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -24,38 +24,38 @@ describe('KeylayoutFileReader', function () {
|
|||
it('validate() should return true on correct inputfile', async function () {
|
||||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test.keylayout');
|
||||
const result: Keylayout.KeylayoutXMLSourceFile|null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result);
|
||||
const result: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result as Keylayout.KeylayoutXMLSourceFile, inputFilename);
|
||||
assert.isTrue(validated);
|
||||
});
|
||||
|
||||
it('validate() should return false on inputfile with unknown tags', async function () {
|
||||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test_unknownTags.keylayout');
|
||||
const result: Keylayout.KeylayoutXMLSourceFile|null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result);
|
||||
const result: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result as Keylayout.KeylayoutXMLSourceFile, inputFilename);
|
||||
assert.isFalse(validated);
|
||||
});
|
||||
|
||||
it('validate() should return false on inputfile with additional tags', async function () {
|
||||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test_additionalTags.keylayout');
|
||||
const result: Keylayout.KeylayoutXMLSourceFile|null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result);
|
||||
const result: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result as Keylayout.KeylayoutXMLSourceFile, inputFilename);
|
||||
assert.isFalse(validated);
|
||||
});
|
||||
it('validate() should return false on inputfile with missing tags', async function () {
|
||||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test_missingTags.keylayout');
|
||||
const result: Keylayout.KeylayoutXMLSourceFile|null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result);
|
||||
const result: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result as Keylayout.KeylayoutXMLSourceFile, inputFilename);
|
||||
assert.isFalse(validated);
|
||||
});
|
||||
it('validate() should return false on no entries in action-when', async function () {
|
||||
const sutR = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Test_noActionWhen.keylayout');
|
||||
const result: Keylayout.KeylayoutXMLSourceFile|null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result);
|
||||
const result: Keylayout.KeylayoutXMLSourceFile | null = sutR.read(compilerTestCallbacks.loadFile(inputFilename));
|
||||
const validated = sutR.validate(result as Keylayout.KeylayoutXMLSourceFile, inputFilename);
|
||||
assert.isFalse(validated);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue