go back to string

This commit is contained in:
2022-04-16 23:51:05 +03:00
parent d611287c1a
commit e1addc4004
10 changed files with 242 additions and 73 deletions

View File

@@ -13,7 +13,7 @@ void test_all(){
int main(){
setlocale(LC_ALL, "en-US.Unicode");
printf("\e[92mdtsod parser in c language!\e[97m\n");
optime("test_all",1,test_all());
optime("test_all",1,{test_all();});
printf("\e[0m\n");
return 0;
}

View File

@@ -1,26 +1,16 @@
#include "tests.h"
#include "../StringFragment/StringFragment.h"
#include "../base/mystr.h"
void test_string(){
optime(__func__,1,({
printf("\e[96m-------------[test_string]-------------\n");
char c[]="0123456789abcdef";
StringFragment s={.ptr=cptr_copy(c),.offset=0,.length=cptr_length(c)};
printf("\e[92m\"%s\" \e[94m-> StringFragment\n",c);
if(s.length!=16) throw("StringFragment created with incorrect length");
StringFragment extr=StringFragment_extract(s);
printf("\e[94mStringFragment_extract() -> \e[92m\"%s\"\n",extr.ptr);
if(extr.length!=16) throw("StringFragment extracted with incorrect length");
free(extr.ptr);
s.offset+=2; s.length-=4;
printf("\e[94mStringFragment offset+=2 length-=4\n");
extr=StringFragment_extract(s);
printf("\e[94mStringFragment_extract() -> \e[92m\"%s\"\n",extr.ptr);
if(extr.length!=12) throw("StringFragment extracted with incorrect length");
string s=string_cpFromCharPtr(c);
printf("\e[92m\"%s\" \e[94m-> string_cpFromCharPtr()\n",c);
if(s.length!=16) throw("string created with incorrect length");
char* p=string_cpToCptr(s);
printf("\e[94mstring_cpToCptr() -> \e[92m\"%s\"\n",p);
free(p);
free(s.ptr);
free(extr.ptr);
}));
}