diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-03-24 12:35:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-24 12:35:30 -0400 |
commit | ae3eb38592cb40011fd026d3c7c64ebc022bedca (patch) | |
tree | 5b576d374cc2d12bc5593c8b09adaa25c4453346 /tests/test_str_substring_between.c | |
parent | ccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (diff) | |
parent | 239251d34af9137acf7e84c6969e118d3b0593c0 (diff) | |
download | spmc-ae3eb38592cb40011fd026d3c7c64ebc022bedca.tar.gz |
Merge pull request #2 from jhunkeler/ctest
Implement ctest testing
Diffstat (limited to 'tests/test_str_substring_between.c')
-rw-r--r-- | tests/test_str_substring_between.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_str_substring_between.c b/tests/test_str_substring_between.c new file mode 100644 index 0000000..0177068 --- /dev/null +++ b/tests/test_str_substring_between.c @@ -0,0 +1,28 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case '%s': returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.inputValue.sptr = "[]", .caseValue.str = "[one two three]", .truthValue.sptr = "one two three"}, + {.inputValue.sptr = "..", .caseValue.str = ".[one].", .truthValue.sptr = "[one]"}, + {.inputValue.sptr = "\'\'", .caseValue.str = ".['one'].", .truthValue.sptr = "one"}, + {.inputValue.sptr = "@^", .caseValue.str = "abcdef@ghijkl^mnop@qrst^uvwxyz", .truthValue.sptr = "ghijkl"}, + {.inputValue.sptr = "", .caseValue.sptr = NULL, .truthValue.sptr = NULL}, + {.inputValue.sptr = NULL, .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 *result = substring_between(testCase[i].caseValue.str, testCase[i].inputValue.sptr); + if (testCase[i].truthValue.sptr == NULL && result == NULL) { + continue; + } else if (testCase[i].truthValue.sptr != NULL && result == NULL) { + fprintf(stderr, testFmt, testCase[i].caseValue.str, result, testCase[i].truthValue.sptr); + return 1; + } + myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.str, result, testCase[i].truthValue.sptr); + free(result); + } + return 0; +}
\ No newline at end of file |