Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(common/web/types): unit tests for unicodeset-parser-api #12714

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*
* Created by Dr Mark C. Sinclair on 2024-11-28
*
* Test code for unicodeset-parser-api.ts
*/

import 'mocha';
import { assert } from 'chai';
import { UnicodeSet } from '../../src/ldml-keyboard/unicodeset-parser-api.js';

class MockUnicodeSet extends UnicodeSet {
constructor(public pattern: string, public ranges: number[][]) {
super(pattern, ranges); // does nothing
this.pattern = pattern;
this.ranges = ranges;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary as you have public in the constructor properties, which does the same thing.

Suggested change
this.pattern = pattern;
this.ranges = ranges;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now with improved knowledge of TS, I can take out the whole MockUnicodeSet.

}
}

describe('Test of Unicode-Parser-API', () => {
describe('Test UnicodeSet', () => {
it('can provide a correct ranges length', () => {
const unicodeSet = new MockUnicodeSet("[ħa-z]", [[0x41, 0x7A], [0x0127, 0x0127]]);
assert.equal(unicodeSet.length, 2);
});
it('can provide a correct string representation', () => {
const unicodeSet = new MockUnicodeSet("[ħa-z]", [[0x41, 0x7A], [0x0127, 0x0127]]);
assert.deepEqual(unicodeSet.toString(), "[ħa-z]");
});
});
});