forked from bblanchon/ArduinoJson
This commit is contained in:
@ -76,17 +76,10 @@ TEST_CASE("JsonObject::printTo()") {
|
||||
check(obj, "{\"a\":[1,2],\"b\":[4,5]}");
|
||||
}
|
||||
|
||||
SECTION("TwoDoublesFourDigits") {
|
||||
obj["a"] = double_with_n_digits(3.14159265358979323846, 4);
|
||||
obj.set("b", 2.71828182845904523536, 4);
|
||||
obj.set("c", double_with_n_digits(3.14159265358979323846, 3));
|
||||
check(obj, "{\"a\":3.1416,\"b\":2.7183,\"c\":3.142}");
|
||||
}
|
||||
|
||||
SECTION("TwoDoubleDefaultDigits") {
|
||||
obj["a"] = 3.14159265358979323846;
|
||||
obj.set("b", 2.71828182845904523536);
|
||||
check(obj, "{\"a\":3.14,\"b\":2.72}");
|
||||
SECTION("Two doubles") {
|
||||
obj["a"] = 12.34;
|
||||
obj.set("b", 56.78);
|
||||
check(obj, "{\"a\":12.34,\"b\":56.78}");
|
||||
}
|
||||
|
||||
SECTION("TwoNull") {
|
||||
|
@ -24,31 +24,23 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE(1 == _object.size());
|
||||
}
|
||||
|
||||
SECTION("StoreInteger") {
|
||||
SECTION("int") {
|
||||
_object.set("hello", 123);
|
||||
|
||||
REQUIRE(123 == _object["hello"].as<int>());
|
||||
REQUIRE(_object["hello"].is<int>());
|
||||
REQUIRE_FALSE(_object["hello"].is<double>());
|
||||
REQUIRE_FALSE(_object["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("StoreDouble") {
|
||||
SECTION("double") {
|
||||
_object.set("hello", 123.45);
|
||||
|
||||
REQUIRE(123.45 == _object["hello"].as<double>());
|
||||
REQUIRE(_object["hello"].is<double>());
|
||||
REQUIRE_FALSE(_object["hello"].is<long>());
|
||||
REQUIRE_FALSE(_object["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("StoreDoubleWithDigits") {
|
||||
_object.set("hello", 123.45, 2);
|
||||
|
||||
REQUIRE(123.45 == _object["hello"].as<double>());
|
||||
REQUIRE(_object["hello"].is<double>());
|
||||
REQUIRE_FALSE(_object["hello"].is<long>());
|
||||
}
|
||||
|
||||
SECTION("StoreBoolean") {
|
||||
SECTION("bool") {
|
||||
_object.set("hello", true);
|
||||
|
||||
REQUIRE(_object["hello"].as<bool>());
|
||||
@ -56,7 +48,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE_FALSE(_object["hello"].is<long>());
|
||||
}
|
||||
|
||||
SECTION("StoreString") {
|
||||
SECTION("const char*") {
|
||||
_object.set("hello", "h3110");
|
||||
|
||||
REQUIRE(std::string("h3110") == _object["hello"].as<const char*>());
|
||||
@ -64,7 +56,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE_FALSE(_object["hello"].is<long>());
|
||||
}
|
||||
|
||||
SECTION("StoreArray") {
|
||||
SECTION("nested array") {
|
||||
JsonArray& arr = jb.createArray();
|
||||
|
||||
_object.set("hello", arr);
|
||||
@ -74,7 +66,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE_FALSE(_object["hello"].is<JsonObject&>());
|
||||
}
|
||||
|
||||
SECTION("StoreObject") {
|
||||
SECTION("nested object") {
|
||||
JsonObject& obj = jb.createObject();
|
||||
|
||||
_object.set("hello", obj);
|
||||
@ -84,7 +76,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE_FALSE(_object["hello"].is<JsonArray&>());
|
||||
}
|
||||
|
||||
SECTION("StoreArraySubscript") {
|
||||
SECTION("array subscript") {
|
||||
JsonArray& arr = jb.createArray();
|
||||
arr.add(42);
|
||||
|
||||
@ -93,7 +85,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
REQUIRE(42 == _object["a"]);
|
||||
}
|
||||
|
||||
SECTION("StoreObjectSubscript") {
|
||||
SECTION("object subscript") {
|
||||
JsonObject& obj = jb.createObject();
|
||||
obj.set("x", 42);
|
||||
|
||||
|
@ -23,24 +23,24 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(1 == _object.size());
|
||||
}
|
||||
|
||||
SECTION("StoreInteger") {
|
||||
SECTION("int") {
|
||||
_object["hello"] = 123;
|
||||
|
||||
REQUIRE(123 == _object["hello"].as<int>());
|
||||
REQUIRE(true == _object["hello"].is<int>());
|
||||
REQUIRE(false == _object["hello"].is<double>());
|
||||
REQUIRE(false == _object["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("StoreVolatileInteger") { // issue #415
|
||||
SECTION("volatile int") { // issue #415
|
||||
volatile int i = 123;
|
||||
_object["hello"] = i;
|
||||
|
||||
REQUIRE(123 == _object["hello"].as<int>());
|
||||
REQUIRE(true == _object["hello"].is<int>());
|
||||
REQUIRE(false == _object["hello"].is<double>());
|
||||
REQUIRE(false == _object["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("StoreDouble") {
|
||||
SECTION("double") {
|
||||
_object["hello"] = 123.45;
|
||||
|
||||
REQUIRE(true == _object["hello"].is<double>());
|
||||
@ -48,15 +48,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(123.45 == _object["hello"].as<double>());
|
||||
}
|
||||
|
||||
SECTION("StoreDoubleWithDigits") {
|
||||
_object["hello"].set(123.45, 2);
|
||||
|
||||
REQUIRE(true == _object["hello"].is<double>());
|
||||
REQUIRE(false == _object["hello"].is<long>());
|
||||
REQUIRE(123.45 == _object["hello"].as<double>());
|
||||
}
|
||||
|
||||
SECTION("StoreBoolean") {
|
||||
SECTION("bool") {
|
||||
_object["hello"] = true;
|
||||
|
||||
REQUIRE(true == _object["hello"].is<bool>());
|
||||
@ -64,7 +56,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(true == _object["hello"].as<bool>());
|
||||
}
|
||||
|
||||
SECTION("StoreString") {
|
||||
SECTION("const char*") {
|
||||
_object["hello"] = "h3110";
|
||||
|
||||
REQUIRE(true == _object["hello"].is<const char*>());
|
||||
@ -74,7 +66,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
_object["hello"].as<char*>()); // <- short hand
|
||||
}
|
||||
|
||||
SECTION("StoreArray") {
|
||||
SECTION("array") {
|
||||
JsonArray& arr = _jsonBuffer.createArray();
|
||||
|
||||
_object["hello"] = arr;
|
||||
@ -90,7 +82,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(false == _object["hello"].is<JsonObject&>());
|
||||
}
|
||||
|
||||
SECTION("StoreObject") {
|
||||
SECTION("object") {
|
||||
JsonObject& obj = _jsonBuffer.createObject();
|
||||
|
||||
_object["hello"] = obj;
|
||||
@ -106,7 +98,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(false == _object["hello"].is<JsonArray&>());
|
||||
}
|
||||
|
||||
SECTION("StoreArraySubscript") {
|
||||
SECTION("array subscript") {
|
||||
JsonArray& arr = _jsonBuffer.createArray();
|
||||
arr.add(42);
|
||||
|
||||
@ -115,7 +107,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
REQUIRE(42 == _object["a"]);
|
||||
}
|
||||
|
||||
SECTION("StoreObjectSubscript") {
|
||||
SECTION("object subscript") {
|
||||
JsonObject& obj = _jsonBuffer.createObject();
|
||||
obj.set("x", 42);
|
||||
|
||||
|
Reference in New Issue
Block a user