// ArduinoJson - https://arduinojson.org // Copyright © 2014-2022, Benoit BLANCHON // MIT License #include #include #include TEST_CASE("JsonVariant::add()") { DynamicJsonDocument doc(4096); JsonVariant var = doc.to(); SECTION("add integer to new variant") { var.add(42); REQUIRE(var.as() == "[42]"); } SECTION("add const char* to new variant") { var.add("hello"); REQUIRE(var.as() == "[\"hello\"]"); } SECTION("add std::string to new variant") { var.add(std::string("hello")); REQUIRE(var.as() == "[\"hello\"]"); } SECTION("add integer to integer") { var.set(123); var.add(456); // no-op REQUIRE(var.as() == "123"); } SECTION("add integer to object") { var["val"] = 123; var.add(456); // no-op REQUIRE(var.as() == "{\"val\":123}"); } }