aboutsummaryrefslogtreecommitdiff
path: root/tests/test_str_strdelsuffix.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_strdelsuffix.c
parentccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (diff)
downloadspmc-ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630.tar.gz
Initial commit of tests
Diffstat (limited to 'tests/test_str_strdelsuffix.c')
-rw-r--r--tests/test_str_strdelsuffix.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_str_strdelsuffix.c b/tests/test_str_strdelsuffix.c
new file mode 100644
index 0000000..0bc9c85
--- /dev/null
+++ b/tests/test_str_strdelsuffix.c
@@ -0,0 +1,24 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "could not remove '%s' from '%s', expecting '%s'\n";
+struct TestCase testCase[] = {
+ {.inputValue.sptr = "gumball", .caseValue.str = "abracadabra brisket gumball", .truthValue.sptr = "abracadabra brisket"},
+ {.inputValue.sptr = "y", .caseValue.str = "balloons are falling from the sky", .truthValue.sptr = "balloons are falling from the sk"},
+ {.inputValue.sptr = "ickly", .caseValue.str = "mangled mangoes oxidize quickly", .truthValue.sptr = "mangled mangoes oxidize qu"},
+ {.inputValue.sptr = "B", .caseValue.str = "bBbB", .truthValue.sptr = "bBb"},
+ {.inputValue.sptr = NULL, .caseValue.str = "bBbB", .truthValue.sptr = "bBbB"},
+ {.inputValue.sptr = "test", .caseValue.str = "\0", .truthValue.sptr = ""},
+ {.inputValue.sptr = NULL, .caseValue.str = "\0", .truthValue.sptr = ""},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ char *orig = strdup(testCase[i].caseValue.str);
+ strdelsuffix(testCase[i].caseValue.str, testCase[i].inputValue.sptr);
+ myassert(strcmp(testCase[i].caseValue.str, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].inputValue.sptr, orig, testCase[i].truthValue.sptr);
+ free(orig);
+ }
+ return 0;
+} \ No newline at end of file