aboutsummaryrefslogtreecommitdiff
path: root/tests/test_str_split.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-03-24 12:27:33 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-03-24 12:27:33 -0400
commitad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630 (patch)
tree4b31aa43dcb942611fef8699bc96d166cf63b68e /tests/test_str_split.c
parentccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (diff)
downloadspmc-ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630.tar.gz
Initial commit of tests
Diffstat (limited to 'tests/test_str_split.c')
-rw-r--r--tests/test_str_split.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_str_split.c b/tests/test_str_split.c
new file mode 100644
index 0000000..58ef56f
--- /dev/null
+++ b/tests/test_str_split.c
@@ -0,0 +1,29 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "could not split '%s' with '%s'\n";
+struct TestCase testCase[] = {
+ {.inputValue.sptr = " ", .caseValue.str = "one two three", .truthValue.slptr = (char *[]){"one", "two", "three", NULL}},
+ {.inputValue.sptr = "|", .caseValue.str = "one|two|three", .truthValue.slptr = (char *[]){"one", "two", "three", NULL}},
+ {.inputValue.sptr = "a", .caseValue.str = "123a456a789", .truthValue.slptr = (char *[]){"123", "456", "789", NULL}},
+ {.inputValue.sptr = "b", .caseValue.str = "123a456b789", .truthValue.slptr = (char *[]){"123a456", "789", NULL}},
+ {.inputValue.sptr = NULL, .caseValue.str = "123a456a789", .truthValue.slptr = NULL},
+ {.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 = split(testCase[i].caseValue.str, testCase[i].inputValue.sptr);
+ if (testCase[i].truthValue.slptr == NULL && result == NULL) {
+ continue;
+ }
+
+ for (size_t part = 0; testCase[i].truthValue.slptr[part] != NULL; part++) {
+ myassert(strcmp(result[part], testCase[i].truthValue.slptr[part]) == 0, testFmt, testCase[i].caseValue.str, testCase[i].inputValue.sptr);
+ }
+ split_free(result);
+ }
+ return 0;
+} \ No newline at end of file