From e97ceb8c253e2016d5c8ae68f339dec6ec9f9e0d Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Fri, 27 Apr 2018 13:06:21 +0200 Subject: [PATCH] test: use main program for testing --- .gitignore | 1 - Makefile | 6 ++---- test.c | 53 ----------------------------------------------------- test.sh | 25 +++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 58 deletions(-) delete mode 100644 test.c create mode 100644 test.sh diff --git a/.gitignore b/.gitignore index c8fc225..a3896b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /main -/test /*.o /*.d diff --git a/Makefile b/Makefile index cb9d1bc..1d3ae11 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,9 @@ OBJS = syllable.o utf8.o transliteration.o iast.o main: main.o $(OBJS) $(CC) $^ -o $@ - ./main -test: test.o $(OBJS) - $(CC) $^ -o $@ - ./test +test: main + sh test.sh %.o: %.c $(CC) -MMD -MP -c $< -o $@ diff --git a/test.c b/test.c deleted file mode 100644 index 453b54e..0000000 --- a/test.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -#include "syllable.h" -#include "utf8.h" -#include "transliteration.h" -#include "iast.h" - -struct string_pair { - const char *devanagari; - const char *latin; -}; - -static const struct string_pair table_iast[] = { - {"संस्कृतम्", "saṃskṛtam"}, - {"आर्यावर्त", "āryāvarta"}, - {"तन्त्रशास्त्रम्", "tantraśāstram"}, - {"ऋग्वेद", "ṛgveda"}, - {"महाभारतम्", "mahābhāratam"}, - {"सरस्वती नदी", "sarasvatī nadī"}, - {"देवनागरी", "devanāgarī"}, - {"योगः", "yogaḥ"}, - {"भगवद्गीता", "bhagavadgītā"}, - {NULL, NULL} -}; - -int main(int argc, const char **argv) -{ - struct transliteration_context *context; - const struct string_pair *walk = table_iast; - char *ptr; - int retval = 0; - int match; - - context = transliteration_context_iast_alloc(); - while (walk->devanagari != NULL) { - ptr = transliterate_devanagari_to_latin(walk->devanagari, context); - - match = strcmp(ptr, walk->latin) == 0; - printf("\033[%dm", match ? 32 : 31); - printf("%s = %s", ptr, walk->latin); - printf("\033[0m\n"); - - if (!match) - retval++; - - free(ptr); - walk++; - } - - return retval; -} diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..6f5d13b --- /dev/null +++ b/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +test_word() +{ + transliterated=$(echo -n "$1" | ./main) + expected="$2" + + if test "x$transliterated" = "x$expected" + then + echo "\033[32m$transliterated\033[0m = \033[32m$expected\033[0m" + else + echo "\033[31m$transliterated\033[0m != \033[31m$expected\033[0m" + fi +} + +test_word "संस्कृतम्" "saṃskṛtam" +test_word "आर्यावर्त" "āryāvarta" +test_word "तन्त्रशास्त्रम्" "tantraśāstram" +test_word "ऋग्वेद" "ṛgveda" +test_word "महाभारतम्" "mahābhāratam" +test_word "सरस्वती नदी" "sarasvatī nadī" +test_word "देवनागरी" "devanāgarī" +test_word "योगः" "yogaḥ" +test_word "भगवद्गीता" "bhagavadgītā"