Fix tests for #10

This commit is contained in:
c9s 2014-05-18 15:06:11 +08:00
parent d4c2c6b47e
commit 4565346298
3 changed files with 38 additions and 36 deletions

View file

@ -506,33 +506,31 @@ bool r3_node_has_slug_edges(node *n) {
void r3_tree_dump(node * n, int level) { void r3_tree_dump(node * n, int level) {
if ( n->edge_len ) { if ( n->combined_pattern ) {
if ( n->combined_pattern ) { printf(" regexp:%s", n->combined_pattern);
printf(" regexp:%s", n->combined_pattern); }
printf(" endpoint:%d", n->endpoint);
if (n->data) {
printf(" data:%p", n->data);
}
printf("\n");
for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level);
printf(" |-\"%s\"", e->pattern);
if (e->has_slug) {
printf(" slug:");
printf("%s", compile_slug(e->pattern, e->pattern_len) );
} }
printf(" endpoint:%d", n->endpoint); if ( e->child ) {
r3_tree_dump( e->child, level + 1);
if (n->data) {
printf(" data:%p", n->data);
} }
printf("\n"); printf("\n");
for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level);
printf(" |-\"%s\"", e->pattern);
if (e->has_slug) {
printf(" slug:");
printf("%s", compile_slug(e->pattern, e->pattern_len) );
}
if ( e->child ) {
r3_tree_dump( e->child, level + 1);
}
printf("\n");
}
} }
} }

View file

@ -179,3 +179,10 @@
1400396341,10811271.16 1400396341,10811271.16
1400396368,10631572.01 1400396368,10631572.01
1400396396,10442039.18 1400396396,10442039.18
1400396467,10833155.84
1400396500,10639776.08
1400396541,9454881.65
1400396547,10795847.32
1400396725,10488850.71
1400396745,10442025.32
1400396765,10689592.72

1 1400242718 5649455.80
179 1400396341 10811271.16
180 1400396368 10631572.01
181 1400396396 10442039.18
182 1400396467 10833155.84
183 1400396500 10639776.08
184 1400396541 9454881.65
185 1400396547 10795847.32
186 1400396725 10488850.71
187 1400396745 10442025.32
188 1400396765 10689592.72

View file

@ -276,19 +276,15 @@ START_TEST(test_pcre_pattern_more)
int var2 = 200; int var2 = 200;
int var3 = 300; int var3 = 300;
printf("var0: %p\n", &var0); info("var0: %p\n", &var0);
printf("var1: %p\n", &var1); info("var1: %p\n", &var1);
printf("var2: %p\n", &var2); info("var2: %p\n", &var2);
printf("var3: %p\n", &var3); info("var3: %p\n", &var3);
r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, &var1); r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, &var1);
r3_tree_dump(n, 0);
r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, &var2); r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, &var2);
r3_tree_dump(n, 0);
r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, &var3); r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, &var3);
r3_tree_dump(n, 0);
r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, &var0); r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, &var0);
r3_tree_dump(n, 0);
r3_tree_compile(n); r3_tree_compile(n);
r3_tree_dump(n, 0); r3_tree_dump(n, 0);
node *matched; node *matched;
@ -297,21 +293,22 @@ START_TEST(test_pcre_pattern_more)
fail_if(matched == NULL); fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0); ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123"); ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*) matched->data), var1);
/* info("matched %p\n", matched->data);
info("matched %p\n", matched->data);
ck_assert_int_eq( *((int*) matched->data), var1);
matched = r3_tree_match(n, "/user2/123", strlen("/user2/123"), entry); matched = r3_tree_match(n, "/user2/123", strlen("/user2/123"), entry);
fail_if(matched == NULL); fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0); ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123"); ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*)matched->data), var2); ck_assert_int_eq( *((int*)matched->data), var2);
matched = r3_tree_match(n, "/user3/123", strlen("/user3/123"), entry); matched = r3_tree_match(n, "/user3/123", strlen("/user3/123"), entry);
fail_if(matched == NULL); fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0); ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123"); ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*)matched->data), var3); ck_assert_int_eq( *((int*)matched->data), var3);
*/
} }
END_TEST END_TEST