mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 08:48:30 +01:00
JsonVariant::as
This commit is contained in:
@@ -267,4 +267,60 @@ TEST_CASE("JsonVariant::as()") {
|
||||
|
||||
REQUIRE(variant.as<MY_ENUM>() == ONE);
|
||||
}
|
||||
|
||||
SECTION("linked object") {
|
||||
StaticJsonDocument<128> doc2;
|
||||
doc2["hello"] = "world";
|
||||
variant.link(doc2);
|
||||
|
||||
SECTION("as<std::string>()") {
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("as<JsonArray>()") {
|
||||
JsonArray a = variant.as<JsonArray>();
|
||||
CHECK(a.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("as<JsonObject>()") {
|
||||
JsonObject o = variant.as<JsonObject>();
|
||||
CHECK(o.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("as<JsonObjectConst>()") {
|
||||
JsonObjectConst o = variant.as<JsonObjectConst>();
|
||||
CHECK(o.isNull() == false);
|
||||
CHECK(o.size() == 1);
|
||||
CHECK(o["hello"] == "world");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("linked array") {
|
||||
StaticJsonDocument<128> doc2;
|
||||
doc2.add("hello");
|
||||
doc2.add("world");
|
||||
variant.link(doc2);
|
||||
|
||||
SECTION("as<std::string>()") {
|
||||
CHECK(variant.as<std::string>() == "[\"hello\",\"world\"]");
|
||||
}
|
||||
|
||||
SECTION("as<JsonArray>()") {
|
||||
JsonArray a = variant.as<JsonArray>();
|
||||
CHECK(a.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("as<JsonArrayConst>()") {
|
||||
JsonArrayConst a = variant.as<JsonArrayConst>();
|
||||
CHECK(a.isNull() == false);
|
||||
CHECK(a.size() == 2);
|
||||
CHECK(a[0] == "hello");
|
||||
CHECK(a[1] == "world");
|
||||
}
|
||||
|
||||
SECTION("as<JsonObject>()") {
|
||||
JsonObject o = variant.as<JsonObject>();
|
||||
CHECK(o.isNull() == true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user