adds more sstrreplace tests

Sun, 29 Dec 2019 16:04:34 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Dec 2019 16:04:34 +0100
changeset 382
d746888af4e5
parent 381
f5421bb2c8d1
child 383
db4c6b94939b

adds more sstrreplace tests

test/string_tests.c file | annotate | diff | comparison | revisions
--- a/test/string_tests.c	Sun Dec 29 13:39:36 2019 +0100
+++ b/test/string_tests.c	Sun Dec 29 16:04:34 2019 +0100
@@ -482,6 +482,9 @@
     sstr_t str = ST("test ababab string aba");
     sstr_t longstr = ST("xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd");
     sstr_t notrail = ST("test abab");
+    sstr_t empty = ST("");
+    sstr_t astr = ST("aaaaaaaaaa");
+    sstr_t csstr = ST("test AB ab TEST xyz");
 
     sstr_t repl = sstrreplace(str, SC("abab"), SC("muchlonger"));
     sstr_t expected = ST("test muchlongerab string aba");
@@ -494,7 +497,35 @@
 
     sstr_t replnotrail = sstrreplace(notrail, SC("ab"), SC("z"));
     sstr_t notrailexpect = ST("test zz");
-
+    
+    sstr_t repleq = sstrreplace(str, str, SC("hello"));
+    sstr_t eqexpect = ST("hello");
+    
+    sstr_t replempty1 = sstrreplace(empty, SC("ab"), SC("c")); // expect: empty
+    sstr_t replempty2 = sstrreplace(str, SC("abab"), empty);
+    sstr_t emptyexpect2 = ST("test ab string aba");
+    
+    sstr_t replpre = sstrreplace(str, SC("test "), SC("TEST "));
+    sstr_t preexpected = ST("TEST ababab string aba");
+    
+    sstr_t replan1 = sstrreplacen(astr, SC("a"), SC("x"), 1);
+    sstr_t an1expected = ST("xaaaaaaaaa");
+    
+    sstr_t replan4 = sstrreplacen(astr, SC("a"), SC("x"), 4);
+    sstr_t an4expected = ST("xxxxaaaaaa");
+    
+    sstr_t replan9 = sstrreplacen(astr, SC("a"), SC("x"), 9);
+    sstr_t an9expected = ST("xxxxxxxxxa");
+    
+    sstr_t replan10 = sstrreplacen(astr, SC("a"), SC("x"), 10);
+    sstr_t an10expected = ST("xxxxxxxxxx");
+    
+    sstr_t replcs1 = sstrreplace(csstr, SC("AB"), SC("*"));
+    sstr_t cs1expected = ST("test * ab TEST xyz");
+    
+    sstr_t replcs2 = sstrreplace(csstr, SC("test"), SC("TEST"));
+    sstr_t cs2expected = ST("TEST AB ab TEST xyz");
+    
     UCX_TEST_BEGIN
 
     UCX_TEST_ASSERT(repl.ptr != str.ptr, "result string is not fresh");
@@ -508,9 +539,51 @@
 
     UCX_TEST_ASSERT(!sstrcmp(replnotrail, notrailexpect),
             "no trail replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(repleq, eqexpect),
+            "equal replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replempty1, empty),
+            "replacement in empty string fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replempty2, emptyexpect2),
+            "empty replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replpre, preexpected),
+            "prefix replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replan1, an1expected),
+            "a1 replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replan4, an4expected),
+            "a4 replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replan9, an9expected),
+            "a9 replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replan10, an10expected),
+            "a10 replacement fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replcs1, cs1expected),
+            "case sensitivity test1 fails");
+    
+    UCX_TEST_ASSERT(!sstrcmp(replcs2, cs2expected),
+            "case sensitivity test2 fails");
 
     UCX_TEST_END
 
     free(repl.ptr);
     free(repln.ptr);
-}
\ No newline at end of file
+    free(longrepl.ptr);
+    free(replnotrail.ptr);
+    free(repleq.ptr);
+    if(replempty1.ptr) free(replempty1.ptr);
+    free(replempty2.ptr);
+    free(replpre.ptr);
+    free(replan1.ptr);
+    free(replan4.ptr);
+    free(replan9.ptr);
+    free(replan10.ptr);
+    free(replcs1.ptr);
+    free(replcs2.ptr);
+}

mercurial