subscript.cpp 769 B

123456789101112131415161718192021222324252627282930313233
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include "Allocators.hpp"
  7. TEST_CASE("JsonObjectConst::operator[]") {
  8. JsonDocument doc;
  9. doc["hello"] = "world";
  10. JsonObjectConst obj = doc.as<JsonObjectConst>();
  11. SECTION("supports const char*") {
  12. REQUIRE(obj["hello"] == "world"); // issue #2019
  13. }
  14. SECTION("supports std::string") {
  15. REQUIRE(obj[std::string("hello")] == "world"); // issue #2019
  16. }
  17. #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
  18. !defined(SUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR)
  19. SECTION("supports VLA") {
  20. size_t i = 16;
  21. char vla[i];
  22. strcpy(vla, "hello");
  23. REQUIRE(std::string("world") == obj[vla]);
  24. }
  25. #endif
  26. }