Merge pull request #14457 from timvandermeij/unicode-test

Implement a unit test for `getCharUnicodeCategory` in `src/core/unicode.js` (PR 14428 follow-up)
This commit is contained in:
Tim van der Meij 2022-01-16 15:40:26 +01:00 committed by GitHub
commit f955b0e20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,16 +14,17 @@
*/
import {
getDingbatsGlyphsUnicode,
getGlyphsUnicode,
} from "../../src/core/glyphlist.js";
import {
getCharUnicodeCategory,
getNormalizedUnicodes,
getUnicodeForGlyph,
getUnicodeRangeFor,
mapSpecialUnicodeValues,
reverseIfRtl,
} from "../../src/core/unicode.js";
import {
getDingbatsGlyphsUnicode,
getGlyphsUnicode,
} from "../../src/core/glyphlist.js";
describe("unicode", function () {
describe("mapSpecialUnicodeValues", function () {
@ -42,6 +43,30 @@ describe("unicode", function () {
});
});
describe("getCharUnicodeCategory", function () {
it("should correctly determine the character category", function () {
const tests = {
// Whitespace
" ": { isDiacritic: false, isWhitespace: true },
"\t": { isDiacritic: false, isWhitespace: true },
"\u2001": { isDiacritic: false, isWhitespace: true },
"\uFEFF": { isDiacritic: false, isWhitespace: true },
// Diacritic
"\u0302": { isDiacritic: true, isWhitespace: false },
"\u0344": { isDiacritic: true, isWhitespace: false },
"\u0361": { isDiacritic: true, isWhitespace: false },
// No whitespace or diacritic
a: { isDiacritic: false, isWhitespace: false },
1: { isDiacritic: false, isWhitespace: false },
};
for (const [character, expectation] of Object.entries(tests)) {
expect(getCharUnicodeCategory(character)).toEqual(expectation);
}
});
});
describe("getUnicodeForGlyph", function () {
let standardMap, dingbatsMap;