mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-21 05:17:43 +00:00
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
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
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);
|
||
});
|
||
})
|
||
});
|