test/test_string.cpp

changeset 588
6a3cd8f0a2cf
parent 587
3dd55e246d2d
child 589
c290f8fd979e
equal deleted inserted replaced
587:3dd55e246d2d 588:6a3cd8f0a2cf
185 } 185 }
186 186
187 TEST(String, strcmp) { 187 TEST(String, strcmp) {
188 cxstring str = CX_STR("compare this"); 188 cxstring str = CX_STR("compare this");
189 189
190 EXPECT_EQ(cx_strcmp(CX_STR(""), CX_STR("")), 0); 190 EXPECT_EQ(cx_strcmp(cx_str(""), cx_str("")), 0);
191 EXPECT_GT(cx_strcmp(str, CX_STR("")), 0); 191 EXPECT_GT(cx_strcmp(str, cx_str("")), 0);
192 EXPECT_EQ(cx_strcmp(str, CX_STR("compare this")), 0); 192 EXPECT_EQ(cx_strcmp(str, cx_str("compare this")), 0);
193 EXPECT_NE(cx_strcmp(str, CX_STR("Compare This")), 0); 193 EXPECT_NE(cx_strcmp(str, cx_str("Compare This")), 0);
194 EXPECT_LT(cx_strcmp(str, CX_STR("compare tool")), 0); 194 EXPECT_LT(cx_strcmp(str, cx_str("compare tool")), 0);
195 EXPECT_GT(cx_strcmp(str, CX_STR("compare shit")), 0); 195 EXPECT_GT(cx_strcmp(str, cx_str("compare shit")), 0);
196 EXPECT_LT(cx_strcmp(str, CX_STR("compare this not")), 0); 196 EXPECT_LT(cx_strcmp(str, cx_str("compare this not")), 0);
197 EXPECT_GT(cx_strcmp(str, CX_STR("compare")), 0); 197 EXPECT_GT(cx_strcmp(str, cx_str("compare")), 0);
198 } 198 }
199 199
200 TEST(String, strcasecmp) { 200 TEST(String, strcasecmp) {
201 cxstring str = CX_STR("compare this"); 201 cxstring str = CX_STR("compare this");
202 202
203 EXPECT_EQ(cx_strcasecmp(CX_STR(""), CX_STR("")), 0); 203 EXPECT_EQ(cx_strcasecmp(cx_str(""), cx_str("")), 0);
204 EXPECT_GT(cx_strcasecmp(str, CX_STR("")), 0); 204 EXPECT_GT(cx_strcasecmp(str, cx_str("")), 0);
205 EXPECT_EQ(cx_strcasecmp(str, CX_STR("compare this")), 0); 205 EXPECT_EQ(cx_strcasecmp(str, cx_str("compare this")), 0);
206 EXPECT_EQ(cx_strcasecmp(str, CX_STR("Compare This")), 0); 206 EXPECT_EQ(cx_strcasecmp(str, cx_str("Compare This")), 0);
207 EXPECT_LT(cx_strcasecmp(str, CX_STR("compare tool")), 0); 207 EXPECT_LT(cx_strcasecmp(str, cx_str("compare tool")), 0);
208 EXPECT_GT(cx_strcasecmp(str, CX_STR("compare shit")), 0); 208 EXPECT_GT(cx_strcasecmp(str, cx_str("compare shit")), 0);
209 EXPECT_LT(cx_strcasecmp(str, CX_STR("compare this not")), 0); 209 EXPECT_LT(cx_strcasecmp(str, cx_str("compare this not")), 0);
210 EXPECT_GT(cx_strcasecmp(str, CX_STR("compare")), 0); 210 EXPECT_GT(cx_strcasecmp(str, cx_str("compare")), 0);
211 } 211 }
212 212
213 213
214 TEST(String, strcat) { 214 TEST(String, strcat) {
215 cxstring s1 = CX_STR("12"); 215 cxstring s1 = CX_STR("12");
218 cxstring sn = {nullptr, 0}; 218 cxstring sn = {nullptr, 0};
219 219
220 CxTestingAllocator alloc; 220 CxTestingAllocator alloc;
221 221
222 cxmutstr t1 = cx_strcat_a(&alloc, 2, s1, s2); 222 cxmutstr t1 = cx_strcat_a(&alloc, 2, s1, s2);
223 EXPECT_EQ(cx_strcmp(cx_strcast(t1), CX_STR("1234")), 0); 223 EXPECT_EQ(cx_strcmp(cx_strcast(t1), cx_str("1234")), 0);
224 cx_strfree_a(&alloc, &t1); 224 cx_strfree_a(&alloc, &t1);
225 225
226 cxmutstr t2 = cx_strcat_a(&alloc, 3, s1, s2, s3); 226 cxmutstr t2 = cx_strcat_a(&alloc, 3, s1, s2, s3);
227 EXPECT_EQ(cx_strcmp(cx_strcast(t2), CX_STR("123456")), 0); 227 EXPECT_EQ(cx_strcmp(cx_strcast(t2), cx_str("123456")), 0);
228 cx_strfree_a(&alloc, &t2); 228 cx_strfree_a(&alloc, &t2);
229 229
230 cxmutstr t3 = cx_strcat_a(&alloc, 6, s1, sn, s2, sn, s3, sn); 230 cxmutstr t3 = cx_strcat_a(&alloc, 6, s1, sn, s2, sn, s3, sn);
231 EXPECT_EQ(cx_strcmp(cx_strcast(t3), CX_STR("123456")), 0); 231 EXPECT_EQ(cx_strcmp(cx_strcast(t3), cx_str("123456")), 0);
232 cx_strfree_a(&alloc, &t3); 232 cx_strfree_a(&alloc, &t3);
233 233
234 cxmutstr t4 = cx_strcat_a(&alloc, 2, sn, sn); 234 cxmutstr t4 = cx_strcat_a(&alloc, 2, sn, sn);
235 EXPECT_EQ(cx_strcmp(cx_strcast(t4), CX_STR("")), 0); 235 EXPECT_EQ(cx_strcmp(cx_strcast(t4), cx_str("")), 0);
236 cx_strfree_a(&alloc, &t4); 236 cx_strfree_a(&alloc, &t4);
237 237
238 EXPECT_TRUE(alloc.verify()); 238 EXPECT_TRUE(alloc.verify());
239 } 239 }
240 240

mercurial