test r3_pattern_to_opcode
This commit is contained in:
parent
a41c9187ac
commit
4d93d217a4
3 changed files with 26 additions and 1 deletions
|
@ -174,6 +174,8 @@ route * r3_tree_match_route(const node *n, match_entry * entry);
|
|||
#define METHOD_HEAD 2<<5
|
||||
#define METHOD_OPTIONS 2<<6
|
||||
|
||||
enum { OP_EXPECT_DIGITS, OP_EXPECT_WORDS, OP_EXPECT_NOSLASH };
|
||||
int r3_pattern_to_opcode(char * pattern, int pattern_len);
|
||||
|
||||
enum { OP_EXPECT_DIGITS = 1, OP_EXPECT_WORDS, OP_EXPECT_NOSLASH };
|
||||
|
||||
#endif /* !R3_NODE_H */
|
||||
|
|
14
src/str.c
14
src/str.c
|
@ -13,6 +13,20 @@
|
|||
#include "str_array.h"
|
||||
#include "zmalloc.h"
|
||||
|
||||
int r3_pattern_to_opcode(char * pattern, int pattern_len) {
|
||||
if ( strncmp(pattern, "\\w+", pattern_len) == 0 ) {
|
||||
return OP_EXPECT_WORDS;
|
||||
}
|
||||
if ( strncmp(pattern, "\\d+", pattern_len) == 0 ) {
|
||||
return OP_EXPECT_DIGITS;
|
||||
}
|
||||
if ( strncmp(pattern, "[^/]+", pattern_len) == 0 ) {
|
||||
return OP_EXPECT_NOSLASH;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* provide a quick way to count slugs, simply search for '{'
|
||||
|
|
|
@ -13,6 +13,14 @@
|
|||
#include "str_array.h"
|
||||
#include "zmalloc.h"
|
||||
|
||||
START_TEST (test_pattern_to_opcode)
|
||||
{
|
||||
ck_assert( r3_pattern_to_opcode("\\w+", sizeof("\\w+") - 1) == OP_EXPECT_WORDS );
|
||||
ck_assert( r3_pattern_to_opcode("\\d+", sizeof("\\d+") - 1) == OP_EXPECT_DIGITS );
|
||||
ck_assert( r3_pattern_to_opcode("[^/]+", sizeof("[^/]+") - 1) == OP_EXPECT_NOSLASH );
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_slug_compile)
|
||||
{
|
||||
char * path = "/user/{id}";
|
||||
|
@ -106,6 +114,7 @@ Suite* r3_suite (void) {
|
|||
tcase_add_test(tcase, test_find_slug_placeholder_with_broken_slug);
|
||||
tcase_add_test(tcase, test_slug_count);
|
||||
tcase_add_test(tcase, test_slug_compile);
|
||||
tcase_add_test(tcase, test_pattern_to_opcode);
|
||||
|
||||
suite_add_tcase(suite, tcase);
|
||||
return suite;
|
||||
|
|
Loading…
Reference in a new issue