test/string_tests.c

changeset 149
3bf87676d42d
parent 148
c27c2425c0b1
child 173
31a8682fffb7
equal deleted inserted replaced
148:c27c2425c0b1 149:3bf87676d42d
67 UCX_TEST_END 67 UCX_TEST_END
68 68
69 free(cat.ptr); 69 free(cat.ptr);
70 } 70 }
71 71
72 UCX_TEST(test_sstrchr) { 72 UCX_TEST(test_sstrchr_sstrrchr) {
73 sstr_t str = ST("I will find you - and I will kill you"); 73 sstr_t str = ST("I will find you - and I will kill you");
74 UCX_TEST_BEGIN 74 UCX_TEST_BEGIN
75 75
76 sstr_t result = sstrchr(str, 'w'); 76 sstr_t result = sstrchr(str, 'w');
77 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length"); 77 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
81 result = sstrrchr(str, 'w'); 81 result = sstrrchr(str, 'w');
82 UCX_TEST_ASSERT(result.length == 13, "sstrrchr returned wrong length"); 82 UCX_TEST_ASSERT(result.length == 13, "sstrrchr returned wrong length");
83 UCX_TEST_ASSERT(strcmp("will kill you", result.ptr) 83 UCX_TEST_ASSERT(strcmp("will kill you", result.ptr)
84 == 0, "sstrrchr did not return the expected string"); 84 == 0, "sstrrchr did not return the expected string");
85 85
86 UCX_TEST_END
87 }
88
89 UCX_TEST(test_sstrcmp) {
90 sstr_t str = ST("compare this");
91
92 UCX_TEST_BEGIN
93 UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
94 UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
95 UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed");
96 UCX_TEST_ASSERT(sstrcmp(str, S("compare shit")) > 0, "memcmp > 0 failed");
97 UCX_TEST_ASSERT(sstrcmp(str, S("compare this not")) < 0, "len < 0 failed");
98 UCX_TEST_ASSERT(sstrcmp(str, S("compare")) > 0, "len > 0 failed");
99 UCX_TEST_END
100 }
101
102 UCX_TEST(test_sstrcasecmp) {
103
104 sstr_t str = ST("compare this");
105
106 UCX_TEST_BEGIN
107 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
108 UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
109 "not ignoring case");
110 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed");
111 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed");
112 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this not")) < 0,
113 "len < 0 failed");
114 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare")) > 0, "len > 0 failed");
86 UCX_TEST_END 115 UCX_TEST_END
87 } 116 }
88 117
89 UCX_TEST(test_sstrsplit) { 118 UCX_TEST(test_sstrsplit) {
90 119

mercurial