From ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 24 Mar 2020 12:27:33 -0400 Subject: Initial commit of tests --- tests/test_str_lstrip.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_str_lstrip.c (limited to 'tests/test_str_lstrip.c') diff --git a/tests/test_str_lstrip.c b/tests/test_str_lstrip.c new file mode 100644 index 0000000..fa0c187 --- /dev/null +++ b/tests/test_str_lstrip.c @@ -0,0 +1,36 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case '%s': returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.caseValue.str = " four spaces", .truthValue.sptr = "four spaces"}, + {.caseValue.str = "\tone tab", .truthValue.sptr = "one tab"}, + {.caseValue.str = "\na new line", .truthValue.sptr = "a new line"}, + {.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++) { + char *caseValue = NULL; + char *orig = NULL; + char *result = NULL; + + if (testCase[i].caseValue.sptr != NULL) { + caseValue = strdup(testCase[i].caseValue.str); + orig = strdup(caseValue); + result = lstrip(caseValue); + } + + if (testCase[i].truthValue.sptr == NULL && result == NULL) { + continue; + } else if (testCase[i].truthValue.sptr != NULL && result == NULL) { + fprintf(stderr, testFmt, orig, result, testCase[i].truthValue.sptr); + return 1; + } + myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, orig, result, testCase[i].truthValue.sptr); + free(caseValue); + free(orig); + } + return 0; +} \ No newline at end of file -- cgit