MCPcopy Create free account
hub / github.com/crownengine/crown / test_dynamic_string

Function test_dynamic_string

src/core/unit_tests.cpp:1160–1268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1158}
1159
1160static void test_dynamic_string()
1161{
1162 memory_globals::init();
1163 {
1164 TempAllocator1024 ta;
1165 DynamicString str(ta);
1166 ENSURE(str.empty());
1167
1168 str.set("murmur32", 8);
1169 ENSURE(str.length() == 8);
1170
1171 const StringId32 id = str.to_string_id();
1172 ENSURE(id._id == 0x68bd9babu);
1173 }
1174 {
1175 TempAllocator1024 ta;
1176 DynamicString str(ta);
1177 str += "Test ";
1178 str += "string.";
1179 ENSURE(strcmp(str.c_str(), "Test string.") == 0);
1180 }
1181 {
1182 TempAllocator1024 ta;
1183 DynamicString str(ta);
1184 str.set(" \tSushi\t ", 13);
1185 str.ltrim();
1186 ENSURE(strcmp(str.c_str(), "Sushi\t ") == 0);
1187 }
1188 {
1189 TempAllocator1024 ta;
1190 DynamicString str(ta);
1191 str.set(" \tSushi\t ", 13);
1192 str.rtrim();
1193 ENSURE(strcmp(str.c_str(), " \tSushi") == 0);
1194 }
1195 {
1196 TempAllocator1024 ta;
1197 DynamicString str(ta);
1198 str.set(" \tSushi\t ", 13);
1199 str.trim();
1200 ENSURE(strcmp(str.c_str(), "Sushi") == 0);
1201 }
1202 {
1203 TempAllocator1024 ta;
1204 DynamicString str(ta);
1205 str.set("Hello everyone!", 15);
1206
1207 ENSURE(str.has_prefix("Hello"));
1208 ENSURE(!str.has_prefix("Helloo"));
1209
1210 ENSURE(str.has_suffix("one!"));
1211 ENSURE(!str.has_suffix("one"));
1212
1213 ENSURE(!str.has_prefix("Hello everyone!!!"));
1214 ENSURE(!str.has_suffix("Hello everyone!!!"));
1215 }
1216 {
1217 Guid guid = guid::parse("dd733419-bbd0-4248-bc84-e0e8363d7165");

Callers

nothing calls this directly

Calls 13

strcmpFunction · 0.85
trimMethod · 0.80
from_guidMethod · 0.80
from_string_idMethod · 0.80
initFunction · 0.70
parseFunction · 0.70
StringId32Class · 0.70
StringId64Class · 0.70
shutdownFunction · 0.70
emptyMethod · 0.45
setMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected