add.cpp 588 B

12345678910111213141516171819202122232425262728293031
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <stdint.h>
  6. #include <catch.hpp>
  7. TEST_CASE("JsonVariant::add()") {
  8. DynamicJsonDocument doc(4096);
  9. JsonVariant var = doc.to<JsonVariant>();
  10. SECTION("integer") {
  11. var.add(42);
  12. REQUIRE(var.as<std::string>() == "[42]");
  13. }
  14. SECTION("const char*") {
  15. var.add("hello");
  16. REQUIRE(var.as<std::string>() == "[\"hello\"]");
  17. }
  18. SECTION("std::string") {
  19. var.add(std::string("hello"));
  20. REQUIRE(var.as<std::string>() == "[\"hello\"]");
  21. }
  22. }