forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunicode-spec.js
161 lines (132 loc) · 5.88 KB
/
unicode-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint max-len:0 */
import Settings from "../src/Settings";
import {scriptFromCodepoint, supportedCodepoint} from "../src/unicodeScripts";
import {strictSettings, nonstrictSettings} from "./helpers";
describe("unicode", function() {
it("should build Latin-1 inside \\text{}", function() {
expect`\text{ÀÁÂÃÄÅÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåèéêëìíîïñòóôõöùúûüýÿÆÇÐØÞßæçðøþ}`
.toBuild();
});
it("should not parse Latin-1 outside \\text{} with strict", function() {
const chars = 'ÀÁÂÃÄÅÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåèéêëìíîïñòóôõöùúûüýÿÇÐÞçþ';
for (const ch of chars) {
expect(ch).not.toParse(strictSettings);
}
});
it("should build Latin-1 outside \\text{}", function() {
expect`ÀÁÂÃÄÅÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåèéêëìíîïñòóôõöùúûüýÿÇÐÞçðþ`
.toBuild(nonstrictSettings);
});
it("should build all lower case Greek letters", function() {
expect`αβγδεϵζηθϑικλμνξοπϖρϱςστυφϕχψω`.toBuild();
});
it("should build math upper case Greek letters", function() {
expect`ΓΔΘΛΞΠΣΥΦΨΩ`.toBuild();
});
it("should build Cyrillic inside \\text{}", function() {
expect`\text{БГДЖЗЙЛФЦШЫЮЯ}`.toBuild();
});
it("should build Cyrillic outside \\text{}", function() {
expect`БГДЖЗЙЛФЦШЫЮЯ`.toBuild(nonstrictSettings);
});
it("should not parse Cyrillic outside \\text{} with strict", function() {
expect`БГДЖЗЙЛФЦШЫЮЯ`.not.toParse(strictSettings);
});
it("should build CJK inside \\text{}", function() {
expect`\text{私はバナナです}`.toBuild();
expect`\text{여보세요}`.toBuild();
});
it("should build CJK outside \\text{}", function() {
expect`私はバナナです`.toBuild(nonstrictSettings);
expect`여보세요`.toBuild(nonstrictSettings);
});
it("should not parse CJK outside \\text{} with strict", function() {
expect`私はバナナです。`.not.toParse(strictSettings);
expect`여보세요`.not.toParse(strictSettings);
});
it("should build Devangari inside \\text{}", function() {
expect`\text{नमस्ते}`.toBuild();
});
it("should build Devangari outside \\text{}", function() {
expect`नमस्ते`.toBuild(nonstrictSettings);
});
it("should not parse Devangari outside \\text{} with strict", function() {
expect`नमस्ते`.not.toParse(strictSettings);
});
it("should build Georgian inside \\text{}", function() {
expect`\text{გამარჯობა}`.toBuild();
});
it("should build Georgian outside \\text{}", function() {
expect`გამარჯობა`.toBuild(nonstrictSettings);
});
it("should not parse Georgian outside \\text{} with strict", function() {
expect`გამარჯობა`.not.toParse(strictSettings);
});
it("should build Armenian both inside and outside \\text{}", function() {
expect`ԱԲԳաբգ`.toBuild(nonstrictSettings);
expect`\text{ԱԲԳաբգ}`.toBuild(nonstrictSettings);
});
it("should build extended Latin characters inside \\text{}", function() {
expect`\text{ěščřžůřťďňőİı}`.toBuild();
});
it("should not parse extended Latin outside \\text{} with strict", function() {
expect`ěščřžůřťďňőİı`.not.toParse(strictSettings);
});
it("should not allow emoji in strict mode", function() {
expect`✌`.not.toParse(strictSettings);
expect`\text{✌}`.not.toParse(strictSettings);
const settings = new Settings({
strict: (errorCode) =>
(errorCode === "unknownSymbol" ? "error" : "ignore"),
});
expect`✌`.not.toParse(settings);
expect`\text{✌}`.not.toParse(settings);
});
it("should allow emoji outside strict mode", function() {
expect`✌`.toWarn();
expect`\text{✌}`.toWarn();
const settings = new Settings({
strict: (errorCode) =>
(errorCode === "unknownSymbol" ? "ignore" : "error"),
});
expect`✌`.toParse(settings);
expect`\text{✌}`.toParse(settings);
});
});
describe("unicodeScripts", () => {
const scriptRegExps = {
// eslint-disable-next-line no-misleading-character-class
latin: /[\u0100-\u024f\u0300-\u036f]/,
cyrillic: /[\u0400-\u04ff]/,
armenian: /[\u0530-\u058F]/,
brahmic: /[\u0900-\u109F]/,
georgian: /[\u10a0-\u10ff]/,
cjk: /[\u3000-\u30FF\u4E00-\u9FAF\uFF00-\uFF60]/,
hangul: /[\uAC00-\uD7AF]/,
};
const scriptNames = Object.keys(scriptRegExps);
const allRegExp = new RegExp(
scriptNames.map(script => scriptRegExps[script].source).join('|')
);
it("supportedCodepoint() should return the correct values", () => {
for (let codepoint = 0; codepoint <= 0xffff; codepoint++) {
expect(supportedCodepoint(codepoint)).toBe(
allRegExp.test(String.fromCharCode(codepoint))
);
}
});
it("scriptFromCodepoint() should return correct values", () => {
outer: for (let codepoint = 0; codepoint <= 0xffff; codepoint++) {
const character = String.fromCharCode(codepoint);
const script = scriptFromCodepoint(codepoint);
for (const scriptName of scriptNames) {
if (scriptRegExps[scriptName].test(character)) {
expect(script).toEqual(scriptName);
continue outer;
}
}
expect(script).toBe(null);
expect(supportedCodepoint(codepoint)).toBe(false);
}
});
});