Skip to content

Commit

Permalink
chore(common/web): adjust initVisualKeyboardKey() and checkBuilderKvk…
Browse files Browse the repository at this point in the history
…Key() to cope with some null inputs
  • Loading branch information
markcsinclair committed Dec 3, 2024
1 parent 2493e2b commit c0beb22
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions common/web/types/test/kvk/test-kvk-file-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ function initVisualKeyboard(

function initVisualKeyboardKey(
index: number,
flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap,
flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap,
shift: BUILDER_KVK_SHIFT_STATE = BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL,
text: string = "text",
bitmap: number[] = null,
): VisualKeyboardKey {
const vkk: VisualKeyboardKey = {
flags: flags,
shift: shift,
vkey: index,
text: "text",
bitmap: new Uint8Array([index]),
text: text,
bitmap: bitmap ? new Uint8Array(bitmap) : null,
};
return vkk;
}
Expand Down Expand Up @@ -186,7 +188,16 @@ function checkBuilderKvkKey(target: BUILDER_KVK_KEY, source: VisualKeyboardKey)
assert.equal(target.flags, source.flags);
assert.equal(target.shift, source.shift);
assert.equal(target.vkey, source.vkey);
assert.deepEqual(target.text.str, source.text);
assert.equal(target.bitmapSize, source.bitmap.byteLength);
assert.deepEqual(target.bitmapData, Array.from(source.bitmap));
if (source.text != null) {
assert.deepEqual(target.text.str, source.text);
} else {
assert.deepEqual(target.text.str, '');
}
if (source.bitmap != null) {
assert.equal(target.bitmapSize, source.bitmap.byteLength);
assert.deepEqual(target.bitmapData, Array.from(source.bitmap));
} else {
assert.equal(target.bitmapSize, 0);
assert.deepEqual(target.bitmapData, []);
}
}

0 comments on commit c0beb22

Please sign in to comment.