spiegel-keyman/developer/src/kmc-model/test/punctuation.tests.ts
Marc Durdin 529a49431e maint(developer): make TestCompilerCallbacks usage more consistent and simplify
Simplify usage of `TestCompilerCallbacks` by making it responsible for
the `beforeEach` and `afterEach` incantations itself. There are a couple
of more complex usages of `TestCompilerCallbacks` which have been
excluded from this change on purpose.

Renamed `testCallbacks` to `callbacks` in the one place where it was
different.

Hoist @types/node and @types/mocha because inconsistent versions of
@types/mocha were causing compiler errors with this change.

Also added a cast to `fs.readFileSync` to `Uint8Array` to eliminate
compiler warnings/errors in test files.

Fixes: #15654
Test-bot: skip
2026-03-03 16:44:06 +01:00

40 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { LexicalModelCompiler } from '../src/lexical-model-compiler.js';
import {assert} from 'chai';
import 'mocha';
import { makePathToFixture, compileModelSourceCode } from './helpers/index.js';
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
describe('LexicalModelCompiler', function () {
const callbacks = new TestCompilerCallbacks(this);
describe('specifying punctuation', function () {
const MODEL_ID = 'example.qaa.trivial';
const PATH = makePathToFixture(MODEL_ID);
it('should compile punctuation into the generated code', async function () {
const compiler = new LexicalModelCompiler();
assert.isTrue(await compiler.init(callbacks, null));
const code = compiler.generateLexicalModelCode(MODEL_ID, {
format: 'trie-1.0',
sources: ['wordlist.tsv'],
punctuation: {
quotesForKeepSuggestion: { open: `«`, close: `»`},
insertAfterWord: " " , // OGHAM SPACE MARK
}
}, PATH) as string;
// Check that the punctuation actually made into the code:
assert.match(code, /«/);
assert.match(code, /»/);
// Ensure we inserted that OGHAM SPACE MARK!
assert.match(code, /\u1680/);
// Make sure it compiles!
const compilation = compileModelSourceCode(code);
assert.isFalse(compilation.hasSyntaxError);
assert.isNotNull(compilation.exportedModel);
});
})
});