mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-12 08:57:30 +00:00
feat(developer): use NodeAssert.rejects for tests of run() only; other tests changed back to before
This commit is contained in:
parent
2a2b214e7f
commit
b8e4a79211
5 changed files with 152 additions and 127 deletions
|
|
@ -33,6 +33,7 @@ export interface convert_object {
|
|||
kmn_filename: string,
|
||||
arrayOf_Modifiers: string[][],
|
||||
arrayOf_Rules: rule_object[],
|
||||
//arrayOf_Rules: any[],
|
||||
};
|
||||
|
||||
export class KeylayoutToKmnConverter {
|
||||
|
|
@ -97,8 +98,8 @@ export class KeylayoutToKmnConverter {
|
|||
public convert(jsonObj: any, outputfilename: string = ""): convert_object {
|
||||
|
||||
const modifierBehavior: string[][] = []; // modifier for each behaviour
|
||||
const rules: rule_object[] = []; // an array of data for kmn rules
|
||||
const jsonObj_any: any = jsonObj;
|
||||
const rules: rule_object[] = []; // an array of data for a kmn rule
|
||||
//const rules: any[] = []; // an array of data for a kmn rule
|
||||
|
||||
const data_object: convert_object = {
|
||||
keylayout_filename: "",
|
||||
|
|
@ -108,22 +109,23 @@ export class KeylayoutToKmnConverter {
|
|||
};
|
||||
|
||||
// ToDo in a new PR: check tags ( issue # 13599)
|
||||
if (jsonObj_any.hasOwnProperty("keyboard")) {
|
||||
if (jsonObj.hasOwnProperty("keyboard")) {
|
||||
|
||||
data_object.keylayout_filename = jsonObj_any.keyboard['@_name'] + ".keylayout";
|
||||
// get filename from data that had been read
|
||||
const fileNameNoExtention = jsonObj.keyboard['@_name'];
|
||||
const filePath = this.callbacks.path.join(process.cwd(), "data");
|
||||
|
||||
// this.callbacks.fs.readFileSync(this.callbacks.path.join(process.cwd(), KeylayoutFileReader.FILE_SUBFOLDER, this.callbacks.path.basename(absolutefilename)), 'utf8');
|
||||
//use join as in this.callbacks.path.join(process.cwd(), "data", absolutefilename.replace(/^.*[\\/]/, '')), 'utf8'
|
||||
data_object.keylayout_filename = this.callbacks.path.join(filePath, (fileNameNoExtention + ".keylayout"));
|
||||
|
||||
// if no outputfile name is specified: create one from input file name
|
||||
if ((outputfilename === "") || (outputfilename === null)) {
|
||||
// data_object.kmn_filename = (process.cwd() + "\\data\\" + data_object.keylayout_filename.substring(0, data_object.keylayout_filename.lastIndexOf(".")) + ".kmn");
|
||||
data_object.kmn_filename = (process.cwd() + "\\data\\" + data_object.keylayout_filename.substring(0, data_object.keylayout_filename.lastIndexOf(".")) + ".kmn");
|
||||
data_object.kmn_filename = this.callbacks.path.join(filePath, fileNameNoExtention + ".kmn");
|
||||
}
|
||||
// if outputfile name is specified: use it
|
||||
else
|
||||
data_object.kmn_filename = outputfilename;
|
||||
|
||||
//console.log("RUN kmc convert - input file: ", (process.cwd() + "\\data\\" + data_object.keylayout_filename), " --> output file: ", data_object.kmn_filename);
|
||||
console.log("RUN kmc convert - input file: ", (this.callbacks.path.dirname(data_object.kmn_filename) + "\\" + 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);
|
||||
|
||||
data_object.arrayOf_Modifiers = modifierBehavior; // ukelele uses behaviours e.g. 18 modifiersCombinations in 8 KeyMapSelect(behaviors)
|
||||
data_object.arrayOf_Rules = rules;
|
||||
|
|
@ -151,6 +153,7 @@ export class KeylayoutToKmnConverter {
|
|||
public createRuleData(data_ukelele: convert_object, jsonObj: any): convert_object {
|
||||
|
||||
const object_array: rule_object[] = [];
|
||||
// const object_array = [];
|
||||
let dk_counter_C3: number = 0;
|
||||
let dk_counter_C2: number = 0;
|
||||
let action_id: string;
|
||||
|
|
@ -165,6 +168,7 @@ export class KeylayoutToKmnConverter {
|
|||
for (let i = 0; i < jsonObj.keyboard.keyMapSet[0].keyMap.length; i++) {
|
||||
|
||||
let rule_obj: rule_object;
|
||||
//let rule_obj;
|
||||
|
||||
// ...............................................................................................................................
|
||||
// case C0: output ...............................................................................................................
|
||||
|
|
@ -180,7 +184,7 @@ export class KeylayoutToKmnConverter {
|
|||
for (let l = 0; l < data_ukelele.arrayOf_Modifiers[i].length; l++) {
|
||||
if (this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']))) {
|
||||
|
||||
rule_obj = new Rules(
|
||||
rule_obj = new Rule(
|
||||
/* rule_type */ "C0",
|
||||
|
||||
/* modifier_prev_deadkey*/ "",
|
||||
|
|
@ -224,7 +228,7 @@ export class KeylayoutToKmnConverter {
|
|||
|
||||
for (let m = 0; m < b1_modifierKey_arr.length; m++) {
|
||||
|
||||
rule_obj = new Rules(
|
||||
rule_obj = new Rule(
|
||||
/* rule_type */ "C1",
|
||||
|
||||
/* modifier_prev_deadkey*/ "",
|
||||
|
|
@ -295,7 +299,7 @@ export class KeylayoutToKmnConverter {
|
|||
for (let n3 = 0; n3 < b4_deadkey_arr.length; n3++) {
|
||||
for (let n4 = 0; n4 < b1_modifierKey_arr.length; n4++) {
|
||||
|
||||
rule_obj = new Rules(
|
||||
rule_obj = new Rule(
|
||||
/* rule_type */ "C2",
|
||||
|
||||
/* modifier_prev_deadkey*/ "",
|
||||
|
|
@ -384,7 +388,7 @@ export class KeylayoutToKmnConverter {
|
|||
for (let n6 = 0; n6 < b4_deadkey_arr.length; n6++) {
|
||||
for (let n7 = 0; n7 < b1_modifierKey_arr.length; n7++) {
|
||||
|
||||
rule_obj = new Rules(
|
||||
rule_obj = new Rule(
|
||||
/* rule_type */ "C3",
|
||||
/* modifier_prev_deadkey*/ this.create_kmn_modifier(b2_prev_deadkeyModifier_arr[n1][n2], isCapsused),
|
||||
/* prev_deadkey */ this.map_UkeleleKC_To_VK(Number(b2_prev_deadkey_arr[n3][0])),
|
||||
|
|
@ -443,6 +447,7 @@ export class KeylayoutToKmnConverter {
|
|||
const list_of_unique_Text2_rules: string[][] = [];
|
||||
|
||||
const object_array: rule_object[] = data_ukelele.arrayOf_Rules;
|
||||
//const object_array = data_ukelele.arrayOf_Rules;
|
||||
|
||||
//------------------------------------ C2: dk ----------------------------------
|
||||
// first rule is always unique
|
||||
|
|
@ -985,7 +990,7 @@ export class KeylayoutToKmnConverter {
|
|||
/**
|
||||
* @brief class for all storing a rule containing data for key, deadkey, previous deadkey, output)
|
||||
*/
|
||||
class Rules {
|
||||
class Rule {
|
||||
constructor(
|
||||
public rule_type: string, /* C0, C1, C2, C3, or C4 */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { CompilerCallbacks, CompilerOptions } from "@keymanapp/developer-utils";
|
||||
import { KeylayoutToKmnConverter, convert_object, rule_object } from './keylayout-to-kmn-converter.js';
|
||||
//import { KeylayoutToKmnConverter, convert_object, rule_object } from './keylayout-to-kmn-converter.js';
|
||||
import { KeylayoutToKmnConverter, convert_object } from './keylayout-to-kmn-converter.js';
|
||||
import { util } from '@keymanapp/common-types';
|
||||
|
||||
export class KmnFileWriter {
|
||||
|
|
@ -78,7 +79,8 @@ export class KmnFileWriter {
|
|||
let data: string = "";
|
||||
|
||||
// filter array of all rules and remove duplicates
|
||||
const unique_data_Rules: rule_object[] = data_ukelele.arrayOf_Rules.filter((curr) => {
|
||||
//const unique_data_Rules: rule_object[] = data_ukelele.arrayOf_Rules.filter((curr) => {
|
||||
const unique_data_Rules: any[] = data_ukelele.arrayOf_Rules.filter((curr) => {
|
||||
return (!(curr.output === new TextEncoder().encode("") || curr.output === undefined)
|
||||
&& (curr.key !== "")
|
||||
&& ((curr.rule_type === "C0")
|
||||
|
|
@ -87,11 +89,10 @@ export class KmnFileWriter {
|
|||
|| (curr.rule_type === "C3" && (curr.deadkey !== "") && (curr.prev_deadkey !== "")))
|
||||
);
|
||||
}).reduce((unique, o) => {
|
||||
if (!unique.some((obj: rule_object) =>
|
||||
// if (!unique.some((obj: rule_object) =>
|
||||
if (!unique.some((obj: any) =>
|
||||
new TextDecoder().decode(obj.output) === new TextDecoder().decode(o.output)
|
||||
|
||||
&& obj.output !== new TextEncoder().encode("")
|
||||
|
||||
&& obj.rule_type === o.rule_type
|
||||
&& obj.modifier_key === o.modifier_key
|
||||
&& obj.key === o.key
|
||||
|
|
@ -325,7 +326,8 @@ export class KmnFileWriter {
|
|||
* @param index the index of a rule in array[rule]
|
||||
* @return a string[] containing possible warnings for a rule
|
||||
*/
|
||||
public reviewRules(rule: rule_object[], index: number): string[] {
|
||||
//public reviewRules(rule: rule_object[], index: number): string[] {
|
||||
public reviewRules(rule: any[], index: number): string[] {
|
||||
|
||||
const keylayoutKmnConverter = new KeylayoutToKmnConverter(this.callbacks, this.options);
|
||||
const warningTextArray: string[] = Array(3).fill("");
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
|
||||
import 'mocha';
|
||||
import { assert } from 'chai';
|
||||
import { compilerTestCallbacks, compilerTestOptions, makePathToFixture } from './helpers/index.js';
|
||||
import { KeylayoutToKmnConverter } from '../src/keylayout-to-kmn/keylayout-to-kmn-converter.js';
|
||||
import { KeylayoutFileReader } from '../src/keylayout-to-kmn/keylayout-file-reader.js';
|
||||
import { rejects, doesNotReject } from "node:assert";
|
||||
|
||||
import * as NodeAssert from 'node:assert';
|
||||
|
||||
describe('KeylayoutToKmnConverter', function () {
|
||||
|
||||
|
|
@ -18,56 +18,57 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
compilerTestCallbacks.clear();
|
||||
});
|
||||
|
||||
describe('run()', function () {
|
||||
describe('run() ', function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
||||
it('run() should throw on null input file name and null output file name', async function () {
|
||||
await rejects(async () => sut.run(null, null));
|
||||
// note, could use 'chai as promised' library to make this more fluent:
|
||||
await NodeAssert.rejects(async () => sut.run(null, null));
|
||||
});
|
||||
|
||||
it('run() chai as promisedshould throw on null input file name and empty output file name', async function () {
|
||||
await rejects(async () => sut.run(null, ""));
|
||||
it('run() should throw on null input file name and empty output file name', async function () {
|
||||
await NodeAssert.rejects(async () => sut.run(null, ""));
|
||||
});
|
||||
|
||||
it('run() chai as promisedshould throw on null input file name and unknown output file name', async function () {
|
||||
await rejects(async () => sut.run(null, "X"));
|
||||
it('run() should throw on null input file name and unknown output file name', async function () {
|
||||
await NodeAssert.rejects(async () => sut.run(null, "X"));
|
||||
});
|
||||
|
||||
it('run() should throw on unavailable input file name and null output file name', async function () {
|
||||
const inputFilename = makePathToFixture('../data/Unavailable.keylayout');
|
||||
await rejects(async () => sut.run(inputFilename, null));
|
||||
await NodeAssert.rejects(async () => sut.run(inputFilename, null));
|
||||
});
|
||||
|
||||
it('run() should return on correct input file name and empty output file name ', async function () {
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
await doesNotReject(async () => sut.run(inputFilename, ""));
|
||||
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/Italian.keylayout');
|
||||
await doesNotReject(async () => sut.run(inputFilename, null));
|
||||
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/Italian.keylayout');
|
||||
const outputFilename = makePathToFixture('../../data/OutputName.kmn');
|
||||
await doesNotReject(async () => sut.run(inputFilename, outputFilename));
|
||||
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/Italian_command.A');
|
||||
const outputFilename = makePathToFixture('../../data/OutputXName.B');
|
||||
await rejects(async () => sut.run(inputFilename, outputFilename));
|
||||
await NodeAssert.rejects(async () => sut.run(inputFilename, outputFilename));
|
||||
});
|
||||
|
||||
it('run() return on correct input file extention and unsupperted output file extention', async function () {
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const outputFilename = makePathToFixture('../../data/OutputXName.B');
|
||||
await doesNotReject(async () => sut.run(inputFilename, outputFilename));
|
||||
await NodeAssert.doesNotReject(async () => sut.run(inputFilename, outputFilename));
|
||||
});
|
||||
});
|
||||
|
||||
describe('convert()', function () {
|
||||
describe("convert() ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -85,19 +86,19 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
const converted_empty = sut.convert(read_empty);
|
||||
|
||||
it('should return converted array on correct input', async function () {
|
||||
await (doesNotReject(async () => (converted.arrayOf_Rules.length !== 0)));
|
||||
assert.isTrue(converted.arrayOf_Rules.length !== 0);
|
||||
});
|
||||
|
||||
it('should return empty on empty input', async function () {
|
||||
await (doesNotReject(async () => (converted_empty.keylayout_filename === ''
|
||||
assert.isTrue((converted_empty.keylayout_filename === ''
|
||||
&& converted_empty.arrayOf_Modifiers.length === 0
|
||||
&& converted_empty.arrayOf_Rules.length === 0)));
|
||||
&& converted_empty.arrayOf_Rules.length === 0));
|
||||
});
|
||||
|
||||
it('should return empty on only name as input', async function () {
|
||||
await (doesNotReject(async () => (converted_unavailable.keylayout_filename === ''
|
||||
assert.isTrue((converted_unavailable.keylayout_filename === ''
|
||||
&& converted_unavailable.arrayOf_Modifiers.length === 0
|
||||
&& converted_unavailable.arrayOf_Rules.length === 0)));
|
||||
&& converted_unavailable.arrayOf_Rules.length === 0));
|
||||
});
|
||||
|
||||
it('should return empty on only modifiers as input', async function () {
|
||||
|
|
@ -106,9 +107,9 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
arrayOf_Modifiers: [['caps'], ['Shift'], ['command']],
|
||||
arrayOf_Rules: []
|
||||
});
|
||||
await (doesNotReject(async () => (converted_mod.keylayout_filename === ''
|
||||
assert.isTrue((converted_mod.keylayout_filename === ''
|
||||
&& converted_mod.arrayOf_Modifiers.length === 0
|
||||
&& converted_mod.arrayOf_Rules.length === 0)));
|
||||
&& converted_mod.arrayOf_Rules.length === 0));
|
||||
});
|
||||
|
||||
it('should return empty on only rules as input', async function () {
|
||||
|
|
@ -117,14 +118,15 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
arrayOf_Modifiers: [],
|
||||
arrayOf_Rules: [["C0", "", "", 0, 0, "", "", 0, 0, "CAPS", "K_A", "A"]]
|
||||
});
|
||||
await (doesNotReject(async () => (converted_rule.keylayout_filename === ''
|
||||
assert.isTrue((converted_rule.keylayout_filename === ''
|
||||
&& converted_rule.arrayOf_Modifiers.length === 0
|
||||
&& converted_rule.arrayOf_Rules.length === 0)));
|
||||
&& converted_rule.arrayOf_Rules.length === 0));
|
||||
});
|
||||
});
|
||||
|
||||
describe('create_kmn_modifier', function () {
|
||||
describe('create_kmn_modifier ', function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
||||
[
|
||||
['shift', true, 'NCAPS SHIFT'],
|
||||
['leftshift', true, 'NCAPS SHIFT'],
|
||||
|
|
@ -153,15 +155,16 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
['leftoption', true, 'NCAPS LALT'],
|
||||
['loption', true, 'NCAPS LALT'],
|
||||
].forEach(function (values) {
|
||||
|
||||
it(('should convert "' + values[0] + '"').padEnd(36, " ") + 'to "' + values[2] + '"', async function () {
|
||||
await doesNotReject(async () => (sut.create_kmn_modifier(values[0] as string, values[1] as boolean) === values[2]));
|
||||
const result = sut.create_kmn_modifier(values[0] as string, values[1] as boolean);
|
||||
assert.equal(result, values[2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAcceptableKeymanModifier', function () {
|
||||
describe("isAcceptableKeymanModifier ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
||||
[
|
||||
["NCAPS", true],
|
||||
["NxCAPS", false],
|
||||
|
|
@ -177,17 +180,16 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
["", true],
|
||||
[null, false],
|
||||
].forEach(function (values) {
|
||||
|
||||
it(("isAcceptableKeymanModifier(" + values[0] + ")").padEnd(38, " ") + ' should return ' + values[1], async function () {
|
||||
await doesNotReject(async () => sut.isAcceptableKeymanModifier(values[0] as string) === values[1]);
|
||||
const result = sut.isAcceptableKeymanModifier(values[0] as string);
|
||||
assert.equal(result, values[1]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('map_UkeleleKC_To_VK', function () {
|
||||
describe("map_UkeleleKC_To_VK ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
||||
[
|
||||
[0x00, "K_A"],
|
||||
[0x31, "K_SPACE"],
|
||||
|
|
@ -200,13 +202,15 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[null, ""],
|
||||
].forEach(function (values) {
|
||||
it(("map_UkeleleKC_To_VK(" + values[0] + ")").padEnd(26, " ") + "should return " + "'" + values[1] + "'", async function () {
|
||||
await doesNotReject(async () => sut.map_UkeleleKC_To_VK(values[0] as number) === values[1]);
|
||||
const result = sut.map_UkeleleKC_To_VK(values[0] as number);
|
||||
assert.equal(result, values[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfCapsIsUsed', function () {
|
||||
describe("checkIfCapsIsUsed ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
||||
[
|
||||
[[['caps', 'xxx'], ['yyy']], true],
|
||||
[[['Caps', 'xxx'], ['yyy']], true],
|
||||
|
|
@ -217,20 +221,20 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[[['', ''], ['']], false],
|
||||
[[null], false],
|
||||
].forEach(function (values) {
|
||||
it(("checkIfCapsIsUsed(" + values[0] + ")").padEnd(26, " ") + "should return " + "'" + values[1] + "'", async function () {
|
||||
await doesNotReject(async () => sut.checkIfCapsIsUsed(values[0] as string[][]) === values[1]);
|
||||
it(("checkIfCapsIsUsed([['caps', 'xxx'], ['yyy']])").padEnd(45, " ") + "should return " + "'" + values[1] + "'", async function () {
|
||||
const result = sut.checkIfCapsIsUsed(values[0] as string[][]) === values[1];
|
||||
assert.isTrue(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_Modifier_array__From__KeyModifier_array', 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/Italian.keylayout');
|
||||
const read = sut_r.read(inputFilename);
|
||||
const converted = sut.convert(read);
|
||||
|
||||
// strings as input
|
||||
[[[['0', 0]], [['', 'shift? caps? ']]],
|
||||
[[['0', 1]], [['anyShift caps?', 'shift? rightShift caps? ', 'shift? leftShift caps? ', 'shift leftShift caps ']]],
|
||||
[[['0', 999]], [null]],
|
||||
|
|
@ -242,27 +246,27 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
("get_Modifier_array__From__KeyModifier_array(['" + values[0][0][0] + "', '" + values[0][0][1] + "'])").padEnd(68, " ") + " should return ['" + values[1][0][0] + "', '" + values[1][0][1] + "']" :
|
||||
("get_Modifier_array__From__KeyModifier_array(['" + values[0][0][0] + "', '" + values[0][0][1] + "'])").padEnd(68, " ") + " should return ['" + values[1][0] + "']", async function () {
|
||||
const result = sut.get_Modifier_array__From__KeyModifier_array(converted.arrayOf_Modifiers, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.deepStrictEqual(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
// null, undefined or empty as input
|
||||
[[[[null]], [null]],
|
||||
[[[undefined]], [null]],
|
||||
[[[]], [null]],
|
||||
].forEach(function (values) {
|
||||
it(("get_Modifier_array__From__KeyModifier_array([" + values[0][0] + "])").padEnd(68, " ") + " should return ['" + values[1][0] + "']", async function () {
|
||||
const result = sut.get_Modifier_array__From__KeyModifier_array(converted.arrayOf_Modifiers, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.deepStrictEqual(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_KeyModifier_array__From__ActionID', function () {
|
||||
describe("get_KeyModifier_array__From__ActionID ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const read = sut_r.read(inputFilename);
|
||||
|
||||
[
|
||||
["a16", [['32', 3]]],
|
||||
["a19", [['45', 3]]],
|
||||
|
|
@ -273,6 +277,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[" ", []],
|
||||
["", []],
|
||||
].forEach(function (values) {
|
||||
|
||||
let outstring = "[ ";
|
||||
for (let i = 0; i < values[1].length; i++) {
|
||||
outstring = outstring + "[ '" + values[1][i][0] + "', " + values[1][i][1].toString() + "], ";
|
||||
|
|
@ -280,16 +285,17 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
|
||||
it(("get_KeyModifier_array__From__ActionID('" + values[0] + "')").padEnd(57, " ") + ' should return ' + outstring.substring(0, outstring.lastIndexOf(']') + 2) + " ]", async function () {
|
||||
const result = sut.get_KeyModifier_array__From__ActionID(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_ActionID__From__ActionNext', function () {
|
||||
describe("get_ActionID__From__ActionNext ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const read = sut_r.read(inputFilename);
|
||||
|
||||
[
|
||||
["none", ""],
|
||||
["a18", ""],
|
||||
|
|
@ -306,12 +312,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(("get_ActionID__From__ActionNext('" + values[0] + "')").padEnd(49, " ") + ' should return ' + "'" + values[1] + "'", async function () {
|
||||
const result = sut.get_ActionID__From__ActionNext(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_ActionIndex__From__ActionId', function () {
|
||||
describe("get_ActionIndex__From__ActionId ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -331,12 +337,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(("get_ActionIndex__From__ActionId('" + values[0] + "')").padEnd(50, " ") + ' should return ' + values[1], async function () {
|
||||
const result = sut.get_ActionIndex__From__ActionId(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_Output__From__ActionId_None', function () {
|
||||
describe("get_Output__From__ActionId_None ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -351,7 +357,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
it(
|
||||
("get_Output__From__ActionId_None('" + values[0] + "')").padEnd(56, " ") + ' should return ' + "'" + values[1] + "'", async function () {
|
||||
const result = sut.get_Output__From__ActionId_None(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -361,12 +367,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(("get_Output__From__ActionId_None('" + values[0] + "')").padEnd(56, " ") + ' should return ' + values[1], async function () {
|
||||
const result = sut.get_Output__From__ActionId_None(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array', function () {
|
||||
describe("get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -428,7 +434,6 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
['K_A', 'a9', '0', 'NCAPS', 'â']
|
||||
];
|
||||
|
||||
// for non-empty/undefined/null and isCaps_used = true
|
||||
[[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', '']]],
|
||||
|
|
@ -439,6 +444,7 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
[[['', 'K_SPACE', 'a0', '0', 'ˆ']], [['K_SPACE', 'a0', '0', 'NCAPS', 'ˆ']]],
|
||||
[[['', '', '', '', '']], [['', '', '', 'NCAPS', '']]],
|
||||
].forEach(function (values) {
|
||||
|
||||
const isCaps_used = true;
|
||||
const string_in = "get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array(['" + "', '" + values[0][0][0] + "', '" + values[0][0][1] + "', '" + values[0][0][2] + "', '" + values[0][0][3] + "', '" + values[0][0][4] + "'])";
|
||||
const string_out = "['" + "', '" + values[1][0][0] + "', '" + values[1][0][1] + "', '" + values[1][0][2] + "', '" + values[1][0][3] + "', '" + values[1][0][4] + "']";
|
||||
|
|
@ -446,27 +452,26 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
it((JSON.stringify(values[1]).length > 60) ? 'an array of objects should return an array of objectss' :
|
||||
string_in.padEnd(74, " ") + ' should return ' + string_out, async function () {
|
||||
const result = sut.get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array(read, values[0], isCaps_used);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
// for non-empty/undefined/null and isCaps_used = false
|
||||
[[[['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) {
|
||||
|
||||
const isCaps_used = false;
|
||||
const string_in = "get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array(['" + "', '" + values[0][0][0] + "', '" + values[0][0][1] + "', '" + values[0][0][2] + "', '" + values[0][0][3] + "', '" + values[0][0][4] + "'])";
|
||||
const string_out = "['" + "', '" + values[1][0][0] + "', '" + values[1][0][1] + "', '" + values[1][0][2] + "', '" + values[1][0][3] + "', '" + values[1][0][4] + "']";
|
||||
|
||||
it(string_in.padEnd(74, " ") + ' should return ' + string_out, async function () {
|
||||
const result = sut.get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array(read, values[0], isCaps_used);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
// for empty/undefined/null
|
||||
[[[], []],
|
||||
[undefined, []],
|
||||
[null, []],
|
||||
|
|
@ -474,12 +479,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
const isCaps = true;
|
||||
it(("get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array([" + values[0] + "])").padEnd(74, " ") + ' should return ' + "[" + values[1] + "]", async function () {
|
||||
const result = sut.get_KeyMBehaviourModOutputArray__from__KeyActionBehaviourOutput_array(read, values[0], isCaps);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_ActionStateOutput_array__From__ActionState', function () {
|
||||
describe("get_ActionStateOutput_array__From__ActionState ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -520,12 +525,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
("get_ActionStateOutput_array__From__ActionState('" + values[0] + "')").padEnd(60, " ") + ' should return an array of objects' :
|
||||
("get_ActionStateOutput_array__From__ActionState('" + values[0] + "')").padEnd(60, " ") + ' should return ' + "'" + JSON.stringify(values[1]) + "'", async function () {
|
||||
const result = sut.get_ActionStateOutput_array__From__ActionState(read, String(values[0]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput', function () {
|
||||
describe("get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
|
|
@ -557,12 +562,12 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
("get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return an array of objects' :
|
||||
("get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput('" + values[0] + "', '" + values[1] + "', " + values[2] + ")").padEnd(67, " ") + ' should return ' + "'" + JSON.stringify(values[3]) + "'", async function () {
|
||||
const result = sut.get_ActionOutputBehaviourKeyModi_From__ActionIDStateOutput(read, converted.arrayOf_Modifiers, String(values[0]), String(values[1]), Boolean(values[2]));
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[3]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[3]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_KeyActionOutput_array__From__ActionStateOutput_array', 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/Italian.keylayout');
|
||||
|
|
@ -610,11 +615,11 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(("get_KeyActionOutput_array__From__ActionStateOutput_array([['" + values[0][0][0] + "', '" + values[0][0][1] + "', '" + values[0][0][2] + "'],..])").padEnd(73, " ") + ' should return an array of objects', async function () {
|
||||
const result = sut.get_KeyActionOutput_array__From__ActionStateOutput_array(read, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//-----------------
|
||||
const oneEntryResult = [
|
||||
["49", "K_SPACE", "a0", "0", "ˆ"],
|
||||
["49", "K_SPACE", "a0", "1", "ˆ"],
|
||||
|
|
@ -640,30 +645,31 @@ describe('KeylayoutToKmnConverter', function () {
|
|||
].forEach(function (values) {
|
||||
it(("get_KeyActionOutput_array__From__ActionStateOutput_array(['" + values[0][0][0] + "', '" + values[0][0][1] + "', '" + values[0][0][2] + "'])").padEnd(73, " ") + ' should return an array of objects', async function () {
|
||||
const result = sut.get_KeyActionOutput_array__From__ActionStateOutput_array(read, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------
|
||||
[[[['', '1', 'ˆ']], []],
|
||||
[[['', '', '']], []],
|
||||
[[[' ', ' ', '']], []],
|
||||
].forEach(function (values) {
|
||||
it(("get_KeyActionOutput_array__From__ActionStateOutput_array(['" + values[0][0][0] + "', '" + values[0][0][1] + "', '" + values[0][0][2] + "'])").padEnd(73, " ") + ' should return ' + "'[" + values[1] + "]'", async function () {
|
||||
const result = sut.get_KeyActionOutput_array__From__ActionStateOutput_array(read, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------
|
||||
[[[], []],
|
||||
[undefined, []],
|
||||
[null, []],
|
||||
].forEach(function (values) {
|
||||
it(("get_KeyActionOutput_array__From__ActionStateOutput_array(" + values[0] + ")").padEnd(73, " ") + ' should return ' + "'[" + values[1] + "]'", async function () {
|
||||
const result = sut.get_KeyActionOutput_array__From__ActionStateOutput_array(read, values[0]);
|
||||
await doesNotReject(async () => JSON.stringify(result) === JSON.stringify(values[1]));
|
||||
assert.equal(JSON.stringify(result), JSON.stringify(values[1]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
*/
|
||||
|
||||
import 'mocha';
|
||||
import { assert } from 'chai';
|
||||
import { compilerTestCallbacks, makePathToFixture } from './helpers/index.js';
|
||||
import { KeylayoutFileReader } from '../src/keylayout-to-kmn/keylayout-file-reader.js';
|
||||
import { doesNotReject } from "node:assert";
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
describe('KeylayoutFileReader', function () {
|
||||
|
||||
|
|
@ -17,32 +18,39 @@ describe('KeylayoutFileReader', function () {
|
|||
compilerTestCallbacks.clear();
|
||||
});
|
||||
|
||||
describe('read()', function () {
|
||||
describe("read() ", function () {
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const empty: any = [];
|
||||
const inputFilename_unavailable = makePathToFixture('X.keylayout');
|
||||
|
||||
it('read() should return filled array on correct input', async function () {
|
||||
await doesNotReject(async () => (sut_r.read(makePathToFixture('../data/Italian.keylayout'))));
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const result = sut_r.read(inputFilename);
|
||||
assert.isNotEmpty(result);
|
||||
});
|
||||
|
||||
it('read() should return empty array on null input', async function () {
|
||||
await doesNotReject(async () => (Array.isArray(sut_r.read(null)) === Array.isArray(empty)));
|
||||
it('read() should return empty array on null input', async function () {
|
||||
const result = sut_r.read(null);
|
||||
assert.isEmpty(result);
|
||||
});
|
||||
|
||||
it('read() should return empty array on empty input', async function () {
|
||||
await doesNotReject(async () => (Array.isArray(sut_r.read("")) === Array.isArray(empty)));
|
||||
it('read() should return empty array on empty input', async function () {
|
||||
const result = sut_r.read("");
|
||||
assert.isEmpty(result);
|
||||
});
|
||||
|
||||
it('read() should return empty array on space as input', async function () {
|
||||
await doesNotReject(async () => (Array.isArray(sut_r.read(" ")) === Array.isArray(empty)));
|
||||
it('read() should return empty array on space as input', async function () {
|
||||
const result = sut_r.read(" ");
|
||||
assert.isEmpty(result);
|
||||
});
|
||||
|
||||
it('read() should return empty array on unavailable file name', async function () {
|
||||
await doesNotReject(async () => (Array.isArray(sut_r.read(makePathToFixture('Unavailable_InputFilename.keylayout'))) === empty));
|
||||
it('read() should return empty array on unavailable file name', async function () {
|
||||
const result = sut_r.read(inputFilename_unavailable);
|
||||
assert.isEmpty(result);
|
||||
});
|
||||
|
||||
it('read() should return empty array on typo in path', async function () {
|
||||
await doesNotReject(async () => (Array.isArray(sut_r.read(makePathToFixture('../data|Italian.keylayout'))) === empty));
|
||||
it('read() should return empty array on typo in path', async function () {
|
||||
const result = sut_r.read('../data|Italian.keylayout');
|
||||
assert.isEmpty(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,15 +6,12 @@
|
|||
*/
|
||||
|
||||
import 'mocha';
|
||||
import { assert } from 'chai';
|
||||
import { util } from '@keymanapp/common-types';
|
||||
import { compilerTestCallbacks, compilerTestOptions, makePathToFixture } from './helpers/index.js';
|
||||
import { KeylayoutToKmnConverter } from '../src/keylayout-to-kmn/keylayout-to-kmn-converter.js';
|
||||
import { KmnFileWriter } from '../src/keylayout-to-kmn/kmn-file-writer.js';
|
||||
import { KeylayoutFileReader } from '../src/keylayout-to-kmn/keylayout-file-reader.js';
|
||||
import { doesNotReject } from 'node:assert';
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
describe('KmnFileWriter', function () {
|
||||
|
||||
|
|
@ -22,7 +19,7 @@ describe('KmnFileWriter', function () {
|
|||
compilerTestCallbacks.clear();
|
||||
});
|
||||
|
||||
describe('write()', function () {
|
||||
describe("write() ", function () {
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
|
|
@ -36,15 +33,18 @@ describe('KmnFileWriter', function () {
|
|||
const converted_unavailable = sut.convert(read_unavailable);
|
||||
|
||||
it('write() should return true (no error) if written', async function () {
|
||||
await doesNotReject(async () => sut_w.write(converted));
|
||||
const result = sut_w.write(converted);
|
||||
assert.isTrue(result);
|
||||
});
|
||||
|
||||
it('write() should return false if no inputfile', async function () {
|
||||
await doesNotReject(async () => sut_w.write(converted_unavailable) === false);
|
||||
const result = sut_w.write(converted_unavailable);
|
||||
assert.isFalse(result);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('writeData_Rules()', function () {
|
||||
describe("writeData_Rules() ", function () {
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
|
|
@ -58,16 +58,18 @@ describe('KmnFileWriter', function () {
|
|||
const converted_unavailable = sut.convert(read_unavailable);
|
||||
|
||||
it('writeData_Rules() should return true (no error) if written', async function () {
|
||||
await doesNotReject(async () => sut_w.writeData_Rules(converted).length > 0);
|
||||
const result = sut_w.writeData_Rules(converted);
|
||||
assert.isTrue(result.length > 0);
|
||||
});
|
||||
|
||||
it('writeData_Rules() should return false if no inputfile', async function () {
|
||||
await doesNotReject(async () => sut_w.writeData_Rules(converted_unavailable).length > 0);
|
||||
const result = sut_w.writeData_Rules(converted_unavailable);
|
||||
assert.isFalse(result.length > 0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('writeData_Stores() ', function () {
|
||||
describe("writeData_Stores() ", function () {
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
const sut_w = new KmnFileWriter(compilerTestCallbacks, compilerTestOptions);
|
||||
|
|
@ -107,22 +109,21 @@ describe('KmnFileWriter', function () {
|
|||
|
||||
it(('writeData_Stores should return store text with filename ').padEnd(62, " ") + 'on correct input', async function () {
|
||||
const written_correctName = sut_w.writeData_Stores(converted);
|
||||
await doesNotReject(async () => (written_correctName === (out_expected_first + converted.keylayout_filename + out_expected_last)));
|
||||
assert.equal(written_correctName, (out_expected_first + converted.keylayout_filename + out_expected_last));
|
||||
});
|
||||
|
||||
it(('writeData_Stores should return store text without filename ').padEnd(62, " ") + 'on empty input', async function () {
|
||||
const written_emptyName = sut_w.writeData_Stores(converted_empty);
|
||||
await doesNotReject(async () => (written_emptyName === (out_expected_first + out_expected_last)));
|
||||
|
||||
assert.equal(written_emptyName, (out_expected_first + out_expected_last));
|
||||
});
|
||||
|
||||
it(('writeData_Stores should return store text without filename ').padEnd(62, " ") + 'on only filename as input', async function () {
|
||||
const written_onlyName = sut_w.writeData_Stores(converted_unavailable);
|
||||
await doesNotReject(async () => (written_onlyName === (out_expected_first + converted_unavailable.keylayout_filename + out_expected_last)));
|
||||
assert.equal(written_onlyName, (out_expected_first + converted_unavailable.keylayout_filename + out_expected_last));
|
||||
});
|
||||
});
|
||||
|
||||
describe('reviewRules() ', function () {
|
||||
describe("reviewRules() ", function () {
|
||||
const inputFilename = makePathToFixture('../data/Italian.keylayout');
|
||||
const sut = new KeylayoutToKmnConverter(compilerTestCallbacks, compilerTestOptions);
|
||||
const sut_r = new KeylayoutFileReader(compilerTestCallbacks);
|
||||
|
|
@ -135,12 +136,14 @@ describe('KmnFileWriter', function () {
|
|||
const read_unavailable = sut_r.read(inputFilename_unavailable);
|
||||
const converted_unavailable = sut.convert(read_unavailable);
|
||||
|
||||
it('reviewRules() should return true (no error) if written', async function () {
|
||||
await doesNotReject(async () => sut_w.write(converted));
|
||||
it('write() should return true (no error) if written', async function () {
|
||||
const result = sut_w.write(converted);
|
||||
assert.isTrue(result);
|
||||
});
|
||||
|
||||
it('reviewRules() should return false if no inputfile', async function () {
|
||||
await doesNotReject(async () => !sut_w.write(converted_unavailable));
|
||||
it('write() should return false if no inputfile', async function () {
|
||||
const result = sut_w.write(converted_unavailable);
|
||||
assert.isFalse(result);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -167,7 +170,8 @@ describe('KmnFileWriter', function () {
|
|||
[' ;', ' ;']
|
||||
].forEach(function (values) {
|
||||
it(('should convert "' + values[0] + '"').padEnd(25, " ") + 'to "' + values[1] + '"', async function () {
|
||||
await doesNotReject(async () => util.convertToUnicodeCodePoint(values[0] as string) === values[1]);
|
||||
const result = util.convertToUnicodeCodePoint(values[0] as string);
|
||||
assert.equal(result, values[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue