diff --git a/developer/src/kmc-keyboard/src/compiler/layr.ts b/developer/src/kmc-keyboard/src/compiler/layr.ts
index beb0dba6f1..ecacf26e8a 100644
--- a/developer/src/kmc-keyboard/src/compiler/layr.ts
+++ b/developer/src/kmc-keyboard/src/compiler/layr.ts
@@ -22,19 +22,14 @@ export class LayrCompiler extends SectionCompiler {
this.callbacks.reportMessage(CompilerMessages.Error_MustBeAtLeastOneLayerElement());
}
let hardwareLayers = 0;
- let touchLayers = 0;
this.keyboard.layers.forEach(({ hardware, form }) => {
// TODO-LDML: in the future >1 hardware layer may be allowed, check for duplicates
if (form === 'touch') {
- touchLayers++;
if (hardware) {
valid = false;
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({
errorText: `Not allowed: hardware="${hardware}" with layers form="touch"`
}));
- } else if (touchLayers > 1) { // TODO-LDML: revisit if spec changes
- valid = false;
- this.callbacks.reportMessage(CompilerMessages.Error_MustHaveAtMostOneLayersElementPerForm({ form }));
}
} else if (form === 'hardware') {
hardwareLayers++;
@@ -53,6 +48,7 @@ export class LayrCompiler extends SectionCompiler {
this.callbacks.reportMessage(CompilerMessages.Error_MustHaveAtMostOneLayersElementPerForm({ form }));
}
} else {
+ // Should not be reached due to XML validation.
valid = false;
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({
errorText: `Invalid form="${form}" on layers element`
diff --git a/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-form.xml b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-form.xml
new file mode 100644
index 0000000000..a6a34242ac
--- /dev/null
+++ b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-form.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-hardware.xml b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-hardware.xml
new file mode 100644
index 0000000000..da079b7483
--- /dev/null
+++ b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-invalid-hardware.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-missing-hardware.xml b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-missing-hardware.xml
new file mode 100644
index 0000000000..a3847a95ca
--- /dev/null
+++ b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-missing-hardware.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-multi-hardware.xml b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-multi-hardware.xml
new file mode 100644
index 0000000000..943c65c196
--- /dev/null
+++ b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-multi-hardware.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-touch-hardware.xml b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-touch-hardware.xml
new file mode 100644
index 0000000000..b39c0c4796
--- /dev/null
+++ b/developer/src/kmc-keyboard/test/fixtures/sections/layr/invalid-touch-hardware.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/developer/src/kmc-keyboard/test/test-layr.ts b/developer/src/kmc-keyboard/test/test-layr.ts
index 4709f5855b..f33d2fca92 100644
--- a/developer/src/kmc-keyboard/test/test-layr.ts
+++ b/developer/src/kmc-keyboard/test/test-layr.ts
@@ -86,4 +86,17 @@ describe('layr', function () {
assert.equal(touch0row0.keys.length, 4);
allKeysOk(touch0row0,'Q q W w', 'touch0row0');
});
+ for (let badcase of ['invalid-hardware', 'missing-hardware', 'multi-hardware', 'touch-hardware']) {
+ it(`should reject invalid: ${badcase}`, function () {
+ let layr = loadSectionFixture(LayrCompiler, `sections/layr/invalid-${badcase}.xml`, compilerTestCallbacks) as Layr;
+ assert.isNull(layr);
+ assert.isAtLeast(compilerTestCallbacks.messages.length, 1);
+ // TODO-LDML: assert specific err cases
+ });
+ }
+ for (let badcase of ['invalid-form']) {
+ it(`should throw on invalid invalid: ${badcase}`, function () {
+ assert.throws(() => loadSectionFixture(LayrCompiler, `sections/layr/invalid-${badcase}.xml`, compilerTestCallbacks));
+ });
+ }
});