Add failing test to issue #10

This commit is contained in:
c9s 2014-05-18 15:00:11 +08:00
parent c5198a91c7
commit d4c2c6b47e
4 changed files with 41 additions and 8 deletions

View file

@ -45,7 +45,7 @@ void r3_edge_branch(edge *e, int dl) {
int s1_len = 0;
edge **tmp_edges = e->child->edges;
int tmp_r3_edge_len = e->child->edge_len;
int tmp_edge_len = e->child->edge_len;
// the suffix edge of the leaf
c1 = r3_tree_create(3);
@ -54,7 +54,7 @@ void r3_edge_branch(edge *e, int dl) {
// printf("edge left: %s\n", e1->pattern);
// Migrate the child edges to the new edge we just created.
for ( int i = 0 ; i < tmp_r3_edge_len ; i++ ) {
for ( int i = 0 ; i < tmp_edge_len ; i++ ) {
r3_node_append_edge(c1, tmp_edges[i]);
e->child->edges[i] = NULL;
}
@ -65,6 +65,8 @@ void r3_edge_branch(edge *e, int dl) {
r3_node_append_edge(e->child, e1);
c1->endpoint++;
c1->data = e->child->data; // copy data pointer
e->child->data = NULL;
}
void r3_edge_free(edge * e) {

View file

@ -511,7 +511,12 @@ void r3_tree_dump(node * n, int level) {
printf(" regexp:%s", n->combined_pattern);
}
printf(" endpoint:%d\n", n->endpoint);
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];
@ -523,7 +528,7 @@ void r3_tree_dump(node * n, int level) {
printf("%s", compile_slug(e->pattern, e->pattern_len) );
}
if ( e->child && e->child->edges ) {
if ( e->child ) {
r3_tree_dump( e->child, level + 1);
}
printf("\n");

View file

@ -171,3 +171,11 @@
1400394571,8615372.65
1400394590,10964999.94
1400394658,11173658.86
1400395575,10502560.60
1400396023,10925991.89
1400396031,10299722.97
1400396055,10781849.35
1400396123,10746610.69
1400396341,10811271.16
1400396368,10631572.01
1400396396,10442039.18

1 1400242718 5649455.80
171 1400394571 8615372.65
172 1400394590 10964999.94
173 1400394658 11173658.86
174 1400395575 10502560.60
175 1400396023 10925991.89
176 1400396031 10299722.97
177 1400396055 10781849.35
178 1400396123 10746610.69
179 1400396341 10811271.16
180 1400396368 10631572.01
181 1400396396 10442039.18

View file

@ -271,11 +271,24 @@ START_TEST(test_pcre_pattern_more)
entry = match_entry_createl( "/user/123" , strlen("/user/123") );
node * n = r3_tree_create(10);
r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, NULL);
r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, NULL);
int var0 = 5;
int var1 = 100;
int var2 = 200;
int var3 = 300;
printf("var0: %p\n", &var0);
printf("var1: %p\n", &var1);
printf("var2: %p\n", &var2);
printf("var3: %p\n", &var3);
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_dump(n, 0);
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_dump(n, 0);
r3_tree_compile(n);
r3_tree_dump(n, 0);
node *matched;
@ -284,16 +297,21 @@ START_TEST(test_pcre_pattern_more)
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*) matched->data), var1);
/*
matched = r3_tree_match(n, "/user2/123", strlen("/user2/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*)matched->data), var2);
matched = r3_tree_match(n, "/user3/123", strlen("/user3/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
fail_if( *((int*)matched->data), var3);
*/
}
END_TEST