Implement a unit test for getCharUnicodeCategory in src/core/unicode.js (PR 14428 follow-up)

Given that the other functions in this file are already covered by unit
tests, we should also cover this newly added function.
This commit is contained in:
Tim van der Meij 2022-01-16 15:13:02 +01:00
parent 749a3fa699
commit e08fd5e389
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

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;