-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
244 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 80 additions & 66 deletions
146
web/src/engine/keyboard/src/keyboards/keyboardLoadError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,104 @@ | ||
import { type KeyboardStub } from './keyboardLoaderBase.js'; | ||
|
||
export interface KeyboardLoadErrorBuilder { | ||
scriptError(err?: Error): void; | ||
missingError(err: Error): void; | ||
missingKeyboardError(msg: string, err: Error): void; | ||
keyboardDownloadError(msg: string, err: Error): void; | ||
scriptError(err?: Error): void; | ||
missingError(err: Error): void; | ||
keyboardDownloadError(err: Error): void; | ||
|
||
invalidKeyboard(err: Error): void; | ||
} | ||
|
||
export class KeyboardScriptError extends Error { | ||
public readonly cause; | ||
public readonly cause; | ||
|
||
constructor(msg: string, cause?: Error) { | ||
super(msg); | ||
this.cause = cause; | ||
} | ||
constructor(msg: string, cause?: Error) { | ||
super(msg); | ||
this.cause = cause; | ||
} | ||
} | ||
|
||
export class KeyboardMissingError extends Error { | ||
public readonly cause; | ||
public readonly cause; | ||
|
||
constructor(msg: string, cause?: Error) { | ||
super(msg); | ||
this.cause = cause; | ||
} | ||
constructor(msg: string, cause?: Error) { | ||
super(msg); | ||
this.cause = cause; | ||
} | ||
} | ||
|
||
export class KeyboardDownloadError extends Error { | ||
public readonly cause; | ||
public readonly cause; | ||
|
||
constructor(message: string, cause?: Error) { | ||
super(message); | ||
this.cause = cause; | ||
} | ||
constructor(message: string, cause?: Error) { | ||
super(message); | ||
this.cause = cause; | ||
} | ||
} | ||
|
||
export class UriBasedErrorBuilder implements KeyboardLoadErrorBuilder { | ||
readonly uri: string; | ||
|
||
constructor(uri: string) { | ||
this.uri = uri; | ||
} | ||
|
||
missingError(err: Error) { | ||
const msg = `Cannot find the keyboard at ${this.uri}.`; | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
export class InvalidKeyboardError extends Error { | ||
public readonly cause; | ||
|
||
missingKeyboardError(msg: string, err: Error) { | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
|
||
scriptError(err: Error) { | ||
const msg = `Error registering the keyboard script at ${this.uri}; it may contain an error.`; | ||
return new KeyboardScriptError(msg, err); | ||
} | ||
constructor(message: string, cause?: Error) { | ||
super(message); | ||
this.cause = cause; | ||
} | ||
} | ||
|
||
keyboardDownloadError(msg: string, err: Error) { | ||
return new KeyboardDownloadError(msg, err); | ||
} | ||
export class UriBasedErrorBuilder implements KeyboardLoadErrorBuilder { | ||
readonly uri: string; | ||
|
||
constructor(uri: string) { | ||
this.uri = uri; | ||
} | ||
|
||
missingError(err: Error) { | ||
const msg = `Cannot find the keyboard at ${this.uri}.`; | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
|
||
scriptError(err: Error) { | ||
const msg = `Error registering the keyboard script at ${this.uri}; it may contain an error.`; | ||
return new KeyboardScriptError(msg, err); | ||
} | ||
|
||
keyboardDownloadError(err: Error) { | ||
const msg = `Unable to download keyboard at ${this.uri}`; | ||
return new KeyboardDownloadError(msg, err); | ||
} | ||
|
||
invalidKeyboard(err: Error) { | ||
const msg = `${this.uri} is not a valid keyboard file`; | ||
return new InvalidKeyboardError(msg, err); | ||
} | ||
} | ||
|
||
export class StubBasedErrorBuilder implements KeyboardLoadErrorBuilder { | ||
readonly stub: KeyboardStub; | ||
|
||
constructor(stub: KeyboardStub) { | ||
this.stub = stub; | ||
} | ||
|
||
missingError(err: Error) { | ||
const stub = this.stub; | ||
const msg = `Cannot find the ${stub.name} keyboard for ${stub.langName} at ${stub.filename}.`; | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
|
||
missingKeyboardError(msg: string, err: Error) { | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
|
||
scriptError(err: Error) { | ||
const stub = this.stub; | ||
const msg = `Error registering the ${stub.name} keyboard for ${stub.langName}; keyboard script at ${stub.filename} may contain an error.`; | ||
return new KeyboardScriptError(msg, err); | ||
} | ||
|
||
keyboardDownloadError(msg: string, err: Error) { | ||
return new KeyboardDownloadError(msg, err); | ||
} | ||
readonly stub: KeyboardStub; | ||
|
||
constructor(stub: KeyboardStub) { | ||
this.stub = stub; | ||
} | ||
|
||
missingError(err: Error) { | ||
const stub = this.stub; | ||
const msg = `Cannot find the ${stub.name} keyboard for ${stub.langName} at ${stub.filename}.`; | ||
return new KeyboardMissingError(msg, err); | ||
} | ||
|
||
scriptError(err: Error) { | ||
const stub = this.stub; | ||
const msg = `Error registering the ${stub.name} keyboard for ${stub.langName}; keyboard script at ${stub.filename} may contain an error.`; | ||
return new KeyboardScriptError(msg, err); | ||
} | ||
|
||
keyboardDownloadError(err: Error) { | ||
const msg = `Unable to download ${this.stub.name} keyboard for ${this.stub.langName}`; | ||
return new KeyboardDownloadError(msg, err); | ||
} | ||
|
||
invalidKeyboard(err: Error) { | ||
const msg = `${this.stub.name} is not a valid keyboard`; | ||
return new InvalidKeyboardError(msg, err); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
web/src/test/auto/headless/engine/keyboard/keyboard.tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { assert } from 'chai'; | ||
|
||
import { createRequire } from 'module'; | ||
const require = createRequire(import.meta.url); | ||
|
||
import { KeyboardHarness, MinimalKeymanGlobal, DeviceSpec } from 'keyman/engine/keyboard'; | ||
import { NodeKeyboardLoader } from 'keyman/engine/keyboard/node-keyboard-loader'; | ||
|
||
|
||
describe('Keyboard tests', function () { | ||
const khmerPath = require.resolve('@keymanapp/common-test-resources/keyboards/khmer_angkor.js'); | ||
|
||
it('accurately determines layout properties', async () => { | ||
// -- START: Standard Recorder-based unit test loading boilerplate -- | ||
const harness = new KeyboardHarness({}, MinimalKeymanGlobal); | ||
const keyboardLoader = new NodeKeyboardLoader(harness); | ||
const km_keyboard = await keyboardLoader.loadKeyboardFromPath(khmerPath); | ||
// -- END: Standard Recorder-based unit test loading boilerplate -- | ||
|
||
// `khmer_angkor` - supports longpresses, but not flicks or multitaps. | ||
|
||
// Phone supports longpress if the keyboard supports it. | ||
const mobileLayout = km_keyboard.layout(DeviceSpec.FormFactor.Phone); | ||
assert.isTrue(mobileLayout.hasLongpresses); | ||
assert.isFalse(mobileLayout.hasFlicks); | ||
assert.isFalse(mobileLayout.hasMultitaps); | ||
|
||
// Desktop doesn't support longpress even if the keyboard supports it. | ||
const desktopLayout = km_keyboard.layout(DeviceSpec.FormFactor.Desktop); | ||
assert.isFalse(desktopLayout.hasLongpresses); | ||
assert.isFalse(desktopLayout.hasFlicks); | ||
assert.isFalse(desktopLayout.hasMultitaps); | ||
}); | ||
}); |
Oops, something went wrong.