mirror of
https://codeberg.org/vyn/rei-json.git
synced 2025-07-02 01:43:19 +00:00
Add 'remove' methods to Object and Array + unify 'set' methods
This commit is contained in:
parent
eb5191a722
commit
fd034eff71
8 changed files with 109 additions and 26 deletions
|
@ -26,26 +26,68 @@ TEST_CASE("Basic json") {
|
|||
array.push(false);
|
||||
array.pushNull();
|
||||
|
||||
objectJson.addObject("keyObject", std::move(obj));
|
||||
objectJson.addArray("keyArray", std::move(array));
|
||||
objectJson.set("keyObject", std::move(obj));
|
||||
objectJson.set("keyArray", std::move(array));
|
||||
|
||||
REQUIRE(objectJson.getNumber("keyPositiveNumber") == 12);
|
||||
REQUIRE(objectJson["keyPositiveNumber"].asNumber() == 12);
|
||||
|
||||
REQUIRE(objectJson.getNumber("keyNegativeNumber") == -13);
|
||||
REQUIRE(objectJson["keyNegativeNumber"].asNumber() == -13);
|
||||
|
||||
REQUIRE(objectJson.getBool("keyBooleanTrue") == true);
|
||||
REQUIRE(objectJson["keyBooleanTrue"].asBool() == true);
|
||||
|
||||
REQUIRE(objectJson.getBool("keyBooleanFalse") == false);
|
||||
REQUIRE(objectJson["keyBooleanFalse"].asBool() == false);
|
||||
|
||||
REQUIRE(objectJson.getString("keyString") == "YEP");
|
||||
REQUIRE(objectJson["keyString"].asString() == "YEP");
|
||||
|
||||
REQUIRE(objectJson.getString("keyEmptyString") == "");
|
||||
REQUIRE(objectJson["keyEmptyString"].asString() == "");
|
||||
|
||||
REQUIRE(objectJson.getObject("keyObject").getNumber("keyNumberOnObject") == 42);
|
||||
REQUIRE(objectJson["keyObject"].asObject()["keyNumberOnObject"].asNumber() == 42);
|
||||
|
||||
REQUIRE(objectJson.hasNull("keyNull") == true);
|
||||
REQUIRE(objectJson["keyNull"].isNull() == true);
|
||||
|
||||
REQUIRE(objectJson.hasNull("keyPositiveNumber") == false);
|
||||
REQUIRE(objectJson["keyPositiveNumber"].isNull() == false);
|
||||
|
||||
REQUIRE_THROWS(objectJson.getNumber("nonExistantKey"));
|
||||
REQUIRE_THROWS(objectJson["nonExistantKey"]);
|
||||
|
||||
auto& arrayJson = objectJson.getArray("keyArray");
|
||||
|
||||
|
||||
REQUIRE(arrayJson.getNumber(0) == 42);
|
||||
REQUIRE(arrayJson[0].asNumber() == 42);
|
||||
|
||||
REQUIRE(arrayJson.getString(1) == "elemString");
|
||||
REQUIRE(arrayJson[1].asString() == "elemString");
|
||||
|
||||
REQUIRE(arrayJson.getString(2) == "");
|
||||
REQUIRE(arrayJson[2].asString() == "");
|
||||
|
||||
REQUIRE(arrayJson.getBool(3) == true);
|
||||
REQUIRE(arrayJson[3].asBool() == true);
|
||||
|
||||
REQUIRE(arrayJson.getBool(4) == false);
|
||||
REQUIRE(arrayJson[4].asBool() == false);
|
||||
|
||||
REQUIRE(arrayJson.hasNull(5));
|
||||
REQUIRE(arrayJson[5].isNull() == true);
|
||||
|
||||
REQUIRE_THROWS(arrayJson.getNumber(99));
|
||||
REQUIRE_THROWS(arrayJson[99].asNumber());
|
||||
|
||||
objectJson.remove("keyString");
|
||||
REQUIRE_THROWS(objectJson.getString("keyString") == "YEP");
|
||||
|
||||
arrayJson.remove(0);
|
||||
REQUIRE(arrayJson[0].isNumber() == false);
|
||||
REQUIRE(arrayJson[0].isString() == true);
|
||||
REQUIRE(arrayJson[0].asString() == "elemString");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue