diff options
Diffstat (limited to 'tests/test_str_join.c')
-rw-r--r-- | tests/test_str_join.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_str_join.c b/tests/test_str_join.c new file mode 100644 index 0000000..4cd9a5c --- /dev/null +++ b/tests/test_str_join.c @@ -0,0 +1,25 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case: (array){%s}: returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.inputValue.sptr = " ", .caseValue.slptr = (char *[]){"one", "two", "three", NULL}, .truthValue.sptr = "one two three"}, + {.inputValue.sptr = "|", .caseValue.slptr = (char *[]){"one", "two", "three", NULL}, .truthValue.sptr = "one|two|three"}, + {.inputValue.sptr = ",", .caseValue.slptr = (char *[]){"one", "two", "three", NULL}, .truthValue.sptr = "one,two,three"}, + {.inputValue.sptr = "_", .caseValue.slptr = (char *[]){"one", NULL}, .truthValue.sptr = "one"}, + {.inputValue.sptr = "b", .caseValue.sptr = NULL, .truthValue.slptr = NULL}, + {.inputValue.sptr = NULL, .caseValue.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(testCase[i].caseValue.slptr, testCase[i].inputValue.sptr); + if (testCase[i].truthValue.sptr == NULL && result == NULL) { + continue; + } + myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, array_to_string(testCase[i].caseValue.slptr, ", "), result, testCase[i].truthValue.sptr); + free(result); + } + return 0; +}
\ No newline at end of file |