mirror of
https://codeberg.org/vyn/rei-json.git
synced 2025-07-02 01:43:19 +00:00
first commit
This commit is contained in:
commit
eb5191a722
15 changed files with 1075 additions and 0 deletions
54
tests/stringify.cpp
Normal file
54
tests/stringify.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "rei-json/json.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Stringify json") {
|
||||
auto objectJson = rei::json::JsonObject{};
|
||||
objectJson
|
||||
.set("keyPositiveNumber", 12)
|
||||
.set("keyNegativeNumber", -13)
|
||||
.set("keyBooleanTrue", true)
|
||||
.set("keyBooleanFalse", false)
|
||||
.set("keyString", "YEP")
|
||||
.set("keyEmptyString", "")
|
||||
.setNull("keyNull");
|
||||
|
||||
rei::json::JsonObject obj{};
|
||||
obj.set("keyNumberOnObject", 42);
|
||||
|
||||
rei::json::JsonArray array{};
|
||||
array.push(42);
|
||||
array.push("elemString");
|
||||
array.push("");
|
||||
array.push(true);
|
||||
array.push(false);
|
||||
array.pushNull();
|
||||
|
||||
objectJson.addObject("keyObject", std::move(obj));
|
||||
objectJson.addArray("keyArray", std::move(array));
|
||||
|
||||
std::string expectedJson = R"({
|
||||
"keyArray": [
|
||||
42,
|
||||
"elemString",
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
null
|
||||
],
|
||||
"keyBooleanFalse": false,
|
||||
"keyBooleanTrue": true,
|
||||
"keyEmptyString": "",
|
||||
"keyNegativeNumber": -13,
|
||||
"keyNull": null,
|
||||
"keyObject": {
|
||||
"keyNumberOnObject": 42
|
||||
},
|
||||
"keyPositiveNumber": 12,
|
||||
"keyString": "YEP"
|
||||
})";
|
||||
|
||||
REQUIRE(rei::json::toString(objectJson) == expectedJson);
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue