update tests
This commit is contained in:
parent
dba90f5c15
commit
1beea31afa
7 changed files with 80 additions and 90 deletions
4
Makefile
4
Makefile
|
@ -3,7 +3,7 @@ PREFIX=/usr/local
|
||||||
.PHONY: main test install uninstall clean
|
.PHONY: main test install uninstall clean
|
||||||
|
|
||||||
OBJECTS = iast.o iast-czech.o transliteration.o transcription.o utf8.o encoder.o
|
OBJECTS = iast.o iast-czech.o transliteration.o transcription.o utf8.o encoder.o
|
||||||
TEST_OBJECTS = tests/main.o tests/translit.o tests/transcript.o
|
TEST_OBJECTS = tests/main.o tests/translit.o tests/transcript.o tests/encoder.o
|
||||||
CFLAGS = -Wall
|
CFLAGS = -Wall
|
||||||
LIBS =
|
LIBS =
|
||||||
TEST_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags check)
|
TEST_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags check)
|
||||||
|
@ -40,4 +40,4 @@ uninstall:
|
||||||
rm -f $(PREFIX)/share/man/man1/$(PROGNAME).1.gz
|
rm -f $(PREFIX)/share/man/man1/$(PROGNAME).1.gz
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) iast *.o */*.o *.d */*.d doc/*.gz
|
$(RM) iast tests/test *.o */*.o *.d */*.d doc/*.gz
|
||||||
|
|
27
tests/encoder.c
Normal file
27
tests/encoder.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#include "test.h"
|
||||||
|
#include "encoder.h"
|
||||||
|
#include "../encoder.h"
|
||||||
|
|
||||||
|
static void test_encoding(const char *in, const char *expected)
|
||||||
|
{
|
||||||
|
char *iast = encode_iast_punctation(in);
|
||||||
|
ck_assert_str_eq(expected, iast);
|
||||||
|
free(iast);
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST(test_encode_punctation)
|
||||||
|
{
|
||||||
|
test_encoding("sam.skr.tam", "saṃskṛtam");
|
||||||
|
|
||||||
|
test_encoding("yogah.", "yogaḥ");
|
||||||
|
|
||||||
|
test_encoding("tantras,a-stram", "tantraśāstram");
|
||||||
|
|
||||||
|
test_encoding("tantrašástram", "tantraśāstram");
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
void register_encoder_tests(TCase *test_case)
|
||||||
|
{
|
||||||
|
tcase_add_test(test_case, test_encode_punctation);
|
||||||
|
}
|
8
tests/encoder.h
Normal file
8
tests/encoder.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef __TEST_ENCODER_H
|
||||||
|
#define __TEST_ENCODER_H
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
void register_encoder_tests(TCase *test_case);
|
||||||
|
|
||||||
|
#endif /* __TEST_ENCODER_H */
|
|
@ -1,6 +1,7 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
#include "translit.h"
|
#include "translit.h"
|
||||||
#include "transcript.h"
|
#include "transcript.h"
|
||||||
|
#include "encoder.h"
|
||||||
|
|
||||||
static Suite *create_test_suite()
|
static Suite *create_test_suite()
|
||||||
{
|
{
|
||||||
|
@ -12,6 +13,7 @@ static Suite *create_test_suite()
|
||||||
|
|
||||||
register_translit_tests(test_case);
|
register_translit_tests(test_case);
|
||||||
register_transcript_tests(test_case);
|
register_transcript_tests(test_case);
|
||||||
|
register_encoder_tests(test_case);
|
||||||
suite_add_tcase(suite, test_case);
|
suite_add_tcase(suite, test_case);
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
test_word()
|
|
||||||
{
|
|
||||||
output=$(echo -n "$1" | ./iast $3 --)
|
|
||||||
expected="$2"
|
|
||||||
|
|
||||||
test "x$output" = "x$expected" &&
|
|
||||||
echo "\033[32m$output\033[0m = \033[32m$expected\033[0m" ||
|
|
||||||
echo "\033[31m$output\033[0m != \033[31m$expected\033[0m"
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Transliteration to IAST"
|
|
||||||
test_word "संस्कृतम्" "saṃskṛtam"
|
|
||||||
test_word "आर्यावर्त" "āryāvarta"
|
|
||||||
test_word "तन्त्रशास्त्रम्" "tantraśāstram"
|
|
||||||
test_word "सांख्य" "sāṃkhya"
|
|
||||||
test_word "ऋग्वेद" "ṛgveda"
|
|
||||||
test_word "महाभारतम्" "mahābhāratam"
|
|
||||||
test_word "सरस्वती नदी" "sarasvatī nadī"
|
|
||||||
test_word "देवनागरी" "devanāgarī"
|
|
||||||
test_word "योगः" "yogaḥ"
|
|
||||||
test_word "भगवद्गीता" "bhagavadgītā"
|
|
||||||
test_word "सम्भोग" "sambhoga"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Transliteration to czech"
|
|
||||||
test_word "तन्त्रशास्त्रम्" "tantrašástra" -c
|
|
||||||
test_word "सांख्य" "sánkhja" -c
|
|
||||||
test_word "महाभारतम्" "mahábhárata" -c
|
|
||||||
test_word "योगः" "jóga" -c
|
|
||||||
test_word "भगवद्गीता" "bhagavadgíta" -c
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Encoding"
|
|
||||||
test_word "sam.skr.tam" "saṃskṛtam" -e
|
|
||||||
test_word "yogah." "yogaḥ" -e
|
|
||||||
test_word "tantras,a-stram" "tantraśāstram" -e
|
|
||||||
test_word "tantrašástram" "tantraśāstram" -e
|
|
|
@ -2,29 +2,24 @@
|
||||||
#include "transcript.h"
|
#include "transcript.h"
|
||||||
#include "../transcription.h"
|
#include "../transcription.h"
|
||||||
|
|
||||||
|
static void test_transcript(const char *devanagari, const char *latin)
|
||||||
|
{
|
||||||
|
char *czech = transcript_devanagari_to_czech(devanagari);
|
||||||
|
ck_assert_str_eq(latin, czech);
|
||||||
|
free(czech);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(test_transcript_devanagari_to_czech)
|
START_TEST(test_transcript_devanagari_to_czech)
|
||||||
{
|
{
|
||||||
char *czech;
|
test_transcript("तन्त्रशास्त्रम्", "tantrašástra");
|
||||||
|
|
||||||
czech = transcript_devanagari_to_czech("तन्त्रशास्त्रम्");
|
test_transcript("सांख्य", "sánkhja");
|
||||||
ck_assert_str_eq("tantrašástra", czech);
|
|
||||||
free(czech);
|
|
||||||
|
|
||||||
czech = transcript_devanagari_to_czech("सांख्य");
|
test_transcript("महाभारतम्", "mahábhárata");
|
||||||
ck_assert_str_eq("sánkhja", czech);
|
|
||||||
free(czech);
|
|
||||||
|
|
||||||
czech = transcript_devanagari_to_czech("महाभारतम्");
|
test_transcript("योगः", "jóga");
|
||||||
ck_assert_str_eq("mahábhárata", czech);
|
|
||||||
free(czech);
|
|
||||||
|
|
||||||
czech = transcript_devanagari_to_czech("योगः");
|
test_transcript("भगवद्गीता", "bhagavadgíta");
|
||||||
ck_assert_str_eq("jóga", czech);
|
|
||||||
free(czech);
|
|
||||||
|
|
||||||
czech = transcript_devanagari_to_czech("भगवद्गीता");
|
|
||||||
ck_assert_str_eq("bhagavadgíta", czech);
|
|
||||||
free(czech);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
|
@ -2,51 +2,49 @@
|
||||||
#include "translit.h"
|
#include "translit.h"
|
||||||
#include "../transliteration.h"
|
#include "../transliteration.h"
|
||||||
|
|
||||||
|
static void test_transliterate_devanagari_to_latin(const char *devanagari,
|
||||||
|
const char *latin)
|
||||||
|
{
|
||||||
|
char *str = transliterate_devanagari_to_latin(devanagari);
|
||||||
|
ck_assert_str_eq(latin, str);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_transliterate_latin_to_devanagari(const char *latin,
|
||||||
|
const char *devanagari)
|
||||||
|
{
|
||||||
|
char *str = transliterate_latin_to_devanagari(latin);
|
||||||
|
ck_assert_str_eq(devanagari, str);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(test_translit_devanagari_to_latin)
|
START_TEST(test_translit_devanagari_to_latin)
|
||||||
{
|
{
|
||||||
char *latin;
|
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/Sanskrit */
|
/* https://en.wikipedia.org/wiki/Sanskrit */
|
||||||
latin = transliterate_devanagari_to_latin("संस्कृतम्");
|
test_transliterate_devanagari_to_latin("संस्कृतम्", "saṃskṛtam");
|
||||||
ck_assert_str_eq("saṃskṛtam", latin);
|
|
||||||
free(latin);
|
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
|
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
|
||||||
latin = transliterate_devanagari_to_latin("भगवद्गीता");
|
test_transliterate_devanagari_to_latin("भगवद्गीता", "bhagavadgītā");
|
||||||
ck_assert_str_eq("bhagavadgītā", latin);
|
|
||||||
free(latin);
|
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
|
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
|
||||||
latin = transliterate_devanagari_to_latin("आर्यावर्त");
|
test_transliterate_devanagari_to_latin("आर्यावर्त", "āryāvarta");
|
||||||
ck_assert_str_eq("āryāvarta", latin);
|
|
||||||
free(latin);
|
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/Mahabharata */
|
/* https://en.wikipedia.org/wiki/Mahabharata */
|
||||||
latin = transliterate_devanagari_to_latin("महाभारतम्");
|
test_transliterate_devanagari_to_latin("महाभारतम्", "mahābhāratam");
|
||||||
ck_assert_str_eq("mahābhāratam", latin);
|
|
||||||
free(latin);
|
/* https://en.wikipedia.org/wiki/Devanagari */
|
||||||
|
test_transliterate_devanagari_to_latin("देवनागरी", "devanāgarī");
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
START_TEST(test_translit_latin_to_devanagari)
|
START_TEST(test_translit_latin_to_devanagari)
|
||||||
{
|
{
|
||||||
char *devanagari;
|
test_transliterate_latin_to_devanagari("saṃskṛtam", "संस्कृतम्");
|
||||||
|
test_transliterate_latin_to_devanagari("bhagavadgītā", "भगवद्गीता");
|
||||||
devanagari = transliterate_latin_to_devanagari("saṃskṛtam");
|
test_transliterate_latin_to_devanagari("āryāvarta", "आर्यावर्त");
|
||||||
ck_assert_str_eq("संस्कृतम्", devanagari);
|
test_transliterate_latin_to_devanagari("mahābhāratam", "महाभारतम्");
|
||||||
free(devanagari);
|
test_transliterate_latin_to_devanagari("devanāgarī", "देवनागरी");
|
||||||
|
|
||||||
devanagari = transliterate_latin_to_devanagari("bhagavadgītā");
|
|
||||||
ck_assert_str_eq("भगवद्गीता", devanagari);
|
|
||||||
free(devanagari);
|
|
||||||
|
|
||||||
devanagari = transliterate_latin_to_devanagari("āryāvarta");
|
|
||||||
ck_assert_str_eq("आर्यावर्त", devanagari);
|
|
||||||
free(devanagari);
|
|
||||||
|
|
||||||
devanagari = transliterate_latin_to_devanagari("mahābhāratam");
|
|
||||||
ck_assert_str_eq("महाभारतम्", devanagari);
|
|
||||||
free(devanagari);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue