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

Function test_sjson

src/core/unit_tests.cpp:1399–1627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1397}
1398
1399static void test_sjson()
1400{
1401 memory_globals::init();
1402 {
1403 JsonValueType::Enum t = sjson::type("null");
1404 ENSURE(t == JsonValueType::NIL);
1405 }
1406 {
1407 JsonValueType::Enum t = sjson::type("true");
1408 ENSURE(t == JsonValueType::BOOL);
1409 }
1410 {
1411 JsonValueType::Enum t = sjson::type("false");
1412 ENSURE(t == JsonValueType::BOOL);
1413 }
1414 {
1415 JsonValueType::Enum t = sjson::type("3.14");
1416 ENSURE(t == JsonValueType::NUMBER);
1417 }
1418 {
1419 JsonValueType::Enum t = sjson::type("\"foo\"");
1420 ENSURE(t == JsonValueType::STRING);
1421 }
1422 {
1423 JsonValueType::Enum t = sjson::type("[]");
1424 ENSURE(t == JsonValueType::ARRAY);
1425 }
1426 {
1427 JsonValueType::Enum t = sjson::type("{}");
1428 ENSURE(t == JsonValueType::OBJECT);
1429 }
1430 {
1431 const s32 a = sjson::parse_int("3.14");
1432 ENSURE(a == 3);
1433 }
1434 {
1435 const f32 a = sjson::parse_float("3.14");
1436 ENSURE(fequal(a, 3.14f));
1437 }
1438 {
1439 const bool a = sjson::parse_bool("true");
1440 ENSURE(a == true);
1441 }
1442 {
1443 const bool a = sjson::parse_bool("false");
1444 ENSURE(a == false);
1445 }
1446 {
1447 TempAllocator1024 ta;
1448 DynamicString str(ta);
1449 sjson::parse_string(str, "\"This is JSON\"");
1450 ENSURE(strcmp(str.c_str(), "This is JSON") == 0);
1451 }
1452 {
1453 const Vector2 a = sjson::parse_vector2("[ 1.2 -2.5 ]");
1454 ENSURE(fequal(a.x, 1.2f));
1455 ENSURE(fequal(a.y, -2.5f));
1456 }

Callers

nothing calls this directly

Calls 15

strcmpFunction · 0.85
parse_vector2Function · 0.85
parse_vector3Function · 0.85
parse_vector4Function · 0.85
parse_quaternionFunction · 0.85
parse_matrix4x4Function · 0.85
parse_string_idFunction · 0.85
parse_resource_nameFunction · 0.85
parse_guidFunction · 0.85
parse_verbatimFunction · 0.85
set_error_callbackFunction · 0.85
initFunction · 0.70

Tested by

no test coverage detected