test/string_tests.c

changeset 184
5c0990c95f74
parent 180
2185f19dcc45
child 192
1e51558b9d09
equal deleted inserted replaced
183:6a694f8f0084 184:5c0990c95f74
43 UCX_TEST(test_sstr_len) { 43 UCX_TEST(test_sstr_len) {
44 sstr_t s1 = ST("1234"); 44 sstr_t s1 = ST("1234");
45 sstr_t s2 = ST(".:.:."); 45 sstr_t s2 = ST(".:.:.");
46 sstr_t s3 = ST("X"); 46 sstr_t s3 = ST("X");
47 47
48 size_t len = sstrnlen(3, s1, s2, s3); 48 size_t len1 = sstrnlen(1, s1);
49 49 size_t len2 = sstrnlen(2, s1, s2);
50 UCX_TEST_BEGIN 50 size_t len3 = sstrnlen(3, s1, s2, s3);
51 51
52 UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size"); 52 UCX_TEST_BEGIN
53
54 UCX_TEST_ASSERT(len1 == 4, "sstrnlen returned wrong size");
55 UCX_TEST_ASSERT(len2 == 9, "sstrnlen returned wrong size");
56 UCX_TEST_ASSERT(len3 == 10, "sstrnlen returned wrong size");
53 57
54 UCX_TEST_END 58 UCX_TEST_END
55 } 59 }
56 60
57 61
58 UCX_TEST(test_sstrchr_sstrrchr) { 62 UCX_TEST(test_sstrchr_sstrrchr) {
59 sstr_t str = ST("I will find you - and I will kill you"); 63 sstr_t str = ST("I will find you - and I will kill you");
60 UCX_TEST_BEGIN 64 UCX_TEST_BEGIN
65
66 sstr_t notfound = sstrchr(str, 'x');
67 UCX_TEST_ASSERT(notfound.length == 0, "string length not 0");
61 68
62 sstr_t result = sstrchr(str, 'w'); 69 sstr_t result = sstrchr(str, 'w');
63 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length"); 70 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
64 UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr) 71 UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr)
65 == 0, "sstrchr did not return the expected string"); 72 == 0, "sstrchr did not return the expected string");
74 81
75 UCX_TEST(test_sstrcmp) { 82 UCX_TEST(test_sstrcmp) {
76 sstr_t str = ST("compare this"); 83 sstr_t str = ST("compare this");
77 84
78 UCX_TEST_BEGIN 85 UCX_TEST_BEGIN
86 UCX_TEST_ASSERT(sstrcmp(str, S("")) == 1, "empty cmp failed");
87 UCX_TEST_ASSERT(sstrcmp(S(""), S("")) == 0, "empty cmp false negative");
79 UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative"); 88 UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
80 UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive"); 89 UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
81 UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed"); 90 UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed");
82 UCX_TEST_ASSERT(sstrcmp(str, S("compare shit")) > 0, "memcmp > 0 failed"); 91 UCX_TEST_ASSERT(sstrcmp(str, S("compare shit")) > 0, "memcmp > 0 failed");
83 UCX_TEST_ASSERT(sstrcmp(str, S("compare this not")) < 0, "len < 0 failed"); 92 UCX_TEST_ASSERT(sstrcmp(str, S("compare this not")) < 0, "len < 0 failed");
88 UCX_TEST(test_sstrcasecmp) { 97 UCX_TEST(test_sstrcasecmp) {
89 98
90 sstr_t str = ST("compare this"); 99 sstr_t str = ST("compare this");
91 100
92 UCX_TEST_BEGIN 101 UCX_TEST_BEGIN
102 UCX_TEST_ASSERT(sstrcasecmp(str, S("")) == 1, "empty cmp failed");
103 UCX_TEST_ASSERT(sstrcasecmp(S(""), S("")) == 0, "empty cmp false negative");
93 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative"); 104 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
94 UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0, 105 UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
95 "not ignoring case"); 106 "not ignoring case");
96 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed"); 107 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed");
97 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed"); 108 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed");

mercurial