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

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

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions test/unit/unicode_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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;

Expand Down