MCPcopy Index your code
hub / github.com/antirez/botlib / sdsTest

Function sdsTest

sds.c:1132–1293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1130
1131#define UNUSED(x) (void)(x)
1132int sdsTest(void) {
1133 {
1134 sds x = sdsnew("foo"), y;
1135
1136 test_cond("Create a string and obtain the length",
1137 sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0)
1138
1139 sdsfree(x);
1140 x = sdsnewlen("foo",2);
1141 test_cond("Create a string with specified length",
1142 sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0)
1143
1144 x = sdscat(x,"bar");
1145 test_cond("Strings concatenation",
1146 sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0);
1147
1148 x = sdscpy(x,"a");
1149 test_cond("sdscpy() against an originally longer string",
1150 sdslen(x) == 1 && memcmp(x,"a\0",2) == 0)
1151
1152 x = sdscpy(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk");
1153 test_cond("sdscpy() against an originally shorter string",
1154 sdslen(x) == 33 &&
1155 memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0)
1156
1157 sdsfree(x);
1158 x = sdscatprintf(sdsempty(),"%d",123);
1159 test_cond("sdscatprintf() seems working in the base case",
1160 sdslen(x) == 3 && memcmp(x,"123\0",4) == 0)
1161
1162 sdsfree(x);
1163 x = sdsnew("--");
1164 x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN,LLONG_MAX);
1165 test_cond("sdscatfmt() seems working in the base case",
1166 sdslen(x) == 60 &&
1167 memcmp(x,"--Hello Hi! World -9223372036854775808,"
1168 "9223372036854775807--",60) == 0)
1169 printf("[%s]\n",x);
1170
1171 sdsfree(x);
1172 x = sdsnew("--");
1173 x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX);
1174 test_cond("sdscatfmt() seems working with unsigned numbers",
1175 sdslen(x) == 35 &&
1176 memcmp(x,"--4294967295,18446744073709551615--",35) == 0)
1177
1178 sdsfree(x);
1179 x = sdsnew(" x ");
1180 sdstrim(x," x");
1181 test_cond("sdstrim() works when all chars match",
1182 sdslen(x) == 0)
1183
1184 sdsfree(x);
1185 x = sdsnew(" x ");
1186 sdstrim(x," ");
1187 test_cond("sdstrim() works when a single char remains",
1188 sdslen(x) == 1 && x[0] == 'x')
1189

Callers 1

mainFunction · 0.85

Calls 15

sdsnewFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
sdsnewlenFunction · 0.85
sdscatFunction · 0.85
sdscpyFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85
sdscatfmtFunction · 0.85
sdstrimFunction · 0.85
sdsdupFunction · 0.85
sdsrangeFunction · 0.85

Tested by

no test coverage detected