FFstrbuf: fix bugs in ffStrbufAppendS; add more tests

This commit is contained in:
李通洲
2022-09-20 21:50:50 +08:00
parent 254c4e5f50
commit 6eed53217d
2 changed files with 60 additions and 27 deletions
+52 -6
View File
@@ -26,24 +26,58 @@ int main(int argc, char** argv)
//initA
ffStrbufInitA(&strbuf, 64);
ffStrbufInitA(&strbuf, 0);
if(strbuf.allocated != 64)
testFailed(&strbuf, "strbuf.allocated != 64");
if(strbuf.chars[0] != 0) //make sure chars[0] is accessable
testFailed(&strbuf, "strbuf.chars[0] != 0");
if(strbuf.allocated != 0)
testFailed(&strbuf, "strbuf.allocated != 0");
if(strbuf.length != 0)
testFailed(&strbuf, "testSrbuf.length != 0");
testFailed(&strbuf, "strbuf.length != 0");
//appendS
ffStrbufAppendS(&strbuf, "123456789");
ffStrbufAppendS(&strbuf, "12345");
if(strbuf.length != 5)
testFailed(&strbuf, "strbuf.length != 5");
if(strbuf.allocated < 6)
testFailed(&strbuf, "strbuf.allocated < 6");
if(ffStrbufCompS(&strbuf, "12345") != 0)
testFailed(&strbuf, "strbuf.data != \"12345\"");
//appendNS
ffStrbufAppendNS(&strbuf, 4, "67890");
if(strbuf.length != 9)
testFailed(&strbuf, "strbuf.length != 9");
if(strcmp(strbuf.chars, "123456789") != 0)
if(strbuf.allocated < 10)
testFailed(&strbuf, "strbuf.allocated < 10");
if(ffStrbufCompS(&strbuf, "123456789") != 0)
testFailed(&strbuf, "strbuf.data != \"123456789\"");
//appendS long
ffStrbufAppendS(&strbuf, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
if(strbuf.length != 109)
testFailed(&strbuf, "strbuf.length != 109");
if(strbuf.allocated < 110)
testFailed(&strbuf, "strbuf.allocated < 110");
if(strbuf.chars[strbuf.length] != 0)
testFailed(&strbuf, "strbuf.chars[strbuf.length] != 0");
strbuf.length = 9;
//startsWithS
if(!ffStrbufStartsWithS(&strbuf, "123"))
@@ -79,6 +113,18 @@ int main(int argc, char** argv)
if(strcmp(strbuf.chars, "12316") != 0)
testFailed(&strbuf, "strbuf.chars != \"12316\"");
//Destroy
ffStrbufDestroy(&strbuf);
if(strbuf.allocated != 0)
testFailed(&strbuf, "strbuf.allocated != 0");
if(strbuf.length != 0)
testFailed(&strbuf, "strbuf.length != 0");
if(strbuf.chars != NULL)
testFailed(&strbuf, "strbuf.chars != NULL");
//Success
puts("\033[32mAll tests passed!"FASTFETCH_TEXT_MODIFIER_RESET);
}