diff options
Diffstat (limited to 'tests/test_str_join_ex.c')
-rw-r--r-- | tests/test_str_join_ex.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_str_join_ex.c b/tests/test_str_join_ex.c new file mode 100644 index 0000000..7ce787f --- /dev/null +++ b/tests/test_str_join_ex.c @@ -0,0 +1,24 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case: returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.inputValue.sptr = " ", .truthValue.sptr = "one two three"}, + {.inputValue.sptr = "|", .truthValue.sptr = "one|two|three"}, + {.inputValue.sptr = ",", .truthValue.sptr = "one,two,three"}, + {.inputValue.sptr = "b", .truthValue.sptr = "onebtwobthree"}, + {.inputValue.sptr = NULL, .truthValue.slptr = NULL}, +}; +size_t numCases = sizeof(testCase) / sizeof(struct TestCase); + +int main(int argc, char *argv[]) { + for (size_t i = 0; i < numCases; i++) { + char *result = join_ex(testCase[i].inputValue.sptr, "one", "two", "three", NULL); + if (testCase[i].truthValue.sptr == NULL && result == NULL) { + continue; + } + myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, result, testCase[i].truthValue.sptr); + free(result); + } + return 0; +}
\ No newline at end of file |