aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-03-27 16:47:19 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-03-27 16:47:19 -0400
commitd0095b6d304bba14d0f93185939ce864843fa152 (patch)
treee0ca2fadb35cec1aea6ca9fad885fe9ba9d823a9
parent2433d04fb3d3204cdc041ed7d9e2509ce2684ea7 (diff)
downloadspmc-d0095b6d304bba14d0f93185939ce864843fa152.tar.gz
Add normalize_space test
-rw-r--r--tests/test_str_normalize_space.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_str_normalize_space.c b/tests/test_str_normalize_space.c
new file mode 100644
index 0000000..286353d
--- /dev/null
+++ b/tests/test_str_normalize_space.c
@@ -0,0 +1,29 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "case: '%s': returned '%s', expected '%s'\n";
+struct TestCase testCase[] = {
+ {.caseValue.sptr = "no extra whitespace in the string", .truthValue.sptr = "no extra whitespace in the string"},
+ {.caseValue.sptr = "two extra spaces in the string", .truthValue.sptr = "two extra spaces in the string"},
+ {.caseValue.sptr = "three extra spaces in the string", .truthValue.sptr = "three extra spaces in the string"},
+ {.caseValue.sptr = " leading whitespace", .truthValue.sptr = "leading whitespace"},
+ {.caseValue.sptr = "trailing whitespace ", .truthValue.sptr = "trailing whitespace"},
+ {.caseValue.sptr = " leading and trailing whitespace ", .truthValue.sptr = "leading and trailing whitespace"},
+ {.caseValue.sptr = " varying degrees of whitespace everywhere ", .truthValue.sptr = "varying degrees of whitespace everywhere"},
+ {.caseValue.sptr = "nowhitespace", .truthValue.sptr = "nowhitespace"},
+ {.caseValue.sptr = NULL, .truthValue.sptr = NULL},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ if (testCase[i].caseValue.sptr == NULL && testCase[i].truthValue.sptr == NULL) {
+ // null input is null output
+ continue;
+ }
+ char *result = strdup(testCase[i].caseValue.sptr);
+ normalize_space(result);
+ myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.sptr);
+ }
+ return 0;
+} \ No newline at end of file