-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunicode-script.test.js
More file actions
208 lines (186 loc) · 5.83 KB
/
unicode-script.test.js
File metadata and controls
208 lines (186 loc) · 5.83 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { describe, it, expect } from "vitest";
import {
unicodeScripts,
unicodeScriptCodes,
unicodeScript,
unicodeScriptCode,
unicodeScriptExtensions,
unicodeScriptExtensionCodes,
unicodeAugmentedScriptCodes,
unicodeResolvedScriptCodes,
isMixedScript,
isSingleScript,
listUnicodeScripts,
listUnicodeScriptCodes,
listUnicodeAugmentedScriptCodes,
} from "../src/index.js";
describe("unicodeScripts(string)", () => {
it("will always return a Set", () => {
expect(unicodeScripts("")).toEqual(new Set());
expect(unicodeScripts("A")).toContain("Latin");
});
it("will return all scripts that characters in the string belong to", () => {
expect(unicodeScripts("СC")).toEqual(new Set(["Cyrillic", "Latin"]));
});
it("will return all scripts in sorted order", () => {
expect(unicodeScripts("СA")).toEqual(new Set(["Cyrillic", "Latin"]));
expect(unicodeScripts("AС")).toEqual(new Set(["Cyrillic", "Latin"]));
});
});
describe("unicodeScript(char)", () => {
it("will return script for that character", () => {
expect(unicodeScript("ᴦ")).toEqual("Greek");
expect(unicodeScript("�")).toEqual("Common");
});
it("will return Unknown for characters not in any script (unassigned, invalid, etc.)", () => {
expect(unicodeScript("")).toEqual("Unknown");
});
it("will return undefined for strings that are not string length 1", () => {
expect(unicodeScript("")).toBe(undefined);
expect(unicodeScript("ab")).toBe(undefined);
});
describe("[unicode versions]", () => {
it("works for scripts introduced in Unicode 17", () => {
expect(unicodeScript("")).toEqual("Tai_Yo");
});
})
});
describe("unicodeScriptCodes(string)", () => {
it("will return four letter script codes (ISO 15924)", () => {
expect(unicodeScriptCodes("СC")).toEqual(new Set(["Cyrl", "Latn"]));
});
});
describe("unicodeScriptCode(char)", () => {
it("will return four letter script code (ISO 15924)", () => {
expect(unicodeScriptCode("")).toEqual("Zzzz");
});
});
describe("listUnicodeScripts()", () => {
it("will return a list of all script names", () => {
expect(listUnicodeScripts()).toContain("Inscriptional_Parthian");
expect(listUnicodeScripts()).toContain("Unknown");
});
});
describe("listUnicodeScriptCodes()", () => {
it("will return a list of all script codes", () => {
expect(listUnicodeScriptCodes()).toContain("Egyp");
expect(listUnicodeScriptCodes()).toContain("Zzzz");
});
});
describe("listUnicodeAugmentedScriptCodes()", () => {
it("will return a list of all augmented script codes", () => {
expect(listUnicodeAugmentedScriptCodes()).toEqual(
new Set(["Hanb", "Jpan", "Kore"])
);
});
});
describe("unicodeScriptExtensions(string)", () => {
it("will always return a Set", () => {
expect(unicodeScriptExtensions("")).toEqual(new Set());
});
it("will return all extended scripts that characters in the string belong to", () => {
expect(unicodeScriptExtensions("॥")).toEqual(
new Set([
"Bengali",
"Devanagari",
"Dogra",
"Grantha",
"Gujarati",
"Gunjala_Gondi",
"Gurmukhi",
"Gurung_Khema",
"Kannada",
"Khudawadi",
"Limbu",
"Mahajani",
"Malayalam",
"Masaram_Gondi",
"Nandinagari",
"Ol_Onal",
"Oriya",
"Sinhala",
"Syloti_Nagri",
"Takri",
"Tamil",
"Telugu",
"Tirhuta",
])
);
});
});
describe("unicodeScriptExtensionCodes(string)", () => {
it("will return all extended scripts that characters in the string belong to", () => {
expect(unicodeScriptExtensionCodes("॥")).toEqual(
new Set([
"Beng",
"Deva",
"Dogr",
"Gong",
"Gonm",
"Gran",
"Gujr",
"Gukh",
"Guru",
"Knda",
"Limb",
"Mahj",
"Mlym",
"Nand",
"Onao",
"Orya",
"Sind",
"Sinh",
"Sylo",
"Takr",
"Taml",
"Telu",
"Tirh",
])
);
});
});
describe("unicodeAugmentedScriptCodes(string)", () => {
it("will return all extended scripts that characters in the string belong to + augmented", () => {
expect(unicodeAugmentedScriptCodes("ねガ")).toEqual(
new Set(["Hira", "Kana", "Jpan"])
);
});
it("will replace Common with all scripts", () => {
expect(unicodeAugmentedScriptCodes("1")).toEqual(
new Set([
...listUnicodeScriptCodes(),
...listUnicodeAugmentedScriptCodes(),
])
);
});
});
describe("unicodeResolvedScriptCodes(string)", () => {
it("return intersection of augmented scripts per character", () => {
expect(unicodeResolvedScriptCodes("СігсӀе")).toEqual(new Set(["Cyrl"]));
expect(unicodeResolvedScriptCodes("Сirсlе")).toEqual(new Set());
expect(unicodeResolvedScriptCodes("𝖢𝗂𝗋𝖼𝗅𝖾")).toEqual(
new Set([
...listUnicodeScriptCodes(),
...listUnicodeAugmentedScriptCodes(),
])
);
});
});
describe("isMixedScript(string)", () => {
it("return true if unicodeResolvedScriptCodes(string) is empty", () => {
expect(isMixedScript("СігсӀе")).toEqual(false)
expect(isMixedScript("Сirсlе")).toEqual(true)
expect(isMixedScript("𝖢𝗂𝗋𝖼𝗅𝖾")).toEqual(false)
expect(isMixedScript("1")).toEqual(false)
expect(isMixedScript("ねガ")).toEqual(false)
});
});
describe("isSingleScript(string)", () => {
it("return true if unicodeResolvedScriptCodes(string) is not empty", () => {
expect(isSingleScript("СігсӀе")).toEqual(true)
expect(isSingleScript("Сirсlе")).toEqual(false)
expect(isSingleScript("𝖢𝗂𝗋𝖼𝗅𝖾")).toEqual(true)
expect(isSingleScript("1")).toEqual(true)
expect(isSingleScript("ねガ")).toEqual(true)
});
});