feat(developer): improve validation and gap/switch 🙀

- keys: error if to, gap, AND switch are missing
- add parts to LKKey
- add err message and test case

#7401
This commit is contained in:
Steven R. Loomis 2022-11-01 16:55:58 -05:00
parent a212aefeec
commit 77f8f41c21
6 changed files with 69 additions and 0 deletions

View file

@ -71,6 +71,8 @@ export interface LKKeys {
export interface LKKey {
id?: string;
to?: string;
gap?: boolean;
switch?: string;
};
export interface LKLayers {

View file

@ -38,6 +38,11 @@ export class KeysCompiler extends SectionCompiler {
valid = false;
continue;
}
if (!keydef.to && !keydef.gap && !keydef.switch) {
this.callbacks.reportMessage(CompilerMessages.Error_KeyMissingToGapOrSwitch({keyId: key}));
valid = false;
continue;
}
}
}

View file

@ -77,6 +77,10 @@ export class CompilerMessages {
m(this.ERROR_DisplayIsRepeated, `display to='${o.to}' has more than one display entry.`);
static ERROR_DisplayIsRepeated = SevError | 0x0010;
static Error_KeyMissingToGapOrSwitch = (o:{keyId: string}) =>
m(this.ERROR_KeyMissingToGapOrSwitch, `key id='${o.keyId}' must have either to=, gap=, or switch=.`);
static ERROR_KeyMissingToGapOrSwitch = SevError | 0x0011;
static severityName(code: number): string {
let severity = code & CompilerErrorSeverity.Severity_Mask;
switch(severity) {

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard SYSTEM "../../../../../../../resources/standards-data/ldml-keyboards/techpreview/dtd/ldmlKeyboard.dtd">
<keyboard locale="mt" conformsTo="techpreview">
<names>
<name value="hardware-gap-switch" />
</names>
<keys>
<key id="Q" gap="true" />
<key id="W" switch="shift" />
<key id="q" to="q" />
<key id="w" to="w" />
</keys>
<layers form="hardware">
<layer id="base">
<!-- beware: this is mapping ` and 1! -->
<row keys="Q W" />
</layer>
<layer id="shift">
<!-- beware: this is mapping ` and 1! -->
<row keys="q w" />
</layer>
</layers>
</keyboard>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard SYSTEM "../../../../../../../resources/standards-data/ldml-keyboards/techpreview/dtd/ldmlKeyboard.dtd">
<keyboard locale="mt" conformsTo="techpreview">
<names>
<name value="hardware-missing-attrs" />
</names>
<keys>
<key id="Q" /> <!-- missing to, gap, and switch -->
</keys>
<layers form="hardware">
<layer id="base">
<!-- beware: this is mapping `! -->
<row keys="Q" />
</layer>
</layers>
</keyboard>

View file

@ -55,4 +55,17 @@ describe('keys', function () {
assert.deepEqual(compilerTestCallbacks.messages[0], CompilerMessages.Error_KeyNotFoundInKeyBag({col: 1, form: 'hardware', keyId: 'foo', layer: 'base', row: 1}));
});
it('should reject layouts with invalid keys', function() {
let keys = loadSectionFixture(KeysCompiler, 'sections/keys/invalid-key-missing-attrs.xml', compilerTestCallbacks) as Keys;
assert.isNull(keys);
assert.equal(compilerTestCallbacks.messages.length, 1);
assert.deepEqual(compilerTestCallbacks.messages[0], CompilerMessages.Error_KeyMissingToGapOrSwitch({keyId: 'Q'}));
});
it('should accept layouts with gap/switch keys', function() {
let keys = loadSectionFixture(KeysCompiler, 'sections/keys/gap-switch.xml', compilerTestCallbacks) as Keys;
assert.isNotNull(keys);
assert.equal(compilerTestCallbacks.messages.length, 0);
assert.equal(keys.keys.length, 2);
});
});