Skip to content

Commit

Permalink
add some more string unit tests for split and case
Browse files Browse the repository at this point in the history
  • Loading branch information
crowell committed Jun 9, 2016
1 parent c5afe78 commit 8d2a13d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ all: test_list test_base64 test_str
LDFLAGS=-lr_util

test_list:
$(CC) -g -I$(LIBR_INCLUDE) test_list.c $(LIBR_UTIL)/list.c -o test_list -L$(LIBR_UTIL) $(LDFLAGS)
$(CC) -g -I$(LIBR_INCLUDE) test_list.c -o test_list -L$(LIBR_UTIL) $(LDFLAGS)

test_base64:
$(CC) -g -I$(LIBR_INCLUDE) test_base64.c $(LIBR_UTIL)/base64.c -o test_base64 -L$(LIBR_UTIL) $(LDFLAGS)
$(CC) -g -I$(LIBR_INCLUDE) test_base64.c -o test_base64 -L$(LIBR_UTIL) $(LDFLAGS)

test_str:
$(CC) -g -I$(LIBR_INCLUDE) test_str.c $(LIBR_UTIL)/str.c -o test_str -L$(LIBR_UTIL) $(LDFLAGS)
$(CC) -g -I$(LIBR_INCLUDE) test_str.c -o test_str -L$(LIBR_UTIL) $(LDFLAGS)

clean:
rm test_list test_base64 test_str
Expand Down
38 changes: 37 additions & 1 deletion unit/test_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ bool test_r_str_rwx_i(void) {
mu_end;
}

//TODO find a way to test r_str_home.

bool test_r_str_bool(void) {
const char* one = r_str_bool(1);
const char* zero = r_str_bool(0);
Expand All @@ -80,7 +82,39 @@ bool test_r_str_bool(void) {
mu_end;
}

//TODO find a way to test r_str_home.
bool test_r_str_case(void) {
char* str1_mixedcase = strdup ("mIxEdCaSe");
char* str2_mixedcase = strdup ("mIxEdCaSe");
r_str_case (str1_mixedcase, true /*upcase*/);
r_str_case (str2_mixedcase, false /*downcase*/);
mu_assert_streq (str1_mixedcase, "MIXEDCASE", "upcase");
mu_assert_streq (str2_mixedcase, "mixedcase", "downcase");
char* non_alphanum_1 = strdup ("c00lstring!");
char* non_alphanum_2 = strdup ("c00lstrinG!");
r_str_case (non_alphanum_1, true /*upcase*/);
r_str_case (non_alphanum_2, false /*downcase*/);
mu_assert_streq (non_alphanum_1, "C00LSTRING!", "upcase, nonalpanum");
mu_assert_streq (non_alphanum_2, "c00lstring!", "downcase, nonalpanum");
free (str1_mixedcase);
free (str2_mixedcase);
free (non_alphanum_1);
free (non_alphanum_2);
mu_end;
}

//TODO test r_str_hash64, r_str_hash
//TODO test r_str_delta (WTF!)

bool test_r_str_split(void) {
char* hi = strdup ("hello world");
mu_assert_eq (r_str_split (hi, ' '), 1, "split on space");
char* hello = hi;
char* world = hi + 6;
mu_assert_streq (hello, "hello", "first string in split");
mu_assert_streq (world, "world", "second string in split");
free (hi);
mu_end;
}

bool all_tests() {
mu_run_test(test_r_str_replace_char_once);
Expand All @@ -89,6 +123,8 @@ bool all_tests() {
mu_run_test(test_r_str_rwx);
mu_run_test(test_r_str_rwx_i);
mu_run_test(test_r_str_bool);
mu_run_test(test_r_str_case);
mu_run_test(test_r_str_split);
return tests_passed != tests_run;
}

Expand Down

0 comments on commit 8d2a13d

Please sign in to comment.