sanskrit-iast/tests/translit.c

111 lines
3.8 KiB
C
Raw Normal View History

#include "test.h"
2020-01-01 17:15:07 +01:00
#include "translit.h"
#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"
2020-01-07 13:18:54 +01:00
static void test_transliterate_devanagari_to_latin(const char *devanagari,
const char *latin)
2020-01-01 17:15:07 +01:00
{
char *str;
int ret;
ret = transliterate_devanagari_to_latin(devanagari, &str);
ck_assert_int_eq(0, ret);
2020-01-07 13:18:54 +01:00
ck_assert_str_eq(latin, str);
free(str);
}
2020-01-01 17:15:07 +01:00
2020-01-07 13:18:54 +01:00
static void test_transliterate_latin_to_devanagari(const char *latin,
const char *devanagari)
{
char *str;
int ret;
ret = transliterate_latin_to_devanagari(latin, &str);
2020-01-07 13:18:54 +01:00
ck_assert_str_eq(devanagari, str);
free(str);
}
START_TEST(test_translit_devanagari_to_latin)
{
2020-01-01 17:15:07 +01:00
/* https://en.wikipedia.org/wiki/Sanskrit */
2020-01-07 13:18:54 +01:00
test_transliterate_devanagari_to_latin("संस्कृतम्", "saṃskṛtam");
2020-01-01 17:15:07 +01:00
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
2020-01-07 13:18:54 +01:00
test_transliterate_devanagari_to_latin("भगवद्गीता", "bhagavadgītā");
2020-01-01 17:15:07 +01:00
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
2020-01-07 13:18:54 +01:00
test_transliterate_devanagari_to_latin("आर्यावर्त", "āryāvarta");
2020-01-01 17:15:07 +01:00
/* https://en.wikipedia.org/wiki/Mahabharata */
2020-01-07 13:18:54 +01:00
test_transliterate_devanagari_to_latin("महाभारतम्", "mahābhāratam");
/* https://en.wikipedia.org/wiki/Devanagari */
test_transliterate_devanagari_to_latin("देवनागरी", "devanāgarī");
2020-01-01 17:15:07 +01:00
}
END_TEST
START_TEST(test_translit_latin_to_devanagari)
{
2020-01-07 13:18:54 +01:00
test_transliterate_latin_to_devanagari("saṃskṛtam", "संस्कृतम्");
test_transliterate_latin_to_devanagari("bhagavadgītā", "भगवद्गीता");
test_transliterate_latin_to_devanagari("āryāvarta", "आर्यावर्त");
test_transliterate_latin_to_devanagari("mahābhāratam", "महाभारतम्");
test_transliterate_latin_to_devanagari("devanāgarī", "देवनागरी");
}
END_TEST
2020-10-11 08:55:24 +02:00
START_TEST(test_translit_lla_sylable)
{
test_transliterate_devanagari_to_latin("अग्निमीळे", "agnimīḷe");
test_transliterate_latin_to_devanagari("agnimīḷe", "अग्निमीळे");
2021-04-21 22:06:15 +02:00
/* rigveda 1.22.17 */
test_transliterate_devanagari_to_latin("समूळ्हमस्य", "samūḷhamasya");
test_transliterate_latin_to_devanagari("samūḷhamasya", "समूळ्हमस्य");
2020-10-11 08:55:24 +02:00
test_transliterate_devanagari_to_latin("चाकॢप्र", "cākḷpra");
test_transliterate_latin_to_devanagari("cākḷpra", "चाकॢप्र");
}
END_TEST
2020-10-11 09:48:55 +02:00
START_TEST(test_translit_candrabindu)
{
test_transliterate_devanagari_to_latin("तान्यजत्राँ", "tānyajatrām̐");
test_transliterate_latin_to_devanagari("tānyajatrām̐", "तान्यजत्राँ");
}
END_TEST
START_TEST(test_translit_zero_width_joiner)
{
2021-12-26 14:19:51 +01:00
test_transliterate_devanagari_to_latin("श‍ृ शृ", "ś"ZWJ"ṛ śṛ");
test_transliterate_latin_to_devanagari("ś"ZWJ"ṛ śṛ", "श‍ृ शृ");
}
END_TEST
START_TEST(test_translit_vedic)
{
/* rigveda 1.25.4 */
test_transliterate_devanagari_to_latin("वस्यइष्टये", "vasya"ZWNJ"iṣṭaye");
test_transliterate_latin_to_devanagari("vasya"ZWNJ"iṣṭaye", "वस्यइष्टये");
/* rigveda 3.5.2 */
test_transliterate_devanagari_to_latin("पूर्वीर्ऋतस्य", "pūrvīr"ZWNJ"ṛtasya");
test_transliterate_latin_to_devanagari("pūrvīr"ZWNJ"ṛtasya", "पूर्वीर्ऋतस्य");
}
END_TEST
2020-01-01 17:15:07 +01:00
void register_translit_tests(TCase *test_case)
{
tcase_add_test(test_case, test_translit_devanagari_to_latin);
tcase_add_test(test_case, test_translit_latin_to_devanagari);
2020-10-11 08:55:24 +02:00
tcase_add_test(test_case, test_translit_lla_sylable);
2020-10-11 09:48:55 +02:00
tcase_add_test(test_case, test_translit_candrabindu);
tcase_add_test(test_case, test_translit_zero_width_joiner);
2021-12-26 14:19:51 +01:00
tcase_add_test(test_case, test_translit_vedic);
2020-01-01 17:15:07 +01:00
}