summaryrefslogtreecommitdiffstats
path: root/tests/storage/test_parser2.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-28 17:35:37 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-28 17:35:37 +0800
commitbcd0f502f7867dd7d1698b0101c4eab73ce686b8 (patch)
tree139634ef883b05277024867a4c0f9b929dd20dfc /tests/storage/test_parser2.cpp
parent2e94362059fe96a490ef7a8b320a08941b96ec81 (diff)
downloadlibpinyin-bcd0f502f7867dd7d1698b0101c4eab73ce686b8.tar.gz
libpinyin-bcd0f502f7867dd7d1698b0101c4eab73ce686b8.tar.xz
libpinyin-bcd0f502f7867dd7d1698b0101c4eab73ce686b8.zip
write test parser2
Diffstat (limited to 'tests/storage/test_parser2.cpp')
-rw-r--r--tests/storage/test_parser2.cpp33
1 files changed, 29 insertions, 4 deletions
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 <errno.h>
#include <stdio.h>
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#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;
}