From e08fd5e389780b18f614e4d77a470eed6af181ee Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 16 Jan 2022 15:13:02 +0100 Subject: [PATCH] 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. --- test/unit/unicode_spec.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/test/unit/unicode_spec.js b/test/unit/unicode_spec.js index dd544c743fb38..f9fd2a0cb9499 100644 --- a/test/unit/unicode_spec.js +++ b/test/unit/unicode_spec.js @@ -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;