ltrim_slash and related test

This commit is contained in:
c9s 2014-05-15 12:53:48 +08:00
parent c91c06ec3b
commit 3989f2150f
3 changed files with 30 additions and 2 deletions

View file

@ -7,5 +7,8 @@
#ifndef STR_H #ifndef STR_H
#define STR_H #define STR_H
char * ltrim_slash(char* str);
char** str_split(char* a_str, const char a_delim);
#endif /* !STR_H */ #endif /* !STR_H */

View file

@ -13,6 +13,13 @@
char * ltrim_slash(char* str)
{
char * p = str;
while (*p == '/') p++;
return strdup(p);
}
char** str_split(char* a_str, const char a_delim) char** str_split(char* a_str, const char a_delim)
{ {
char** result = 0; char** result = 0;

View file

@ -4,6 +4,14 @@
#include "node.h" #include "node.h"
#include "token.h" #include "token.h"
START_TEST (test_ltrim_slash)
{
fail_if( strcmp( ltrim_slash("/blog") , "blog" ) != 0 );
fail_if( strcmp( ltrim_slash("blog") , "blog" ) != 0 );
}
END_TEST
START_TEST (test_route) START_TEST (test_route)
{ {
token_array *t; token_array *t;
@ -42,13 +50,22 @@ END_TEST
START_TEST (test_token_array) START_TEST (test_token_array)
{ {
token_array * l = token_array_create(10); token_array * l = token_array_create(3);
fail_if( l == NULL ); fail_if( l == NULL );
fail_if( FALSE == token_array_resize(l, l->cap * 2) );
fail_if( FALSE == token_array_append(l, strdup("abc") ) ); fail_if( FALSE == token_array_append(l, strdup("abc") ) );
fail_if( l->len != 1 );
fail_if( FALSE == token_array_append(l, strdup("foo") ) ); fail_if( FALSE == token_array_append(l, strdup("foo") ) );
fail_if( l->len != 2 );
fail_if( FALSE == token_array_append(l, strdup("bar") ) ); fail_if( FALSE == token_array_append(l, strdup("bar") ) );
fail_if( l->len != 3 );
fail_if( FALSE == token_array_append(l, strdup("zoo") ) );
fail_if( l->len != 4 );
fail_if( FALSE == token_array_resize(l, l->cap * 2) );
token_array_free(l); token_array_free(l);
} }
@ -60,6 +77,7 @@ Suite* r3_suite (void) {
TCase *tcase = tcase_create("testcase"); TCase *tcase = tcase_create("testcase");
tcase_add_test(tcase, test_route); tcase_add_test(tcase, test_route);
tcase_add_test(tcase, test_token_array); tcase_add_test(tcase, test_token_array);
tcase_add_test(tcase, test_ltrim_slash);
suite_add_tcase(suite, tcase); suite_add_tcase(suite, tcase);