-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize.test.ts
73 lines (62 loc) · 1.95 KB
/
normalize.test.ts
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
import { assertStrictEq, assertEquals, prepareTest } from "../test.mod.ts";
import { normalize } from "./mod.ts";
async function willSkipNormalizationForEmptyCharacter() {
assertStrictEq(await normalize(""), "");
}
async function willNormalizeAccentedCharacters() {
const strs = [
"Åland Islands",
"Saint Barthélemy",
"Cocos (Keeling) Islands",
"Côte d'Ivoire",
"Curaçao",
"Réunion"
];
assertEquals(await Promise.all(strs.map(async n => normalize(n))), [
"Aland Islands",
"Saint Barthelemy",
"Cocos (Keeling) Islands",
"Cote d'Ivoire",
"Curacao",
"Reunion"
]);
}
async function willNormalizeAccentedCharactersWithoutUsingNativeFunction() {
const cachedFn = String.prototype.normalize;
String.prototype.normalize = null!;
try {
assertStrictEq(await normalize("Réunion"), "Reunion");
} catch (e) {
throw e;
} finally {
String.prototype.normalize = cachedFn;
}
}
async function willReturnOriginalCharacterWhenNoMatchFound() {
assertStrictEq(await normalize("2 ÷ 2 = 1"), "2 ÷ 2 = 1");
}
async function willNormalizeSingleCharacter() {
assertStrictEq(await normalize("ô"), "o");
}
async function willNormalizeNonAccentedCharacter() {
assertStrictEq(await normalize("tromsø"), "tromso");
assertStrictEq(await normalize("\u00d8"), "O");
}
async function willNormalizeRepeatedCharacters() {
assertStrictEq(await normalize("éééé"), "eeee");
assertStrictEq(await normalize("åååå"), "aaaa");
assertStrictEq(await normalize("éåéåéåéå"), "eaeaeaea");
assertStrictEq(await normalize("åéåéåéåé"), "aeaeaeae");
}
prepareTest(
[
willSkipNormalizationForEmptyCharacter,
willNormalizeSingleCharacter,
willNormalizeAccentedCharacters,
willNormalizeAccentedCharactersWithoutUsingNativeFunction,
willReturnOriginalCharacterWhenNoMatchFound,
willNormalizeNonAccentedCharacter,
willNormalizeRepeatedCharacters
],
"normalize_diacritics"
);