2020-01-01 22:02:44 +01:00
|
|
|
|
#include "test.h"
|
2020-01-01 17:15:07 +01:00
|
|
|
|
#include "translit.h"
|
2021-03-12 18:51:09 +01:00
|
|
|
|
#include "../compat.h"
|
2020-01-01 17:15:07 +01:00
|
|
|
|
#include "../transliteration.h"
|
|
|
|
|
|
2021-12-26 14:19:51 +01:00
|
|
|
|
#define ZWJ "\u200d"
|
|
|
|
|
#define ZWNJ "\u200c"
|
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
static void test_translit(const char *devanagari, const char *latin)
|
2020-01-01 17:15:07 +01:00
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
char *a, *b;
|
2021-03-12 18:51:09 +01:00
|
|
|
|
int ret;
|
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
ret = transliterate_devanagari_to_latin(devanagari, &a);
|
2021-03-12 18:51:09 +01:00
|
|
|
|
ck_assert_int_eq(0, ret);
|
2021-12-28 21:06:41 +01:00
|
|
|
|
ck_assert_str_eq(latin, a);
|
2020-01-01 17:15:07 +01:00
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
ret = transliterate_latin_to_devanagari(a, &b);
|
|
|
|
|
ck_assert_int_eq(0, ret);
|
|
|
|
|
ck_assert_str_eq(devanagari, b);
|
2021-03-12 18:51:09 +01:00
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
free(a);
|
|
|
|
|
free(b);
|
2020-01-07 13:18:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 13:02:15 +02:00
|
|
|
|
static void test_translit_latin(const char *latin, const char *devanagari)
|
|
|
|
|
{
|
|
|
|
|
char *str;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = transliterate_latin_to_devanagari(latin, &str);
|
|
|
|
|
ck_assert_int_eq(0, ret);
|
|
|
|
|
ck_assert_str_eq(devanagari, str);
|
|
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
START_TEST(test_translit_words)
|
2020-01-07 13:18:54 +01:00
|
|
|
|
{
|
2020-01-01 17:15:07 +01:00
|
|
|
|
/* https://en.wikipedia.org/wiki/Sanskrit */
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("संस्कृतम्", "saṃskṛtam");
|
2020-01-01 17:15:07 +01:00
|
|
|
|
|
|
|
|
|
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("भगवद्गीता", "bhagavadgītā");
|
2020-01-01 17:15:07 +01:00
|
|
|
|
|
|
|
|
|
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("आर्यावर्त", "āryāvarta");
|
2020-01-01 17:15:07 +01:00
|
|
|
|
|
|
|
|
|
/* https://en.wikipedia.org/wiki/Mahabharata */
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("महाभारतम्", "mahābhāratam");
|
2020-01-07 13:18:54 +01:00
|
|
|
|
|
|
|
|
|
/* https://en.wikipedia.org/wiki/Devanagari */
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("देवनागरी", "devanāgarī");
|
2020-01-01 17:15:07 +01:00
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
START_TEST(test_translit_vedic)
|
2020-01-01 22:02:44 +01:00
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
/* rigveda 1.25.4 */
|
|
|
|
|
test_translit("वस्यइष्टये", "vasya"ZWNJ"iṣṭaye");
|
|
|
|
|
|
|
|
|
|
/* rigveda 3.5.2 */
|
|
|
|
|
test_translit("पूर्वीर्ऋतस्य", "pūrvīr"ZWNJ"ṛtasya");
|
2021-12-28 21:43:49 +01:00
|
|
|
|
|
|
|
|
|
/* vedic stresses */
|
|
|
|
|
test_translit("अ॒ग्निमी॑ळे पु॒रोहि॑तं", "a\\_gnimī\\'ḷe pu\\_rohi\\'taṃ");
|
2023-09-23 09:08:45 +02:00
|
|
|
|
|
|
|
|
|
/* double svarita */
|
|
|
|
|
test_translit("अ॒ग्निमी᳚ळे", "a\\_gnimī\\\"ḷe");
|
2020-01-01 22:02:44 +01:00
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2020-10-11 08:55:24 +02:00
|
|
|
|
START_TEST(test_translit_lla_sylable)
|
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("अग्निमीळे", "agnimīḷe"); /* rigveda 1.1.1 */
|
|
|
|
|
test_translit("चाकॢप्र", "cākḷpra"); /* rigveda 10.130.5 */
|
|
|
|
|
test_translit("समूळ्हमस्य", "samūḷhamasya"); /* rigveda 1.22.17 */
|
2021-04-21 22:06:15 +02:00
|
|
|
|
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("ऌ ऌप ऌळ", "ḷ ḷpa ḷḷa"); /* at the beginning = vowel */
|
|
|
|
|
test_translit("ळ ळे ळृ", "ḷa ḷe ḷṛ"); /* followed by a vowel = consonant */
|
|
|
|
|
test_translit("प्ळ पळ ओप्ळ", "pḷa paḷa opḷa");
|
2020-10-11 08:55:24 +02:00
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2023-03-18 18:34:50 +01:00
|
|
|
|
START_TEST(test_translit_aum)
|
|
|
|
|
{
|
|
|
|
|
test_translit("ॐ औम औमे तौमे ॐ", "aum auma aume taume aum");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 13:02:15 +02:00
|
|
|
|
START_TEST(test_translit_avagraha)
|
|
|
|
|
{
|
|
|
|
|
test_translit_latin("śivo'ham", "शिवोऽहम्");
|
|
|
|
|
test_translit_latin("śivo’ham", "शिवोऽहम्");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-11 09:48:55 +02:00
|
|
|
|
START_TEST(test_translit_candrabindu)
|
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("तान्यजत्राँ", "tānyajatrām̐");
|
2020-10-11 09:48:55 +02:00
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2021-04-21 21:22:11 +02:00
|
|
|
|
START_TEST(test_translit_zero_width_joiner)
|
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
test_translit("शृ शृ", "ś"ZWJ"ṛ śṛ");
|
2021-04-21 21:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2020-01-01 17:15:07 +01:00
|
|
|
|
void register_translit_tests(TCase *test_case)
|
|
|
|
|
{
|
2021-12-28 21:06:41 +01:00
|
|
|
|
tcase_add_test(test_case, test_translit_words);
|
|
|
|
|
tcase_add_test(test_case, test_translit_vedic);
|
2020-10-11 08:55:24 +02:00
|
|
|
|
tcase_add_test(test_case, test_translit_lla_sylable);
|
2023-03-18 18:34:50 +01:00
|
|
|
|
tcase_add_test(test_case, test_translit_aum);
|
2023-05-03 13:02:15 +02:00
|
|
|
|
tcase_add_test(test_case, test_translit_avagraha);
|
2020-10-11 09:48:55 +02:00
|
|
|
|
tcase_add_test(test_case, test_translit_candrabindu);
|
2021-04-21 21:22:11 +02:00
|
|
|
|
tcase_add_test(test_case, test_translit_zero_width_joiner);
|
2020-01-01 17:15:07 +01:00
|
|
|
|
}
|