-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transliterator.test.ts
161 lines (140 loc) · 4.71 KB
/
transliterator.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
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
import { it, expect, describe, test } from '@jest/globals';
import { translit, indic } from './transliterator';
import { dict as hindi_tests } from './hindi_testdata';
import { dict as bengali_tests } from './bengali_testdata';
it("should be good", () => {
expect(translit("जें")).toEqual("jēṁ");
expect(translit("एजें")).toEqual("ējēṁ");
expect(translit("हॉकिंस")).toEqual("hôkiṁsa");
expect(translit("പീച്ചാംകുഴൽ")).toEqual("pīccāṅkuḻal");
expect(translit("Борис Николаевич Ельцин")).toEqual("Boris Nikolaevič Elʹcin");
});
it("should expand properly", () => {
expect(indic(0x21, true)).toEqual([
"ड़",
"ড়",
"ਡ਼",
"ડ઼",
"ଡ଼",
"డ఼", // Telugu nukta is a recent addition: https://www.unicode.org/L2/L2020/20085-telugu-nukta.pdf
"ಡ಼",
"ഡ഼",
]);
})
describe("unicode tests", () => {
const tests = [
["ऱ्", "ṟ"],
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
})
describe("tests from salita", () => {
// https://github.com/mbykov/salita/blob/master/test/tests.js
const tests = [
["सत्य", "satya"],
["सत्यानृत", "satyānr̥ta"],
["राम", "rāma"],
["अपसलैः", "apasalaiḥ"],
["स्रंसिन्", "sraṁsin"],
["संका", "saṅkā"],
["कॢप्त", "kl̥pta"],
["उपनिषत्", "upaniṣat"],
["ऋद्धि", "r̥ddhi"],
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
});
describe("Malayalam special forms", () => {
const tests = [
// ra:
["ര", "ṟa"], // special at end
["രമ", "rama"], // normal at medial
// ya:
["യ്", "y"], // normal at end
["യ്മ", "y:ma"], // special at medial
["യ", "ya"], // shouldn't change
["യമ", "yama"], // shouldn't change
// i: ambiguities
["ഇ", "i"],
["ബഇ", "ba:i"],
// ambiguity
["ൻന", "n:na"],
["ന്ന", "nna"],
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
});
describe("Devanagari special cases", () => {
const tests = [
["बइ", "ba:i"],
["बै", "bai"],
["र्य", "rya"],
//["र्य", "r:ya"], // unsure how this is constructed in the example
["र्", "r̆"], // "eyelash R" as used in Nepali/Marathi
["सय्ँयन्ता", "sam̐yyantā"],
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
});
describe("npm transliteration", () => {
// https://github.com/dzcpy/transliteration/blob/master/test/common/transliterate.ts
const tests = [
["മലയാലമ്", "malayālam"],
['അഭിജീത', 'abhijīta'],
["अभिजीत", "abhijīta"],
// ["অভিজীত", "abhijīt"], Bengali
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
});
describe("conjuncts", () => {
// https://scriptsource.org/cms/scripts/page.php?item_id=entry_detail&uid=g8w4snzcy5
const tests = [
["क्ष", "kṣa"],
["त्र", "tra"],
["ज्ञ", "jña"],
["ष्र", "ṣra"],
["य़", "ẏa"],
];
it.each(tests)("check %s", (input, output) => {
expect(translit(input)).toEqual(output);
});
});
// these were table-driven tests but that was too slow:
it('Hindi tests', () => {
for (const [input, output] of hindi_tests) {
expect(translit(input)).toEqual(output);
}
});
/*
it('Bengali tests', () => {
for (const [input, output] of bengali_tests) {
expect(translit(input)).toEqual(output);
}
});
*/
it('Bengali cases', () => {
const tests = [
["মন", "mana"],
["সাপ", "sāpa"],
["শাপ", "śāpa"],
["মত", "mata"],
["মতো", "matō"],
["তেল", "tēla"],
["গেল", "gēla"],
["জ্বর", "jbara"],
["স্বাস্থ্য", "sbāsthya"],
["বাংলাদেশ", "bāṁlādēśa"],
["ব্যঞ্জনধ্বনি", "byañjanadhbani"],
["আত্মহত্যা", "ātmahatyā"],
["ৰৱ", "rava"], // Assamese
];
for (const [input, output] of tests) {
expect(translit(input)).toEqual(output);
}
});