From 5f39b7321124f98a369110c7f0922c6cd0db11bd Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 Oct 2015 07:39:32 +0800 Subject: [PATCH] Add test_root_match test case --- tests/check_tree.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/check_tree.c b/tests/check_tree.c index 630ae52..92e47dc 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -384,6 +384,45 @@ START_TEST (test_pcre_patterns_insert) END_TEST +/** + * Test for root '/' + */ +START_TEST (test_root_match) +{ + node * n = r3_tree_create(10); + + int a = 10; + int b = 20; + int c = 30; + r3_tree_insert_path(n, "/", &a); + r3_tree_insert_path(n, "/foo", &b); + r3_tree_insert_path(n, "/bar", &c); + + char *errstr = NULL; + r3_tree_compile(n, &errstr); + + r3_tree_dump(n, 0); + node *matched; + matched = r3_tree_match(n, "/", NULL); + ck_assert(matched); + ck_assert(matched->data == &a); + ck_assert(matched->endpoint > 0); + + matched = r3_tree_match(n, "/foo", NULL); + ck_assert(matched); + ck_assert(matched->data == &b); + ck_assert(matched->endpoint > 0); + + matched = r3_tree_match(n, "/bar", NULL); + ck_assert(matched); + ck_assert(matched->data == &c); + ck_assert(matched->endpoint > 0); +} +END_TEST + + + + /** * Test for \d{2}/\d{2} */ @@ -720,6 +759,7 @@ Suite* r3_suite (void) { 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, test_root_match); tcase_add_test(tcase, test_pcre_patterns_insert_3); tcase_add_test(tcase, test_incomplete_slug_path); suite_add_tcase(suite, tcase);