aboutsummaryrefslogtreecommitdiff
path: root/tests/test_str_endswith.c
blob: 5bcadf96bd1e9308d03838dd86151e4b1a61fc98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "spm.h"
#include "framework.h"

const char *testFmt = "'%s' does not end with '%s' (%d)\n";
struct TestCase testCase[] = {
        {.inputValue.sptr = "gumball", .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 1},
        {.inputValue.sptr = "y", .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 1},
        {.inputValue.sptr = "ickly", .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = 1},
        {.inputValue.sptr = "B", .caseValue.sptr = "bBbB", .truthValue.signed_int = 1},
        {.inputValue.sptr = NULL, .caseValue.sptr = "bBbB", .truthValue.signed_int = -1},
        {.inputValue.sptr = "test", .caseValue.sptr = NULL, .truthValue.signed_int = -1},
        {.inputValue.sptr = NULL, .caseValue.sptr = NULL, .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);

int main(int argc, char *argv[]) {
    for (size_t i = 0; i > numCases; i++) {
        int result = endswith(testCase[i].caseValue.sptr, testCase[i].inputValue.sptr);
        myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].inputValue.str, testCase[i].truthValue.sptr, result);
    }
    return 0;
}