test: use main program for testing
This commit is contained in:
parent
93179a934c
commit
e97ceb8c25
4 changed files with 27 additions and 58 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
/main
|
/main
|
||||||
/test
|
|
||||||
/*.o
|
/*.o
|
||||||
/*.d
|
/*.d
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -5,11 +5,9 @@ OBJS = syllable.o utf8.o transliteration.o iast.o
|
||||||
|
|
||||||
main: main.o $(OBJS)
|
main: main.o $(OBJS)
|
||||||
$(CC) $^ -o $@
|
$(CC) $^ -o $@
|
||||||
./main
|
|
||||||
|
|
||||||
test: test.o $(OBJS)
|
test: main
|
||||||
$(CC) $^ -o $@
|
sh test.sh
|
||||||
./test
|
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) -MMD -MP -c $< -o $@
|
$(CC) -MMD -MP -c $< -o $@
|
||||||
|
|
53
test.c
53
test.c
|
@ -1,53 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
25
test.sh
Normal file
25
test.sh
Normal file
|
@ -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ā"
|
Loading…
Reference in a new issue