add test coverage for _m variant functions

Tue, 20 Sep 2022 10:24:03 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 20 Sep 2022 10:24:03 +0200
changeset 585
038f5e99e00f
parent 584
184e9ebfc3cc
child 586
aa51aaa907b9

add test coverage for _m variant functions

test/test_string.cpp file | annotate | diff | comparison | revisions
--- a/test/test_string.cpp	Tue Sep 13 20:11:26 2022 +0200
+++ b/test/test_string.cpp	Tue Sep 20 10:24:03 2022 +0200
@@ -71,6 +71,34 @@
     EXPECT_EQ(len3, 10);
 }
 
+TEST(String, strsubs) {
+    cxstring str = CX_STR("A test string");
+
+    cxstring sub = cx_strsubs(str, 0);
+    EXPECT_EQ(cx_strcmp(sub, str), 0);
+
+    sub = cx_strsubs(str, 2);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("test string")), 0);
+
+    sub = cx_strsubs(str, 7);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("string")), 0);
+
+    sub = cx_strsubs(str, 15);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("")), 0);
+
+    sub = cx_strsubsl(str, 2, 4);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("test")), 0);
+
+    sub = cx_strsubsl(str, 7, 3);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("str")), 0);
+
+    sub = cx_strsubsl(str, 7, 20);
+    EXPECT_EQ(cx_strcmp(sub, cx_str("string")), 0);
+
+    // just for coverage, call the _m variant
+    auto m = cx_strsubs_m(cx_mutstrn(nullptr, 0), 0);
+    EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
+}
 
 TEST(String, strchr) {
     cxstring str = CX_STR("I will find you - and I will kill you");
@@ -81,6 +109,10 @@
     cxstring result = cx_strchr(str, 'w');
     EXPECT_EQ(result.length, 35);
     EXPECT_EQ(strcmp("will find you - and I will kill you", result.ptr), 0);
+
+    // just for coverage, call the _m variant
+    auto m = cx_strchr_m(cx_mutstrn(nullptr, 0), 'a');
+    EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
 }
 
 TEST(String, strrchr) {
@@ -92,6 +124,10 @@
     cxstring result = cx_strrchr(str, 'w');
     EXPECT_EQ(result.length, 13);
     EXPECT_EQ(strcmp("will kill you", result.ptr), 0);
+
+    // just for coverage, call the _m variant
+    auto m = cx_strrchr_m(cx_mutstrn(nullptr, 0), 'a');
+    EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
 }
 
 TEST(String, strstr) {
@@ -139,6 +175,13 @@
     result = cx_strstr(longstr, longstrpattern);
     EXPECT_EQ(result.length, longstrresult.length);
     EXPECT_EQ(strcmp(result.ptr, longstrresult.ptr), 0);
+
+    // just for coverage, call the _m variant
+    auto mstr = cx_strdup(longstr);
+    auto m = cx_strstr_m(mstr, longstrpattern);
+    EXPECT_EQ(m.length, longstrresult.length);
+    EXPECT_EQ(strcmp(m.ptr, longstrresult.ptr), 0);
+    cx_strfree(&mstr);
 }
 
 TEST(String, strcmp) {
@@ -283,6 +326,16 @@
     EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
     EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
     EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
+
+    /* call the _m variant just for coverage */
+    auto mtest = cx_strdup(test);
+    cxmutstr mlist[4];
+    n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist);
+    ASSERT_EQ(n, 3);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), cx_str("th")), 0);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), cx_str("")), 0);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string")), 0);
+    cx_strfree(&mtest);
 }
 
 TEST(String, strsplit_a) {
@@ -387,6 +440,17 @@
     EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
     cxFree(&alloc, list);
 
+    /* call the _m variant just for coverage */
+    auto mtest = cx_strdup(test);
+    cxmutstr *mlist;
+    n = cx_strsplit_ma(&alloc, mtest, cx_str("is,"), 4, &mlist);
+    ASSERT_EQ(n, 3);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), cx_str("th")), 0);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), cx_str("")), 0);
+    EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string")), 0);
+    cxFree(&alloc, mlist);
+    cx_strfree(&mtest);
+
     EXPECT_TRUE(alloc.verify());
 }
 
@@ -404,6 +468,10 @@
     EXPECT_EQ(cx_strcmp(t4, cx_str("xyz")), 0);
     EXPECT_EQ(cx_strcmp(t5, cx_str("")), 0);
     EXPECT_EQ(cx_strcmp(empty, cx_str("")), 0);
+
+    /* call the _m variant just for coverage */
+    cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) "  ein test  \t "));
+    EXPECT_EQ(cx_strcmp(cx_strcast(m1), cx_str("ein test")), 0);
 }
 
 TEST(String, strprefix) {

mercurial