2019-06-30 22:46:51 -04:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <check.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "r3.h"
|
|
|
|
#include "r3_slug.h"
|
|
|
|
|
2019-07-20 19:48:11 -04:00
|
|
|
START_TEST (greedy_pattern)
|
2019-06-30 22:46:51 -04:00
|
|
|
{
|
|
|
|
R3Node * n = r3_tree_create(10);
|
|
|
|
match_entry * entry;
|
|
|
|
R3Route *matched_route;
|
|
|
|
|
|
|
|
char * uri0 = "/foo{:.*}";
|
|
|
|
r3_tree_insert_routel(n, 0, uri0, strlen(uri0), &uri0);
|
|
|
|
|
|
|
|
char * err = NULL;
|
|
|
|
r3_tree_compile(n, &err);
|
|
|
|
ck_assert(err == NULL);
|
|
|
|
|
|
|
|
entry = match_entry_create("/foo/bar");
|
|
|
|
matched_route = r3_tree_match_route(n, entry);
|
|
|
|
ck_assert(matched_route != NULL);
|
|
|
|
ck_assert(matched_route->data == &uri0);
|
|
|
|
|
2019-07-19 18:51:18 -04:00
|
|
|
entry = match_entry_create("/foo");
|
|
|
|
matched_route = r3_tree_match_route(n, entry);
|
|
|
|
ck_assert(matched_route != NULL);
|
|
|
|
ck_assert(matched_route->data == &uri0);
|
2019-06-30 22:46:51 -04:00
|
|
|
|
|
|
|
entry = match_entry_create("/foo/");
|
|
|
|
matched_route = r3_tree_match_route(n, entry);
|
|
|
|
ck_assert(matched_route != NULL);
|
|
|
|
ck_assert(matched_route->data == &uri0);
|
|
|
|
|
|
|
|
entry = match_entry_create("/foo/bar/foo/mmasdfasdfasd/f/asdf/as/df");
|
|
|
|
matched_route = r3_tree_match_route(n, entry);
|
|
|
|
ck_assert(matched_route != NULL);
|
|
|
|
ck_assert(matched_route->data == &uri0);
|
|
|
|
|
|
|
|
r3_tree_free(n);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
Suite* r3_suite (void) {
|
|
|
|
Suite *suite = suite_create("r3 routes2 tests");
|
|
|
|
TCase *tcase = tcase_create("testcase");
|
2019-07-20 19:48:11 -04:00
|
|
|
tcase_add_test(tcase, greedy_pattern);
|
2019-06-30 22:46:51 -04:00
|
|
|
suite_add_tcase(suite, tcase);
|
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
|
|
|
int number_failed;
|
|
|
|
Suite *suite = r3_suite();
|
|
|
|
SRunner *runner = srunner_create(suite);
|
|
|
|
srunner_run_all(runner, CK_NORMAL);
|
|
|
|
number_failed = srunner_ntests_failed(runner);
|
|
|
|
srunner_free(runner);
|
|
|
|
return number_failed;
|
|
|
|
}
|