Add failing tests for {idx:\d{3}}-{idy:\d{3}} pattern

This commit is contained in:
c9s 2014-05-20 21:40:45 +08:00
parent b3e6321303
commit 268047c18c
2 changed files with 58 additions and 61 deletions

View file

@ -358,3 +358,29 @@
1400573847,10478482.69
1400573855,15087645.17
1400573891,15207920.79
1400592138,13289883.29
1400592160,13689866.38
1400592167,13887614.50
1400592181,12902438.30
1400592212,12711239.59
1400592282,13868279.63
1400592287,14008688.28
1400592314,13915819.27
1400592447,13857005.45
1400592453,13737673.35
1400592520,13746939.61
1400592698,13522088.67
1400592756,14069856.66
1400592898,13964804.85
1400592906,12335090.17
1400592931,14145688.00
1400592964,13071020.50
1400593034,13921007.60
1400593050,12790569.45
1400593062,13672159.26
1400593069,13522175.86
1400593171,13911803.66
1400593186,13788854.92
1400593197,13978543.79
1400593210,13568445.16
1400593219,13704926.07

1 1400242718 5649455.80
358 1400573847 10478482.69
359 1400573855 15087645.17
360 1400573891 15207920.79
361 1400592138 13289883.29
362 1400592160 13689866.38
363 1400592167 13887614.50
364 1400592181 12902438.30
365 1400592212 12711239.59
366 1400592282 13868279.63
367 1400592287 14008688.28
368 1400592314 13915819.27
369 1400592447 13857005.45
370 1400592453 13737673.35
371 1400592520 13746939.61
372 1400592698 13522088.67
373 1400592756 14069856.66
374 1400592898 13964804.85
375 1400592906 12335090.17
376 1400592931 14145688.00
377 1400592964 13071020.50
378 1400593034 13921007.60
379 1400593050 12790569.45
380 1400593062 13672159.26
381 1400593069 13522175.86
382 1400593171 13911803.66
383 1400593186 13788854.92
384 1400593197 13978543.79
385 1400593210 13568445.16
386 1400593219 13704926.07

View file

@ -70,19 +70,6 @@ START_TEST (test_compile)
#ifdef DEBUG
r3_tree_dump(n, 0);
#endif
/*
fail_if(n->edges[0]->child->combined_pattern == NULL);
e = r3_node_find_edge_str(n, "/", strlen("/") );
fail_if( NULL == e );
*/
/*
printf( "%s\n", e->pattern );
printf( "%s\n", e->child->combined_pattern );
printf( "%s\n", n->edges[0]->child->combined_pattern);
printf( "%s\n", n->combined_pattern );
*/
match_entry * entry;
entry = match_entry_createl( "foo" , strlen("/foo") );
@ -112,60 +99,14 @@ START_TEST (test_compile)
}
END_TEST
START_TEST (test_compile_slug)
{
/*
char * pattern;
pattern = compile_slug("{id}", strlen("{id}"));
ck_assert_str_eq( pattern, "([^/]+)" );
free(pattern);
pattern = compile_slug("/{id}", strlen("/{id}"));
ck_assert_str_eq( pattern, "/([^/]+)" );
free(pattern);
pattern = compile_slug("-{id}", strlen("-{id}"));
ck_assert_str_eq( pattern, "-([^-]+)" );
free(pattern);
pattern = compile_slug("{id}-{title}", strlen("{id}-{title}"));
ck_assert_str_eq( pattern, "([^/]+)-([^-]+)" );
free(pattern);
pattern = compile_slug("{id:[a-z]+}", strlen("{id:[a-z]+}") );
ck_assert_str_eq( pattern, "([a-z]+)" );
free(pattern);
pattern = compile_slug("/path/{id:[a-z]+}", strlen("/path/{id:[a-z]+}") );
ck_assert_str_eq( pattern, "/path/([a-z]+)" );
free(pattern);
*/
/*
char * p = malloc(sizeof(char) * 10);
strncat(p, "foo", 3);
free(p);
*/
}
END_TEST
START_TEST (test_pcre_patterns_insert)
{
node * n = r3_tree_create(10);
// r3_tree_insert_path(n, "/foo-{user}-{id}", NULL, NULL);
// r3_tree_dump(n, 0);
r3_tree_insert_path(n, "/post/{handle:\\d+}-{id:\\d+}", NULL);
r3_tree_compile(n);
r3_tree_dump(n, 0);
// r3_tree_dump(n, 0);
node *matched;
matched = r3_tree_matchl(n, "/post/111-222", strlen("/post/111-222"), NULL);
@ -182,6 +123,36 @@ START_TEST (test_pcre_patterns_insert)
END_TEST
/**
* Test for \d{3}-\d{4}
*/
START_TEST (test_pcre_patterns_insert_2)
{
node * n = r3_tree_create(10);
// r3_tree_insert_path(n, "/foo-{user}-{id}", NULL, NULL);
// r3_tree_dump(n, 0);
r3_tree_insert_path(n, "/post/{idx:\\d{2}}/{idy:\\d{2}}", NULL);
r3_tree_compile(n);
r3_tree_dump(n, 0);
node *matched;
matched = r3_tree_match(n, "/post/11/22", NULL);
ck_assert(matched);
ck_assert(matched->endpoint > 0);
/*
matched = r3_tree_match(n, "/post/11", NULL);
ck_assert(matched);
ck_assert_int_eq(matched->endpoint, 0);
r3_tree_free(n);
*/
}
END_TEST
START_TEST (test_r3_tree_insert_pathl)
@ -743,13 +714,13 @@ Suite* r3_suite (void) {
tcase_add_test(tcase, test_ltrim_slash);
tcase_add_test(tcase, test_r3_node_find_edge);
tcase_add_test(tcase, test_r3_tree_insert_pathl);
tcase_add_test(tcase, test_compile_slug);
tcase_add_test(tcase, test_compile);
tcase_add_test(tcase, test_route_cmp);
tcase_add_test(tcase, test_insert_route);
tcase_add_test(tcase, test_pcre_pattern_simple);
tcase_add_test(tcase, test_pcre_pattern_more);
tcase_add_test(tcase, test_pcre_patterns_insert);
tcase_add_test(tcase, test_pcre_patterns_insert_2);
tcase_add_test(tcase, benchmark_str);
suite_add_tcase(suite, tcase);