tibetan-mantra-to-iast-and-phonetics 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tests.js ADDED
@@ -0,0 +1,90 @@
1
+ import TibetanMantraToIastAndPhonetics from "./lib/tibetan-mantra-to-iast-and-phonetics.js";
2
+
3
+ export const testGroups = [
4
+ {
5
+ name: "All mantras from Mipham Rinpoché's Le Drip Gyü Chö - Sanskrit transliteration",
6
+ sentences: true,
7
+ phonetics: false,
8
+ tests: [
9
+ { tibetan: "ཨོཾ་ཨཱཿཧཱུྃ།", result: "oṁ āḥ hūṁ" },
10
+ { tibetan: "ཨོཾ་ཨཱཿཧཱུྃ་སྭཱ་ཧཱ།", result: "oṁ āḥ hūṁ svāhā" },
11
+ { tibetan: "ཨོཾ་ཧཱུྃ་ཏྲཱཾ་ཧྲཱིཿཨཱཿ", result: "oṁ hūṁ trāṁ hrīḥ āḥ" },
12
+ { tibetan: "འཿཨཿཧཿཤཿསཿམཿ", result: "āḥ aḥ haḥ śaḥ saḥ maḥ" },
13
+ { tibetan: "ཨོཾ་བཛྲ་སཏྭ་ཧཱུྃ།", result: "oṁ vajra satva hūṁ" },
14
+ {
15
+ tibetan: "ན་མཿས་མནྟ་བུདྡྷཱ་ནཱཾ། ཨཱ་བཱི་ར་ཧཱུྃ་ཁཾ།",
16
+ result: "namaḥ samanta buddhānāṁ āvīra hūṁ khaṁ",
17
+ },
18
+ { tibetan: "ཨོཾ་མ་ཎི་པདྨེ་ཧཱུྃ།", result: "oṁ maṇi padmé hūṁ" },
19
+ {
20
+ tibetan: "ཨོཾ་ཏཱ་རེ་ཏུཏྟཱ་རེ་ཏུ་རེ་སྭཱ་ཧཱ།",
21
+ result: "oṁ tāré tuttāré turé svāhā",
22
+ },
23
+ ],
24
+ },
25
+ {
26
+ name: "Phonetics tests",
27
+ sentences: true,
28
+ phonetics: true,
29
+ tests: [
30
+ { tibetan: "ཨོཾ་ཨ་ར་པ་ཙ་ན།", result: "om a ra pa cha na" },
31
+ { tibetan: "བཛྲ་པཱ་ཙ་ཧོ།", result: "vajra pacha ho" },
32
+ ],
33
+ },
34
+ ];
35
+
36
+ export function runTests() {
37
+ const results = testGroups.map((group) => {
38
+ const groupResults = {
39
+ name: group.name,
40
+ tests: group.tests.map((test) => {
41
+ const options = { mode: group.phonetics ? "phonetics" : "iast" };
42
+ const transliterated = new TibetanMantraToIastAndPhonetics(
43
+ test.tibetan
44
+ ).transliterate(options);
45
+ const pass = transliterated === test.result;
46
+ return {
47
+ tibetan: test.tibetan,
48
+ expected: test.result,
49
+ actual: transliterated,
50
+ pass,
51
+ };
52
+ }),
53
+ };
54
+ return groupResults;
55
+ });
56
+
57
+ return results;
58
+ }
59
+
60
+ if (import.meta.url === `file://${process.argv[1]}`) {
61
+ const results = runTests();
62
+ let totalPassed = 0;
63
+ let totalTests = 0;
64
+
65
+ console.log("\n=== Tibetan Mantra Transliteration Tests ===\n");
66
+
67
+ results.forEach((group) => {
68
+ const passed = group.tests.filter((t) => t.pass).length;
69
+ const total = group.tests.length;
70
+ totalPassed += passed;
71
+ totalTests += total;
72
+
73
+ console.log(`${group.name}: ${passed}/${total}`);
74
+ group.tests.forEach((test) => {
75
+ if (!test.pass) {
76
+ console.log(` ✗ ${test.tibetan}`);
77
+ console.log(` Expected: ${test.expected}`);
78
+ console.log(` Got: ${test.actual}`);
79
+ }
80
+ });
81
+ });
82
+
83
+ console.log(
84
+ `\nTotal: ${totalPassed}/${totalTests} (${(
85
+ (totalPassed / totalTests) *
86
+ 100
87
+ ).toFixed(1)}%)\n`
88
+ );
89
+ process.exit(totalPassed === totalTests ? 0 : 1);
90
+ }