From bcd0f502f7867dd7d1698b0101c4eab73ce686b8 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 28 Nov 2011 17:35:37 +0800 Subject: write test parser2 --- tests/storage/test_parser2.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'tests/storage/test_parser2.cpp') diff --git a/tests/storage/test_parser2.cpp b/tests/storage/test_parser2.cpp index a7e57e2..32b80ff 100644 --- a/tests/storage/test_parser2.cpp +++ b/tests/storage/test_parser2.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include "pinyin_parser2.h" @@ -84,12 +85,36 @@ int main(int argc, char * argv[]) { ++i; } - if (NULL == parser) { - print_help(); - exit(EINVAL); - } + if (!parser) + parser = new FullPinyinParser2(); + + char* linebuf = NULL; size_t size = 0; ssize_t read; + while( (read = getline(&linebuf, &size, stdin)) != -1 ){ + if ( '\n' == linebuf[strlen(linebuf) - 1] ) { + linebuf[strlen(linebuf) - 1] = '\0'; + } + + if ( strcmp ( linebuf, "quit" ) == 0) + break; + + int len = parser->parse(options, keys, key_rests, + linebuf, strlen(linebuf)); + printf("parsed %d chars, %d keys.\n", len, keys->len); + assert(keys->len == key_rests->len); + + for (size_t i = 0; i < keys->len; ++i) { + ChewingKeyRest * key_rest = + &g_array_index(key_rests, ChewingKeyRest, i); + printf("%s %d %d\t", key_rest->get_pinyin_string(), + key_rest->m_raw_begin, key_rest->m_raw_end); + } + printf("\n"); + + } + if (linebuf) + free(linebuf); return 0; } -- cgit