add result_length test
This commit is contained in:
parent
bfb795b093
commit
29434869d5
1 changed files with 55 additions and 0 deletions
|
|
@ -503,6 +503,55 @@ static void test_iterative_lookahead(gconstpointer backend) {
|
|||
g_check_parse_chunks_failed_(p, "fo",2, "b",1);
|
||||
}
|
||||
|
||||
static void test_iterative_result_length(gconstpointer backend) {
|
||||
HParserBackend be = (HParserBackend)GPOINTER_TO_INT(backend);
|
||||
HParser *p = h_token((uint8_t*)"foobar", 6);
|
||||
|
||||
if(h_compile(p, be, NULL) != 0) {
|
||||
g_test_message("Compile failed");
|
||||
g_test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
HSuspendedParser *s = h_parse_start(p);
|
||||
if(!s) {
|
||||
g_test_message("Chunked parsing not available");
|
||||
g_test_fail();
|
||||
return;
|
||||
}
|
||||
h_parse_chunk(s, (uint8_t*)"foo", 3);
|
||||
h_parse_chunk(s, (uint8_t*)"ba", 2);
|
||||
h_parse_chunk(s, (uint8_t*)"rbaz", 4);
|
||||
HParseResult *r = h_parse_finish(s);
|
||||
if(!r) {
|
||||
g_test_message("Parse failed");
|
||||
g_test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
g_check_cmp_int64(r->bit_length, ==, 48);
|
||||
}
|
||||
|
||||
static void test_result_length(gconstpointer backend) {
|
||||
HParserBackend be = (HParserBackend)GPOINTER_TO_INT(backend);
|
||||
HParser *p = h_token((uint8_t*)"foo", 3);
|
||||
|
||||
if(h_compile(p, be, NULL) != 0) {
|
||||
g_test_message("Compile failed");
|
||||
g_test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
HParseResult *r = h_parse(p, (uint8_t*)"foobar", 6);
|
||||
if(!r) {
|
||||
g_test_message("Parse failed");
|
||||
g_test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
g_check_cmp_int64(r->bit_length, ==, 24);
|
||||
}
|
||||
|
||||
static void test_ambiguous(gconstpointer backend) {
|
||||
HParser *d_ = h_ch('d');
|
||||
HParser *p_ = h_ch('+');
|
||||
|
|
@ -713,6 +762,7 @@ void register_parser_tests(void) {
|
|||
g_test_add_data_func("/core/parser/packrat/putget", GINT_TO_POINTER(PB_PACKRAT), test_put_get);
|
||||
g_test_add_data_func("/core/parser/packrat/permutation", GINT_TO_POINTER(PB_PACKRAT), test_permutation);
|
||||
g_test_add_data_func("/core/parser/packrat/bind", GINT_TO_POINTER(PB_PACKRAT), test_bind);
|
||||
g_test_add_data_func("/core/parser/packrat/result_length", GINT_TO_POINTER(PB_PACKRAT), test_result_length);
|
||||
|
||||
g_test_add_data_func("/core/parser/llk/token", GINT_TO_POINTER(PB_LLk), test_token);
|
||||
g_test_add_data_func("/core/parser/llk/ch", GINT_TO_POINTER(PB_LLk), test_ch);
|
||||
|
|
@ -751,8 +801,10 @@ void register_parser_tests(void) {
|
|||
g_test_add_data_func("/core/parser/llk/ignore", GINT_TO_POINTER(PB_LLk), test_ignore);
|
||||
//g_test_add_data_func("/core/parser/llk/leftrec", GINT_TO_POINTER(PB_LLk), test_leftrec);
|
||||
g_test_add_data_func("/core/parser/llk/rightrec", GINT_TO_POINTER(PB_LLk), test_rightrec);
|
||||
g_test_add_data_func("/core/parser/llk/result_length", GINT_TO_POINTER(PB_LLk), test_result_length);
|
||||
g_test_add_data_func("/core/parser/llk/iterative", GINT_TO_POINTER(PB_LLk), test_iterative);
|
||||
g_test_add_data_func("/core/parser/llk/iterative/lookahead", GINT_TO_POINTER(PB_LLk), test_iterative_lookahead);
|
||||
g_test_add_data_func("/core/parser/llk/iterative/result_length", GINT_TO_POINTER(PB_LLk), test_iterative_result_length);
|
||||
|
||||
g_test_add_data_func("/core/parser/regex/token", GINT_TO_POINTER(PB_REGULAR), test_token);
|
||||
g_test_add_data_func("/core/parser/regex/ch", GINT_TO_POINTER(PB_REGULAR), test_ch);
|
||||
|
|
@ -790,6 +842,7 @@ void register_parser_tests(void) {
|
|||
g_test_add_data_func("/core/parser/regex/epsilon_p", GINT_TO_POINTER(PB_REGULAR), test_epsilon_p);
|
||||
g_test_add_data_func("/core/parser/regex/attr_bool", GINT_TO_POINTER(PB_REGULAR), test_attr_bool);
|
||||
g_test_add_data_func("/core/parser/regex/ignore", GINT_TO_POINTER(PB_REGULAR), test_ignore);
|
||||
g_test_add_data_func("/core/parser/regex/result_length", GINT_TO_POINTER(PB_REGULAR), test_result_length);
|
||||
|
||||
g_test_add_data_func("/core/parser/lalr/token", GINT_TO_POINTER(PB_LALR), test_token);
|
||||
g_test_add_data_func("/core/parser/lalr/ch", GINT_TO_POINTER(PB_LALR), test_ch);
|
||||
|
|
@ -829,6 +882,7 @@ void register_parser_tests(void) {
|
|||
g_test_add_data_func("/core/parser/lalr/leftrec", GINT_TO_POINTER(PB_LALR), test_leftrec);
|
||||
g_test_add_data_func("/core/parser/lalr/leftrec-ne", GINT_TO_POINTER(PB_LALR), test_leftrec_ne);
|
||||
g_test_add_data_func("/core/parser/lalr/rightrec", GINT_TO_POINTER(PB_LALR), test_rightrec);
|
||||
g_test_add_data_func("/core/parser/lalr/result_length", GINT_TO_POINTER(PB_LALR), test_result_length);
|
||||
|
||||
g_test_add_data_func("/core/parser/glr/token", GINT_TO_POINTER(PB_GLR), test_token);
|
||||
g_test_add_data_func("/core/parser/glr/ch", GINT_TO_POINTER(PB_GLR), test_ch);
|
||||
|
|
@ -869,4 +923,5 @@ void register_parser_tests(void) {
|
|||
g_test_add_data_func("/core/parser/glr/leftrec-ne", GINT_TO_POINTER(PB_GLR), test_leftrec_ne);
|
||||
g_test_add_data_func("/core/parser/glr/rightrec", GINT_TO_POINTER(PB_GLR), test_rightrec);
|
||||
g_test_add_data_func("/core/parser/glr/ambiguous", GINT_TO_POINTER(PB_GLR), test_ambiguous);
|
||||
g_test_add_data_func("/core/parser/glr/result_length", GINT_TO_POINTER(PB_GLR), test_result_length);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue