Checkpoint web parity through Chromium input tasks
This commit is contained in:
29
web/tests/unit/ime-composition.test.mjs
Normal file
29
web/tests/unit/ime-composition.test.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import ts from "../../node_modules/typescript/lib/typescript.js";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "../../..");
|
||||
const sourcePath = path.join(root, "web/protocol/ime-composition.ts");
|
||||
const output = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
|
||||
assert.deepEqual(output.diagnostics, []);
|
||||
const ime = await import(`data:text/javascript;base64,${Buffer.from(output.outputText).toString("base64")}`);
|
||||
|
||||
test("M14-04D blocks operators through composition start/update and reopens after end", () => {
|
||||
let state = ime.createIMECompositionState();
|
||||
assert.equal(ime.shouldBlockOperatorShortcuts(state), false);
|
||||
state = ime.reduceIMEComposition(state, { type: "compositionstart", data: "n" });
|
||||
assert.equal(ime.shouldBlockOperatorShortcuts(state), true);
|
||||
state = ime.reduceIMEComposition(state, { type: "compositionupdate", data: "ni" });
|
||||
assert.deepEqual([state.composing, state.pendingText, state.lastEvent], [true, "ni", "UPDATE"]);
|
||||
state = ime.reduceIMEComposition(state, { type: "compositionend", data: "你" });
|
||||
assert.equal(ime.shouldBlockOperatorShortcuts(state), false);
|
||||
assert.equal(ime.shouldBlockOperatorShortcuts(state, true), true);
|
||||
});
|
||||
|
||||
test("M14-04D ignores stray updates and rejects malformed state", () => {
|
||||
let state = ime.createIMECompositionState();
|
||||
assert.equal(ime.reduceIMEComposition(state, { type: "compositionupdate", data: "x" }), state);
|
||||
assert.throws(() => ime.shouldBlockOperatorShortcuts({ schemaVersion: 2 }), /IME_STATE_INVALID/);
|
||||
});
|
||||
Reference in New Issue
Block a user