std_string.cpp 691 B

12345678910111213141516171819202122232425262728293031323334
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include "Literals.hpp"
  7. static void eraseString(std::string& str) {
  8. char* p = const_cast<char*>(str.c_str());
  9. while (*p)
  10. *p++ = '*';
  11. }
  12. TEST_CASE("std::string") {
  13. JsonDocument doc;
  14. JsonArray array = doc.to<JsonArray>();
  15. SECTION("add()") {
  16. std::string value("hello");
  17. array.add(value);
  18. eraseString(value);
  19. REQUIRE("hello"_s == array[0]);
  20. }
  21. SECTION("operator[]") {
  22. std::string value("world");
  23. array.add("hello");
  24. array[0] = value;
  25. eraseString(value);
  26. REQUIRE("world"_s == array[0]);
  27. }
  28. }