Browse Source

Tests: add user-defined literal `""_s` for `std::string`

Benoit Blanchon 1 năm trước cách đây
mục cha
commit
45611924f3
55 tập tin đã thay đổi với 316 bổ sung229 xóa
  1. 2 1
      extras/tests/Cpp17/string_view.cpp
  2. 5 3
      extras/tests/Deprecated/createNestedArray.cpp
  3. 5 3
      extras/tests/Deprecated/createNestedObject.cpp
  4. 12 0
      extras/tests/Helpers/Literals.hpp
  5. 6 5
      extras/tests/JsonArray/add.cpp
  6. 15 14
      extras/tests/JsonArray/copyArray.cpp
  7. 4 2
      extras/tests/JsonArray/std_string.cpp
  8. 4 3
      extras/tests/JsonArray/subscript.cpp
  9. 5 4
      extras/tests/JsonDeserializer/destination_types.cpp
  10. 4 3
      extras/tests/JsonDeserializer/filter.cpp
  11. 4 3
      extras/tests/JsonDeserializer/input_types.cpp
  12. 15 13
      extras/tests/JsonDeserializer/nestingLimit.cpp
  13. 3 1
      extras/tests/JsonDocument/ElementProxy.cpp
  14. 10 9
      extras/tests/JsonDocument/MemberProxy.cpp
  15. 4 3
      extras/tests/JsonDocument/add.cpp
  16. 2 1
      extras/tests/JsonDocument/assignment.cpp
  17. 2 1
      extras/tests/JsonDocument/clear.cpp
  18. 3 2
      extras/tests/JsonDocument/constructor.cpp
  19. 3 1
      extras/tests/JsonDocument/containsKey.cpp
  20. 6 4
      extras/tests/JsonDocument/issue1120.cpp
  21. 3 2
      extras/tests/JsonDocument/overflowed.cpp
  22. 3 1
      extras/tests/JsonDocument/remove.cpp
  23. 5 4
      extras/tests/JsonDocument/shrinkToFit.cpp
  24. 6 4
      extras/tests/JsonDocument/subscript.cpp
  25. 12 11
      extras/tests/JsonObject/set.cpp
  26. 8 6
      extras/tests/JsonObject/std_string.cpp
  27. 10 9
      extras/tests/JsonObject/subscript.cpp
  28. 4 2
      extras/tests/JsonObjectConst/containsKey.cpp
  29. 3 2
      extras/tests/JsonObjectConst/subscript.cpp
  30. 13 11
      extras/tests/JsonSerializer/JsonVariant.cpp
  31. 3 1
      extras/tests/JsonSerializer/std_string.cpp
  32. 3 2
      extras/tests/JsonVariant/add.cpp
  33. 11 9
      extras/tests/JsonVariant/as.cpp
  34. 2 1
      extras/tests/JsonVariant/clear.cpp
  35. 4 2
      extras/tests/JsonVariant/containsKey.cpp
  36. 5 3
      extras/tests/JsonVariant/copy.cpp
  37. 6 5
      extras/tests/JsonVariant/remove.cpp
  38. 4 3
      extras/tests/JsonVariant/set.cpp
  39. 13 11
      extras/tests/JsonVariant/subscript.cpp
  40. 4 2
      extras/tests/JsonVariant/unbound.cpp
  41. 4 2
      extras/tests/JsonVariantConst/as.cpp
  42. 4 2
      extras/tests/JsonVariantConst/containsKey.cpp
  43. 12 11
      extras/tests/JsonVariantConst/subscript.cpp
  44. 3 2
      extras/tests/Misc/StringWriter.cpp
  45. 11 9
      extras/tests/Misc/unsigned_char.cpp
  46. 3 1
      extras/tests/MixedConfiguration/string_length_size_1.cpp
  47. 3 2
      extras/tests/MixedConfiguration/string_length_size_2.cpp
  48. 6 4
      extras/tests/MixedConfiguration/string_length_size_4.cpp
  49. 7 6
      extras/tests/MsgPackDeserializer/deserializeVariant.cpp
  50. 5 4
      extras/tests/MsgPackDeserializer/destination_types.cpp
  51. 4 3
      extras/tests/MsgPackDeserializer/filter.cpp
  52. 5 6
      extras/tests/MsgPackDeserializer/input_types.cpp
  53. 3 2
      extras/tests/MsgPackSerializer/serializeArray.cpp
  54. 3 1
      extras/tests/MsgPackSerializer/serializeObject.cpp
  55. 7 7
      extras/tests/MsgPackSerializer/serializeVariant.cpp

+ 2 - 1
extras/tests/Cpp17/string_view.cpp

@@ -12,6 +12,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 #if !ARDUINOJSON_ENABLE_STRING_VIEW
 #  error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1
@@ -92,7 +93,7 @@ TEST_CASE("string_view") {
   }
 
   SECTION("String containing NUL") {
-    doc.set(std::string("hello\0world", 11));
+    doc.set("hello\0world"_s);
     REQUIRE(doc.as<std::string_view>().size() == 11);
     REQUIRE(doc.as<std::string_view>() == std::string_view("hello\0world", 11));
   }

+ 5 - 3
extras/tests/Deprecated/createNestedArray.cpp

@@ -7,6 +7,8 @@
 
 #include <string>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonDocument::createNestedArray()") {
   JsonDocument doc;
 
@@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::createNestedArray()") {
   }
 
   SECTION("createNestedArray(std::string)") {
-    JsonArray array = doc.createNestedArray(std::string("key"));
+    JsonArray array = doc.createNestedArray("key"_s);
     array.add(42);
     REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
   }
@@ -59,7 +61,7 @@ TEST_CASE("JsonObject::createNestedArray()") {
   }
 
   SECTION("createNestedArray(std::string)") {
-    JsonArray array = object.createNestedArray(std::string("key"));
+    JsonArray array = object.createNestedArray("key"_s);
     array.add(42);
     REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
   }
@@ -93,7 +95,7 @@ TEST_CASE("JsonVariant::createNestedArray()") {
   }
 
   SECTION("createNestedArray(std::string)") {
-    JsonArray array = variant.createNestedArray(std::string("key"));
+    JsonArray array = variant.createNestedArray("key"_s);
     array.add(42);
     REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
   }

+ 5 - 3
extras/tests/Deprecated/createNestedObject.cpp

@@ -7,6 +7,8 @@
 
 #include <string>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonDocument::createNestedObject()") {
   JsonDocument doc;
 
@@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::createNestedObject()") {
   }
 
   SECTION("createNestedObject(std::string)") {
-    JsonObject object = doc.createNestedObject(std::string("key"));
+    JsonObject object = doc.createNestedObject("key"_s);
     object["hello"] = "world";
     REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
   }
@@ -59,7 +61,7 @@ TEST_CASE("JsonObject::createNestedObject()") {
   }
 
   SECTION("createNestedObject(std::string)") {
-    JsonObject nestedObject = object.createNestedObject(std::string("key"));
+    JsonObject nestedObject = object.createNestedObject("key"_s);
     nestedObject["hello"] = "world";
     REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
   }
@@ -93,7 +95,7 @@ TEST_CASE("JsonVariant::createNestedObject()") {
   }
 
   SECTION("createNestedObject(std::string)") {
-    JsonObject object = variant.createNestedObject(std::string("key"));
+    JsonObject object = variant.createNestedObject("key"_s);
     object["hello"] = "world";
     REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
   }

+ 12 - 0
extras/tests/Helpers/Literals.hpp

@@ -0,0 +1,12 @@
+// ArduinoJson - https://arduinojson.org
+// Copyright © 2014-2024, Benoit BLANCHON
+// MIT License
+
+#pragma once
+
+#include <string>
+
+// the space before _s is required by GCC 4.8
+inline std::string operator"" _s(const char* str, size_t len) {
+  return std::string(str, len);
+}

+ 6 - 5
extras/tests/JsonArray/add.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 
@@ -51,7 +52,7 @@ TEST_CASE("JsonArray::add(T)") {
 
     array.add(vla);
 
-    REQUIRE(std::string("world") == array[0]);
+    REQUIRE("world"_s == array[0]);
   }
 #endif
 
@@ -115,7 +116,7 @@ TEST_CASE("JsonArray::add(T)") {
   }
 
   SECTION("should duplicate std::string") {
-    array.add(std::string("world"));
+    array.add("world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString("world")),
@@ -139,7 +140,7 @@ TEST_CASE("JsonArray::add(T)") {
   }
 
   SECTION("should duplicate serialized(std::string)") {
-    array.add(serialized(std::string("{}")));
+    array.add(serialized("{}"_s));
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString("{}")),
@@ -147,7 +148,7 @@ TEST_CASE("JsonArray::add(T)") {
   }
 
   SECTION("should duplicate serialized(std::string)") {
-    array.add(serialized(std::string("\0XX", 3)));
+    array.add(serialized("\0XX"_s));
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString(" XX")),
@@ -182,7 +183,7 @@ TEST_CASE("JsonArray::add<T>()") {
 
 TEST_CASE("JsonObject::add(JsonObject) ") {
   JsonDocument doc1;
-  doc1[std::string("key1")] = std::string("value1");
+  doc1["key1"_s] = "value1"_s;
 
   TimebombAllocator allocator(10);
   SpyingAllocator spy(&allocator);

+ 15 - 14
extras/tests/JsonArray/copyArray.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("copyArray()") {
   SECTION("int[] -> JsonArray") {
@@ -18,7 +19,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(array, json);
-    CHECK(std::string("[1,2,3]") == json);
+    CHECK("[1,2,3]"_s == json);
   }
 
   SECTION("std::string[] -> JsonArray") {
@@ -31,7 +32,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(array, json);
-    CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
+    CHECK("[\"a\",\"b\",\"c\"]"_s == json);
   }
 
   SECTION("const char*[] -> JsonArray") {
@@ -44,7 +45,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(array, json);
-    CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
+    CHECK("[\"a\",\"b\",\"c\"]"_s == json);
   }
 
   SECTION("const char[][] -> JsonArray") {
@@ -57,7 +58,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(array, json);
-    CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
+    CHECK("[\"a\",\"b\",\"c\"]"_s == json);
   }
 
   SECTION("const char[][] -> JsonDocument") {
@@ -69,7 +70,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
+    CHECK("[\"a\",\"b\",\"c\"]"_s == json);
   }
 
   SECTION("const char[][] -> MemberProxy") {
@@ -81,7 +82,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("{\"data\":[\"a\",\"b\",\"c\"]}") == json);
+    CHECK("{\"data\":[\"a\",\"b\",\"c\"]}"_s == json);
   }
 
   SECTION("int[] -> JsonDocument") {
@@ -93,7 +94,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("[1,2,3]") == json);
+    CHECK("[1,2,3]"_s == json);
   }
 
   SECTION("int[] -> MemberProxy") {
@@ -105,7 +106,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("{\"data\":[1,2,3]}") == json);
+    CHECK("{\"data\":[1,2,3]}"_s == json);
   }
 
   SECTION("int[] -> JsonArray, but not enough memory") {
@@ -127,7 +128,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(array, json);
-    CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
+    CHECK("[[1,2,3],[4,5,6]]"_s == json);
   }
 
   SECTION("int[][] -> MemberProxy") {
@@ -139,7 +140,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("{\"data\":[[1,2,3],[4,5,6]]}") == json);
+    CHECK("{\"data\":[[1,2,3],[4,5,6]]}"_s == json);
   }
 
   SECTION("int[][] -> JsonDocument") {
@@ -151,7 +152,7 @@ TEST_CASE("copyArray()") {
     CHECK(ok);
 
     serializeJson(doc, json);
-    CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
+    CHECK("[[1,2,3],[4,5,6]]"_s == json);
   }
 
   SECTION("int[][] -> JsonArray, but not enough memory") {
@@ -223,9 +224,9 @@ TEST_CASE("copyArray()") {
     size_t result = copyArray(array, destination);
 
     CHECK(3 == result);
-    CHECK(std::string("a12345") == destination[0]);
-    CHECK(std::string("b123456") == destination[1]);
-    CHECK(std::string("c123456") == destination[2]);  // truncated
+    CHECK("a12345"_s == destination[0]);
+    CHECK("b123456"_s == destination[1]);
+    CHECK("c123456"_s == destination[2]);  // truncated
     CHECK(std::string("") == destination[3]);
   }
 

+ 4 - 2
extras/tests/JsonArray/std_string.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 static void eraseString(std::string& str) {
   char* p = const_cast<char*>(str.c_str());
   while (*p)
@@ -19,7 +21,7 @@ TEST_CASE("std::string") {
     std::string value("hello");
     array.add(value);
     eraseString(value);
-    REQUIRE(std::string("hello") == array[0]);
+    REQUIRE("hello"_s == array[0]);
   }
 
   SECTION("operator[]") {
@@ -27,6 +29,6 @@ TEST_CASE("std::string") {
     array.add("hello");
     array[0] = value;
     eraseString(value);
-    REQUIRE(std::string("world") == array[0]);
+    REQUIRE("world"_s == array[0]);
   }
 }

+ 4 - 3
extras/tests/JsonArray/subscript.cpp

@@ -7,6 +7,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonArray::operator[]") {
   SpyingAllocator spy;
@@ -129,7 +130,7 @@ TEST_CASE("JsonArray::operator[]") {
   }
 
   SECTION("should duplicate std::string") {
-    array[0] = std::string("world");
+    array[0] = "world"_s;
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString("world")),
@@ -150,7 +151,7 @@ TEST_CASE("JsonArray::operator[]") {
     array.add("hello");
     array[0].set(vla);
 
-    REQUIRE(std::string("world") == array[0]);
+    REQUIRE("world"_s == array[0]);
   }
 
   SECTION("operator=(VLA)") {
@@ -161,7 +162,7 @@ TEST_CASE("JsonArray::operator[]") {
     array.add("hello");
     array[0] = vla;
 
-    REQUIRE(std::string("world") == array[0]);
+    REQUIRE("world"_s == array[0]);
   }
 #endif
 

+ 5 - 4
extras/tests/JsonDeserializer/destination_types.cpp

@@ -8,6 +8,7 @@
 #include <string>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 using ArduinoJson::detail::sizeofObject;
@@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject;
 TEST_CASE("deserializeJson(JsonDocument&)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc.add(std::string("hello"));
+  doc.add("hello"_s);
   spy.clearLog();
 
   auto err = deserializeJson(doc, "[42]");
@@ -34,7 +35,7 @@ TEST_CASE("deserializeJson(JsonVariant)") {
   SECTION("variant is bound") {
     SpyingAllocator spy;
     JsonDocument doc(&spy);
-    doc.add(std::string("hello"));
+    doc.add("hello"_s);
     spy.clearLog();
 
     JsonVariant variant = doc[0];
@@ -60,7 +61,7 @@ TEST_CASE("deserializeJson(JsonVariant)") {
 TEST_CASE("deserializeJson(ElementProxy)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc.add(std::string("hello"));
+  doc.add("hello"_s);
   spy.clearLog();
 
   SECTION("element already exists") {
@@ -85,7 +86,7 @@ TEST_CASE("deserializeJson(ElementProxy)") {
 TEST_CASE("deserializeJson(MemberProxy)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc[std::string("hello")] = std::string("world");
+  doc["hello"_s] = "world"_s;
   spy.clearLog();
 
   SECTION("member already exists") {

+ 4 - 3
extras/tests/JsonDeserializer/filter.cpp

@@ -10,6 +10,7 @@
 #include <string>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 using ArduinoJson::detail::sizeofObject;
@@ -732,7 +733,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, Filter") {
-    deserializeJson(doc, std::string("{}"), Filter(filter));
+    deserializeJson(doc, "{}"_s, Filter(filter));
   }
 
   SECTION("std::istream&, Filter") {
@@ -760,7 +761,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, Filter, NestingLimit") {
-    deserializeJson(doc, std::string("{}"), Filter(filter), NestingLimit(5));
+    deserializeJson(doc, "{}"_s, Filter(filter), NestingLimit(5));
   }
 
   SECTION("std::istream&, Filter, NestingLimit") {
@@ -788,7 +789,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, NestingLimit, Filter") {
-    deserializeJson(doc, std::string("{}"), NestingLimit(5), Filter(filter));
+    deserializeJson(doc, "{}"_s, NestingLimit(5), Filter(filter));
   }
 
   SECTION("std::istream&, NestingLimit, Filter") {

+ 4 - 3
extras/tests/JsonDeserializer/input_types.cpp

@@ -9,6 +9,7 @@
 
 #include "Allocators.hpp"
 #include "CustomReader.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofObject;
 
@@ -69,7 +70,7 @@ TEST_CASE("deserializeJson(const std::string&)") {
   }
 
   SECTION("should accept temporary string") {
-    DeserializationError err = deserializeJson(doc, std::string("[42]"));
+    DeserializationError err = deserializeJson(doc, "[42]"_s);
 
     REQUIRE(err == DeserializationError::Ok);
   }
@@ -82,7 +83,7 @@ TEST_CASE("deserializeJson(const std::string&)") {
 
     JsonArray array = doc.as<JsonArray>();
     REQUIRE(err == DeserializationError::Ok);
-    REQUIRE(std::string("hello") == array[0]);
+    REQUIRE("hello"_s == array[0]);
   }
 }
 
@@ -108,7 +109,7 @@ TEST_CASE("deserializeJson(std::istream&)") {
 
     REQUIRE(err == DeserializationError::Ok);
     REQUIRE(1 == obj.size());
-    REQUIRE(std::string("world") == obj["hello"]);
+    REQUIRE("world"_s == obj["hello"]);
   }
 
   SECTION("Should not read after the closing brace of an empty object") {

+ 15 - 13
extras/tests/JsonDeserializer/nestingLimit.cpp

@@ -7,6 +7,8 @@
 
 #include <sstream>
 
+#include "Literals.hpp"
+
 #define SHOULD_WORK(expression) REQUIRE(DeserializationError::Ok == expression);
 #define SHOULD_FAIL(expression) \
   REQUIRE(DeserializationError::TooDeep == expression);
@@ -63,23 +65,23 @@ TEST_CASE("JsonDeserializer nesting") {
   SECTION("Input = std::string") {
     SECTION("limit = 0") {
       DeserializationOption::NestingLimit nesting(0);
-      SHOULD_WORK(deserializeJson(doc, std::string("\"toto\""), nesting));
-      SHOULD_WORK(deserializeJson(doc, std::string("123"), nesting));
-      SHOULD_WORK(deserializeJson(doc, std::string("true"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("[]"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("{}"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("[\"toto\"]"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":1}"), nesting));
+      SHOULD_WORK(deserializeJson(doc, "\"toto\""_s, nesting));
+      SHOULD_WORK(deserializeJson(doc, "123"_s, nesting));
+      SHOULD_WORK(deserializeJson(doc, "true"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "[]"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "{}"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "[\"toto\"]"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "{\"toto\":1}"_s, nesting));
     }
 
     SECTION("limit = 1") {
       DeserializationOption::NestingLimit nesting(1);
-      SHOULD_WORK(deserializeJson(doc, std::string("[\"toto\"]"), nesting));
-      SHOULD_WORK(deserializeJson(doc, std::string("{\"toto\":1}"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":{}}"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":[]}"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("[[\"toto\"]]"), nesting));
-      SHOULD_FAIL(deserializeJson(doc, std::string("[{\"toto\":1}]"), nesting));
+      SHOULD_WORK(deserializeJson(doc, "[\"toto\"]"_s, nesting));
+      SHOULD_WORK(deserializeJson(doc, "{\"toto\":1}"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "{\"toto\":{}}"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "{\"toto\":[]}"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "[[\"toto\"]]"_s, nesting));
+      SHOULD_FAIL(deserializeJson(doc, "[{\"toto\":1}]"_s, nesting));
     }
   }
 

+ 3 - 1
extras/tests/JsonDocument/ElementProxy.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 typedef ArduinoJson::detail::ElementProxy<JsonDocument&> ElementProxy;
 
 TEST_CASE("ElementProxy::add()") {
@@ -121,7 +123,7 @@ TEST_CASE("ElementProxy::remove()") {
     ep["a"] = 1;
     ep["b"] = 2;
 
-    ep.remove(std::string("b"));
+    ep.remove("b"_s);
 
     REQUIRE(ep.as<std::string>() == "{\"a\":1}");
   }

+ 10 - 9
extras/tests/JsonDocument/MemberProxy.cpp

@@ -9,6 +9,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 using ArduinoJson::detail::sizeofObject;
@@ -106,8 +107,8 @@ TEST_CASE("MemberProxy::containsKey()") {
   SECTION("containsKey(std::string)") {
     mp["key"] = "value";
 
-    REQUIRE(mp.containsKey(std::string("key")) == true);
-    REQUIRE(mp.containsKey(std::string("key")) == true);
+    REQUIRE(mp.containsKey("key"_s) == true);
+    REQUIRE(mp.containsKey("key"_s) == true);
   }
 }
 
@@ -117,8 +118,8 @@ TEST_CASE("MemberProxy::operator|()") {
   SECTION("const char*") {
     doc["a"] = "hello";
 
-    REQUIRE((doc["a"] | "world") == std::string("hello"));
-    REQUIRE((doc["b"] | "world") == std::string("world"));
+    REQUIRE((doc["a"] | "world") == "hello"_s);
+    REQUIRE((doc["b"] | "world") == "world"_s);
   }
 
   SECTION("Issue #1411") {
@@ -128,7 +129,7 @@ TEST_CASE("MemberProxy::operator|()") {
                                 // to trigger the bug
     const char* sensor = doc["sensor"] | test;  // "gps"
 
-    REQUIRE(sensor == std::string("gps"));
+    REQUIRE(sensor == "gps"_s);
   }
 
   SECTION("Issue #1415") {
@@ -170,7 +171,7 @@ TEST_CASE("MemberProxy::remove()") {
     mp["a"] = 1;
     mp["b"] = 2;
 
-    mp.remove(std::string("b"));
+    mp.remove("b"_s);
 
     REQUIRE(mp.as<std::string>() == "{\"a\":1}");
   }
@@ -286,8 +287,8 @@ TEST_CASE("Deduplicate keys") {
   JsonDocument doc(&spy);
 
   SECTION("std::string") {
-    doc[0][std::string("example")] = 1;
-    doc[1][std::string("example")] = 2;
+    doc[0]["example"_s] = 1;
+    doc[1]["example"_s] = 2;
 
     const char* key1 = doc[0].as<JsonObject>().begin()->key().c_str();
     const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
@@ -351,7 +352,7 @@ TEST_CASE("MemberProxy under memory constraints") {
   SECTION("key allocation fails") {
     killswitch.on();
 
-    doc[std::string("hello")] = "world";
+    doc["hello"_s] = "world";
 
     REQUIRE(doc.is<JsonObject>());
     REQUIRE(doc.size() == 0);

+ 4 - 3
extras/tests/JsonDocument/add.cpp

@@ -9,6 +9,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 
@@ -35,8 +36,8 @@ TEST_CASE("JsonDocument::add(T)") {
   }
 
   SECTION("std::string") {
-    doc.add(std::string("example"));
-    doc.add(std::string("example"));
+    doc.add("example"_s);
+    doc.add("example"_s);
 
     CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
     REQUIRE(spy.log() == AllocatorLog{
@@ -99,7 +100,7 @@ TEST_CASE("JsonDocument::add<T>()") {
 
 TEST_CASE("JsonObject::add(JsonObject) ") {
   JsonDocument doc1;
-  doc1[std::string("hello")] = std::string("world");
+  doc1["hello"_s] = "world"_s;
 
   TimebombAllocator allocator(10);
   SpyingAllocator spy(&allocator);

+ 2 - 1
extras/tests/JsonDocument/assignment.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonDocument assignment") {
   SpyingAllocator spyingAllocator;
@@ -62,7 +63,7 @@ TEST_CASE("JsonDocument assignment") {
   SECTION("Move assign") {
     {
       JsonDocument doc1(&spyingAllocator);
-      doc1[std::string("hello")] = std::string("world");
+      doc1["hello"_s] = "world"_s;
       JsonDocument doc2(&spyingAllocator);
 
       doc2 = std::move(doc1);

+ 2 - 1
extras/tests/JsonDocument/clear.cpp

@@ -9,6 +9,7 @@
 #include <string>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonDocument::clear()") {
   SpyingAllocator spy;
@@ -22,7 +23,7 @@ TEST_CASE("JsonDocument::clear()") {
   }
 
   SECTION("releases resources") {
-    doc[std::string("hello")] = std::string("world");
+    doc["hello"_s] = "world"_s;
     spy.clearLog();
 
     doc.clear();

+ 3 - 2
extras/tests/JsonDocument/constructor.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::addPadding;
 
@@ -20,7 +21,7 @@ TEST_CASE("JsonDocument constructor") {
   SECTION("JsonDocument(const JsonDocument&)") {
     {
       JsonDocument doc1(&spyingAllocator);
-      doc1.set(std::string("The size of this string is 32!!"));
+      doc1.set("The size of this string is 32!!"_s);
 
       JsonDocument doc2(doc1);
 
@@ -38,7 +39,7 @@ TEST_CASE("JsonDocument constructor") {
   SECTION("JsonDocument(JsonDocument&&)") {
     {
       JsonDocument doc1(&spyingAllocator);
-      doc1.set(std::string("The size of this string is 32!!"));
+      doc1.set("The size of this string is 32!!"_s);
 
       JsonDocument doc2(std::move(doc1));
 

+ 3 - 1
extras/tests/JsonDocument/containsKey.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonDocument::containsKey()") {
   JsonDocument doc;
 
@@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::containsKey()") {
   SECTION("returns true when key is a std::string") {
     doc["hello"] = "world";
 
-    REQUIRE(doc.containsKey(std::string("hello")) == true);
+    REQUIRE(doc.containsKey("hello"_s) == true);
   }
 
   SECTION("returns false  on object") {

+ 6 - 4
extras/tests/JsonDocument/issue1120.cpp

@@ -2,6 +2,8 @@
 
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("Issue #1120") {
   JsonDocument doc;
   constexpr char str[] =
@@ -10,12 +12,12 @@ TEST_CASE("Issue #1120") {
 
   SECTION("MemberProxy<std::string>::isNull()") {
     SECTION("returns false") {
-      auto value = doc[std::string("contents")];
+      auto value = doc["contents"_s];
       CHECK(value.isNull() == false);
     }
 
     SECTION("returns true") {
-      auto value = doc[std::string("zontents")];
+      auto value = doc["zontents"_s];
       CHECK(value.isNull() == true);
     }
   }
@@ -46,12 +48,12 @@ TEST_CASE("Issue #1120") {
 
   SECTION("MemberProxy<ElementProxy<MemberProxy>, std::string>::isNull()") {
     SECTION("returns false") {
-      auto value = doc["contents"][1][std::string("module")];
+      auto value = doc["contents"][1]["module"_s];
       CHECK(value.isNull() == false);
     }
 
     SECTION("returns true") {
-      auto value = doc["contents"][1][std::string("zodule")];
+      auto value = doc["contents"][1]["zodule"_s];
       CHECK(value.isNull() == true);
     }
   }

+ 3 - 2
extras/tests/JsonDocument/overflowed.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonDocument::overflowed()") {
   TimebombAllocator timebomb(10);
@@ -30,13 +31,13 @@ TEST_CASE("JsonDocument::overflowed()") {
 
   SECTION("returns true after a failed string copy") {
     timebomb.setCountdown(0);
-    doc.add(std::string("example"));
+    doc.add("example"_s);
     CHECK(doc.overflowed() == true);
   }
 
   SECTION("returns false after a successful string copy") {
     timebomb.setCountdown(3);
-    doc.add(std::string("example"));
+    doc.add("example"_s);
     CHECK(doc.overflowed() == false);
   }
 

+ 3 - 1
extras/tests/JsonDocument/remove.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonDocument::remove()") {
   JsonDocument doc;
 
@@ -31,7 +33,7 @@ TEST_CASE("JsonDocument::remove()") {
     doc["a"] = 1;
     doc["b"] = 2;
 
-    doc.remove(std::string("b"));
+    doc.remove("b"_s);
 
     REQUIRE(doc.as<std::string>() == "{\"a\":1}");
   }

+ 5 - 4
extras/tests/JsonDocument/shrinkToFit.cpp

@@ -9,6 +9,7 @@
 #include <string>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 using ArduinoJson::detail::sizeofObject;
@@ -78,7 +79,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
   }
 
   SECTION("owned string") {
-    doc.set(std::string("abcdefg"));
+    doc.set("abcdefg"_s);
     REQUIRE(doc.as<std::string>() == "abcdefg");
 
     doc.shrinkToFit();
@@ -114,7 +115,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
   }
 
   SECTION("owned key") {
-    doc[std::string("abcdefg")] = 42;
+    doc["abcdefg"_s] = 42;
 
     doc.shrinkToFit();
 
@@ -141,7 +142,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
   }
 
   SECTION("owned string in array") {
-    doc.add(std::string("abcdefg"));
+    doc.add("abcdefg"_s);
 
     doc.shrinkToFit();
 
@@ -168,7 +169,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
   }
 
   SECTION("owned string in object") {
-    doc["key"] = std::string("abcdefg");
+    doc["key"] = "abcdefg"_s;
 
     doc.shrinkToFit();
 

+ 6 - 4
extras/tests/JsonDocument/subscript.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonDocument::operator[]") {
   JsonDocument doc;
   const JsonDocument& cdoc = doc;
@@ -18,8 +20,8 @@ TEST_CASE("JsonDocument::operator[]") {
     }
 
     SECTION("std::string") {
-      REQUIRE(doc[std::string("hello")] == "world");
-      REQUIRE(cdoc[std::string("hello")] == "world");
+      REQUIRE(doc["hello"_s] == "world");
+      REQUIRE(cdoc["hello"_s] == "world");
     }
 
     SECTION("JsonVariant") {
@@ -29,8 +31,8 @@ TEST_CASE("JsonDocument::operator[]") {
     }
 
     SECTION("supports operator|") {
-      REQUIRE((doc["hello"] | "nope") == std::string("world"));
-      REQUIRE((doc["world"] | "nope") == std::string("nope"));
+      REQUIRE((doc["hello"] | "nope") == "world"_s);
+      REQUIRE((doc["world"] | "nope") == "nope"_s);
     }
   }
 

+ 12 - 11
extras/tests/JsonObject/set.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonObject::set()") {
   SpyingAllocator spy;
@@ -22,20 +23,20 @@ TEST_CASE("JsonObject::set()") {
     bool success = obj2.set(obj1);
 
     REQUIRE(success == true);
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                          });
   }
 
   SECTION("copy local string value") {
-    obj1["hello"] = std::string("world");
+    obj1["hello"] = "world"_s;
     spy.clearLog();
 
     bool success = obj2.set(obj1);
 
     REQUIRE(success == true);
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString("world")),
@@ -43,13 +44,13 @@ TEST_CASE("JsonObject::set()") {
   }
 
   SECTION("copy local key") {
-    obj1[std::string("hello")] = "world";
+    obj1["hello"_s] = "world";
     spy.clearLog();
 
     bool success = obj2.set(obj1);
 
     REQUIRE(success == true);
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofString("hello")),
                              Allocate(sizeofPool()),
@@ -63,7 +64,7 @@ TEST_CASE("JsonObject::set()") {
     bool success = obj2.set(obj1);
 
     REQUIRE(success == true);
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofString("hello")),
                              Allocate(sizeofPool()),
@@ -78,7 +79,7 @@ TEST_CASE("JsonObject::set()") {
     bool success = obj2.set(obj1);
 
     REQUIRE(success == true);
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofString("hello")),
                              Allocate(sizeofPool()),
@@ -91,7 +92,7 @@ TEST_CASE("JsonObject::set()") {
 
     obj2.set(static_cast<JsonObjectConst>(obj1));
 
-    REQUIRE(obj2["hello"] == std::string("world"));
+    REQUIRE(obj2["hello"] == "world"_s);
   }
 
   SECTION("copy fails in the middle of an object") {
@@ -99,8 +100,8 @@ TEST_CASE("JsonObject::set()") {
     JsonDocument doc3(&timebomb);
     JsonObject obj3 = doc3.to<JsonObject>();
 
-    obj1[std::string("a")] = 1;
-    obj1[std::string("b")] = 2;
+    obj1["a"_s] = 1;
+    obj1["b"_s] = 2;
 
     bool success = obj3.set(obj1);
 
@@ -113,7 +114,7 @@ TEST_CASE("JsonObject::set()") {
     JsonDocument doc3(&timebomb);
     JsonObject obj3 = doc3.to<JsonObject>();
 
-    obj1["hello"][0] = std::string("world");
+    obj1["hello"][0] = "world"_s;
 
     bool success = obj3.set(obj1);
 

+ 8 - 6
extras/tests/JsonObject/std_string.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 static void eraseString(std::string& str) {
   char* p = const_cast<char*>(str.c_str());
   while (*p)
@@ -20,7 +22,7 @@ TEST_CASE("std::string") {
     deserializeJson(doc, json);
     JsonObject obj = doc.as<JsonObject>();
 
-    REQUIRE(std::string("value") == obj[std::string("key")]);
+    REQUIRE("value"_s == obj["key"_s]);
   }
 
   SECTION("operator[] const") {
@@ -29,21 +31,21 @@ TEST_CASE("std::string") {
     deserializeJson(doc, json);
     JsonObject obj = doc.as<JsonObject>();
 
-    REQUIRE(std::string("value") == obj[std::string("key")]);
+    REQUIRE("value"_s == obj["key"_s]);
   }
 
   SECTION("containsKey()") {
     char json[] = "{\"key\":\"value\"}";
     deserializeJson(doc, json);
     JsonObject obj = doc.as<JsonObject>();
-    REQUIRE(true == obj.containsKey(std::string("key")));
+    REQUIRE(true == obj.containsKey("key"_s));
   }
 
   SECTION("remove()") {
     JsonObject obj = doc.to<JsonObject>();
     obj["key"] = "value";
 
-    obj.remove(std::string("key"));
+    obj.remove("key"_s);
 
     REQUIRE(0 == obj.size());
   }
@@ -53,7 +55,7 @@ TEST_CASE("std::string") {
     JsonObject obj = doc.to<JsonObject>();
     obj[key] = "world";
     eraseString(key);
-    REQUIRE(std::string("world") == obj["hello"]);
+    REQUIRE("world"_s == obj["hello"]);
   }
 
   SECTION("operator[], set value") {
@@ -61,6 +63,6 @@ TEST_CASE("std::string") {
     JsonObject obj = doc.to<JsonObject>();
     obj["hello"] = value;
     eraseString(value);
-    REQUIRE(std::string("world") == obj["hello"]);
+    REQUIRE("world"_s == obj["hello"]);
   }
 }

+ 10 - 9
extras/tests/JsonObject/subscript.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonObject::operator[]") {
   SpyingAllocator spy;
@@ -50,7 +51,7 @@ TEST_CASE("JsonObject::operator[]") {
 
     REQUIRE(true == obj["hello"].is<const char*>());
     REQUIRE(false == obj["hello"].is<long>());
-    REQUIRE(std::string("h3110") == obj["hello"].as<const char*>());
+    REQUIRE("h3110"_s == obj["hello"].as<const char*>());
   }
 
   SECTION("array") {
@@ -132,7 +133,7 @@ TEST_CASE("JsonObject::operator[]") {
   }
 
   SECTION("should duplicate std::string value") {
-    obj["hello"] = std::string("world");
+    obj["hello"] = "world"_s;
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofPool()),
                              Allocate(sizeofString("world")),
@@ -140,7 +141,7 @@ TEST_CASE("JsonObject::operator[]") {
   }
 
   SECTION("should duplicate std::string key") {
-    obj[std::string("hello")] = "world";
+    obj["hello"_s] = "world";
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofString("hello")),
                              Allocate(sizeofPool()),
@@ -148,7 +149,7 @@ TEST_CASE("JsonObject::operator[]") {
   }
 
   SECTION("should duplicate std::string key&value") {
-    obj[std::string("hello")] = std::string("world");
+    obj["hello"_s] = "world"_s;
     REQUIRE(spy.log() == AllocatorLog{
                              Allocate(sizeofString("hello")),
                              Allocate(sizeofPool()),
@@ -197,7 +198,7 @@ TEST_CASE("JsonObject::operator[]") {
 
     obj[vla] = "world";
 
-    REQUIRE(std::string("world") == obj["hello"]);
+    REQUIRE("world"_s == obj["hello"]);
   }
 
   SECTION("obj[str] = VLA") {  // issue #416
@@ -207,7 +208,7 @@ TEST_CASE("JsonObject::operator[]") {
 
     obj["hello"] = vla;
 
-    REQUIRE(std::string("world") == obj["hello"].as<const char*>());
+    REQUIRE("world"_s == obj["hello"].as<const char*>());
   }
 
   SECTION("obj.set(VLA, str)") {
@@ -217,7 +218,7 @@ TEST_CASE("JsonObject::operator[]") {
 
     obj[vla] = "world";
 
-    REQUIRE(std::string("world") == obj["hello"]);
+    REQUIRE("world"_s == obj["hello"]);
   }
 
   SECTION("obj.set(str, VLA)") {
@@ -227,7 +228,7 @@ TEST_CASE("JsonObject::operator[]") {
 
     obj["hello"].set(vla);
 
-    REQUIRE(std::string("world") == obj["hello"].as<const char*>());
+    REQUIRE("world"_s == obj["hello"].as<const char*>());
   }
 
   SECTION("obj[VLA]") {
@@ -238,7 +239,7 @@ TEST_CASE("JsonObject::operator[]") {
     deserializeJson(doc, "{\"hello\":\"world\"}");
 
     obj = doc.as<JsonObject>();
-    REQUIRE(std::string("world") == obj[vla]);
+    REQUIRE("world"_s == obj[vla]);
   }
 #endif
 

+ 4 - 2
extras/tests/JsonObjectConst/containsKey.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonObjectConst::containsKey()") {
   JsonDocument doc;
   doc["hello"] = 42;
@@ -16,8 +18,8 @@ TEST_CASE("JsonObjectConst::containsKey()") {
   }
 
   SECTION("supports std::string") {
-    REQUIRE(false == obj.containsKey(std::string("world")));
-    REQUIRE(true == obj.containsKey(std::string("hello")));
+    REQUIRE(false == obj.containsKey("world"_s));
+    REQUIRE(true == obj.containsKey("hello"_s));
   }
 
 #ifdef HAS_VARIABLE_LENGTH_ARRAY

+ 3 - 2
extras/tests/JsonObjectConst/subscript.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonObjectConst::operator[]") {
   JsonDocument doc;
@@ -17,7 +18,7 @@ TEST_CASE("JsonObjectConst::operator[]") {
   }
 
   SECTION("supports std::string") {
-    REQUIRE(obj[std::string("hello")] == "world");  // issue #2019
+    REQUIRE(obj["hello"_s] == "world");  // issue #2019
   }
 
 #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
@@ -27,7 +28,7 @@ TEST_CASE("JsonObjectConst::operator[]") {
     char vla[i];
     strcpy(vla, "hello");
 
-    REQUIRE(std::string("world") == obj[vla]);
+    REQUIRE("world"_s == obj[vla]);
   }
 #endif
 

+ 13 - 11
extras/tests/JsonSerializer/JsonVariant.cpp

@@ -6,6 +6,8 @@
 #include <catch.hpp>
 #include <limits>
 
+#include "Literals.hpp"
+
 template <typename T>
 void check(T value, const std::string& expected) {
   JsonDocument doc;
@@ -30,42 +32,42 @@ TEST_CASE("serializeJson(JsonVariant)") {
   }
 
   SECTION("string") {
-    check(std::string("hello"), "\"hello\"");
+    check("hello"_s, "\"hello\"");
 
     SECTION("Escape quotation mark") {
-      check(std::string("hello \"world\""), "\"hello \\\"world\\\"\"");
+      check("hello \"world\""_s, "\"hello \\\"world\\\"\"");
     }
 
     SECTION("Escape reverse solidus") {
-      check(std::string("hello\\world"), "\"hello\\\\world\"");
+      check("hello\\world"_s, "\"hello\\\\world\"");
     }
 
     SECTION("Don't escape solidus") {
-      check(std::string("fifty/fifty"), "\"fifty/fifty\"");
+      check("fifty/fifty"_s, "\"fifty/fifty\"");
     }
 
     SECTION("Escape backspace") {
-      check(std::string("hello\bworld"), "\"hello\\bworld\"");
+      check("hello\bworld"_s, "\"hello\\bworld\"");
     }
 
     SECTION("Escape formfeed") {
-      check(std::string("hello\fworld"), "\"hello\\fworld\"");
+      check("hello\fworld"_s, "\"hello\\fworld\"");
     }
 
     SECTION("Escape linefeed") {
-      check(std::string("hello\nworld"), "\"hello\\nworld\"");
+      check("hello\nworld"_s, "\"hello\\nworld\"");
     }
 
     SECTION("Escape carriage return") {
-      check(std::string("hello\rworld"), "\"hello\\rworld\"");
+      check("hello\rworld"_s, "\"hello\\rworld\"");
     }
 
     SECTION("Escape tab") {
-      check(std::string("hello\tworld"), "\"hello\\tworld\"");
+      check("hello\tworld"_s, "\"hello\\tworld\"");
     }
 
     SECTION("NUL char") {
-      check(std::string("hello\0world", 11), "\"hello\\u0000world\"");
+      check("hello\0world"_s, "\"hello\\u0000world\"");
     }
   }
 
@@ -74,7 +76,7 @@ TEST_CASE("serializeJson(JsonVariant)") {
   }
 
   SECTION("SerializedValue<std::string>") {
-    check(serialized(std::string("[1,2]")), "[1,2]");
+    check(serialized("[1,2]"_s), "[1,2]");
   }
 
   SECTION("Double") {

+ 3 - 1
extras/tests/JsonSerializer/std_string.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("serialize JsonArray to std::string") {
   JsonDocument doc;
   JsonArray array = doc.to<JsonArray>();
@@ -48,7 +50,7 @@ TEST_CASE("serialize JsonObject to std::string") {
 
 TEST_CASE("serialize an std::string containing a NUL") {
   JsonDocument doc;
-  doc.set(std::string("hello\0world", 11));
+  doc.set("hello\0world"_s);
 
   std::string json = "erase me";
   serializeJson(doc, json);

+ 3 - 2
extras/tests/JsonVariant/add.cpp

@@ -7,6 +7,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonVariant::add(T)") {
   JsonDocument doc;
@@ -25,7 +26,7 @@ TEST_CASE("JsonVariant::add(T)") {
   }
 
   SECTION("add std::string to new variant") {
-    var.add(std::string("hello"));
+    var.add("hello"_s);
 
     REQUIRE(var.as<std::string>() == "[\"hello\"]");
   }
@@ -67,7 +68,7 @@ TEST_CASE("JsonVariant::add<T>()") {
 
 TEST_CASE("JsonObject::add(JsonObject) ") {
   JsonDocument doc1;
-  doc1[std::string("hello")] = std::string("world");
+  doc1["hello"_s] = "world"_s;
 
   TimebombAllocator allocator(10);
   SpyingAllocator spy(&allocator);

+ 11 - 9
extras/tests/JsonVariant/as.cpp

@@ -6,6 +6,8 @@
 #include <stdint.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 namespace my {
 using ArduinoJson::detail::isinf;
 }  // namespace my
@@ -156,20 +158,20 @@ TEST_CASE("JsonVariant::as()") {
 
     REQUIRE(variant.as<bool>() == true);
     REQUIRE(variant.as<long>() == 0L);
-    REQUIRE(variant.as<const char*>() == std::string("hello"));
-    REQUIRE(variant.as<const char*>() == std::string("hello"));
-    REQUIRE(variant.as<std::string>() == std::string("hello"));
+    REQUIRE(variant.as<const char*>() == "hello"_s);
+    REQUIRE(variant.as<const char*>() == "hello"_s);
+    REQUIRE(variant.as<std::string>() == "hello"_s);
     REQUIRE(variant.as<JsonString>() == "hello");
   }
 
   SECTION("set(std::string(\"4.2\"))") {
-    variant.set(std::string("4.2"));
+    variant.set("4.2"_s);
 
     REQUIRE(variant.as<bool>() == true);
     REQUIRE(variant.as<long>() == 4L);
     REQUIRE(variant.as<double>() == 4.2);
-    REQUIRE(variant.as<const char*>() == std::string("4.2"));
-    REQUIRE(variant.as<std::string>() == std::string("4.2"));
+    REQUIRE(variant.as<const char*>() == "4.2"_s);
+    REQUIRE(variant.as<std::string>() == "4.2"_s);
     REQUIRE(variant.as<JsonString>() == "4.2");
     REQUIRE(variant.as<JsonString>().isLinked() == false);
   }
@@ -227,13 +229,13 @@ TEST_CASE("JsonVariant::as()") {
     }
 
     SECTION("as<std::string>()") {
-      REQUIRE(variant.as<std::string>() == std::string("{\"key\":\"value\"}"));
+      REQUIRE(variant.as<std::string>() == "{\"key\":\"value\"}"_s);
     }
 
     SECTION("ObjectAsJsonObject") {
       JsonObject o = variant.as<JsonObject>();
       REQUIRE(o.size() == 1);
-      REQUIRE(o["key"] == std::string("value"));
+      REQUIRE(o["key"] == "value"_s);
     }
   }
 
@@ -247,7 +249,7 @@ TEST_CASE("JsonVariant::as()") {
     }
 
     SECTION("as<std::string>()") {
-      REQUIRE(variant.as<std::string>() == std::string("[4,2]"));
+      REQUIRE(variant.as<std::string>() == "[4,2]"_s);
     }
 
     SECTION("as<JsonArray>()") {

+ 2 - 1
extras/tests/JsonVariant/clear.cpp

@@ -7,6 +7,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 TEST_CASE("JsonVariant::clear()") {
   SpyingAllocator spy;
@@ -28,7 +29,7 @@ TEST_CASE("JsonVariant::clear()") {
   }
 
   SECTION("releases owned string") {
-    var.set(std::string("hello"));
+    var.set("hello"_s);
     var.clear();
 
     REQUIRE(spy.log() == AllocatorLog{

+ 4 - 2
extras/tests/JsonVariant/containsKey.cpp

@@ -6,6 +6,8 @@
 #include <stdint.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariant::containsKey()") {
   JsonDocument doc;
   JsonVariant var = doc.to<JsonVariant>();
@@ -20,8 +22,8 @@ TEST_CASE("JsonVariant::containsKey()") {
   SECTION("containsKey(std::string)") {
     var["hello"] = "world";
 
-    REQUIRE(var.containsKey(std::string("hello")) == true);
-    REQUIRE(var.containsKey(std::string("world")) == false);
+    REQUIRE(var.containsKey("hello"_s) == true);
+    REQUIRE(var.containsKey("world"_s) == false);
   }
 
   SECTION("containsKey(JsonVariant)") {

+ 5 - 3
extras/tests/JsonVariant/copy.cpp

@@ -6,6 +6,8 @@
 #include <catch.hpp>
 #include "Allocators.hpp"
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariant::set(JsonVariant)") {
   KillswitchAllocator killswitch;
   SpyingAllocator spyingAllocator(&killswitch);
@@ -72,7 +74,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
   }
 
   SECTION("stores std::string by copy") {
-    var1.set(std::string("hello!!"));
+    var1.set("hello!!"_s);
     spyingAllocator.clearLog();
 
     var2.set(var1);
@@ -106,7 +108,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
   }
 
   SECTION("stores Serialized<std::string> by copy") {
-    var1.set(serialized(std::string("hello!!")));
+    var1.set(serialized("hello!!"_s));
     spyingAllocator.clearLog();
 
     var2.set(var1);
@@ -117,7 +119,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
   }
 
   SECTION("fails gracefully if raw string allocation fails") {
-    var1.set(serialized(std::string("hello!!")));
+    var1.set(serialized("hello!!"_s));
     killswitch.on();
     spyingAllocator.clearLog();
 

+ 6 - 5
extras/tests/JsonVariant/remove.cpp

@@ -7,6 +7,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 
@@ -15,9 +16,9 @@ TEST_CASE("JsonVariant::remove(int)") {
   JsonDocument doc(&spy);
 
   SECTION("release top level strings") {
-    doc.add(std::string("hello"));
-    doc.add(std::string("hello"));
-    doc.add(std::string("world"));
+    doc.add("hello"_s);
+    doc.add("hello"_s);
+    doc.add("world"_s);
 
     JsonVariant var = doc.as<JsonVariant>();
     REQUIRE(var.as<std::string>() == "[\"hello\",\"hello\",\"world\"]");
@@ -43,7 +44,7 @@ TEST_CASE("JsonVariant::remove(int)") {
   }
 
   SECTION("release strings in nested array") {
-    doc[0][0] = std::string("hello");
+    doc[0][0] = "hello"_s;
 
     JsonVariant var = doc.as<JsonVariant>();
     REQUIRE(var.as<std::string>() == "[[\"hello\"]]");
@@ -77,7 +78,7 @@ TEST_CASE("JsonVariant::remove(std::string)") {
   var["a"] = 1;
   var["b"] = 2;
 
-  var.remove(std::string("b"));
+  var.remove("b"_s);
 
   REQUIRE(var.as<std::string>() == "{\"a\":1}");
 }

+ 4 - 3
extras/tests/JsonVariant/set.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofObject;
 
@@ -137,14 +138,14 @@ TEST_CASE("JsonVariant::set() with not enough memory") {
   JsonVariant v = doc.to<JsonVariant>();
 
   SECTION("std::string") {
-    bool result = v.set(std::string("hello world!!"));
+    bool result = v.set("hello world!!"_s);
 
     REQUIRE(result == false);
     REQUIRE(v.isNull());
   }
 
   SECTION("Serialized<std::string>") {
-    bool result = v.set(serialized(std::string("hello world!!")));
+    bool result = v.set(serialized("hello world!!"_s));
 
     REQUIRE(result == false);
     REQUIRE(v.isNull());
@@ -178,7 +179,7 @@ TEST_CASE("JsonVariant::set(JsonDocument)") {
 TEST_CASE("JsonVariant::set() releases the previous value") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc["hello"] = std::string("world");
+  doc["hello"] = "world"_s;
   spy.clearLog();
 
   JsonVariant v = doc["hello"];

+ 13 - 11
extras/tests/JsonVariant/subscript.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariant::operator[]") {
   JsonDocument doc;
   JsonVariant var = doc.to<JsonVariant>();
@@ -31,9 +33,9 @@ TEST_CASE("JsonVariant::operator[]") {
 
       REQUIRE(2 == var.size());
       var[0].as<std::string>();
-      // REQUIRE(std::string("element at index 0") == );
-      REQUIRE(std::string("element at index 1") == var[1]);
-      REQUIRE(std::string("element at index 0") ==
+      // REQUIRE("element at index 0"_s == );
+      REQUIRE("element at index 1"_s == var[1]);
+      REQUIRE("element at index 0"_s ==
               var[static_cast<unsigned char>(0)]);  // issue #381
       REQUIRE(var[666].isNull());
       REQUIRE(var[3].isNull());
@@ -46,7 +48,7 @@ TEST_CASE("JsonVariant::operator[]") {
       var[1] = "world";
 
       REQUIRE(var.size() == 2);
-      REQUIRE(std::string("world") == var[1]);
+      REQUIRE("world"_s == var[1]);
     }
 
     SECTION("set value in a nested object") {
@@ -56,7 +58,7 @@ TEST_CASE("JsonVariant::operator[]") {
 
       REQUIRE(1 == var.size());
       REQUIRE(1 == var[0].size());
-      REQUIRE(std::string("world") == var[0]["hello"]);
+      REQUIRE("world"_s == var[0]["hello"]);
     }
 
     SECTION("variant[0] when variant contains an integer") {
@@ -86,8 +88,8 @@ TEST_CASE("JsonVariant::operator[]") {
       object["b"] = "element at key \"b\"";
 
       REQUIRE(2 == var.size());
-      REQUIRE(std::string("element at key \"a\"") == var["a"]);
-      REQUIRE(std::string("element at key \"b\"") == var["b"]);
+      REQUIRE("element at key \"a\""_s == var["a"]);
+      REQUIRE("element at key \"b\""_s == var["b"]);
       REQUIRE(var["c"].isNull());
       REQUIRE(var[0].isNull());
     }
@@ -96,7 +98,7 @@ TEST_CASE("JsonVariant::operator[]") {
       var["hello"] = "world";
 
       REQUIRE(1 == var.size());
-      REQUIRE(std::string("world") == var["hello"]);
+      REQUIRE("world"_s == var["hello"]);
     }
 
     SECTION("set value, key is a char[]") {
@@ -105,7 +107,7 @@ TEST_CASE("JsonVariant::operator[]") {
       key[0] = '!';  // make sure the key is duplicated
 
       REQUIRE(1 == var.size());
-      REQUIRE(std::string("world") == var["hello"]);
+      REQUIRE("world"_s == var["hello"]);
     }
 
     SECTION("var[key].to<JsonArray>()") {
@@ -133,7 +135,7 @@ TEST_CASE("JsonVariant::operator[]") {
     deserializeJson(doc, "{\"hello\":\"world\"}");
     JsonVariant variant = doc.as<JsonVariant>();
 
-    REQUIRE(std::string("world") == variant[vla]);
+    REQUIRE("world"_s == variant[vla]);
   }
 
   SECTION("key is a VLA, const JsonVariant") {
@@ -144,7 +146,7 @@ TEST_CASE("JsonVariant::operator[]") {
     deserializeJson(doc, "{\"hello\":\"world\"}");
     const JsonVariant variant = doc.as<JsonVariant>();
 
-    REQUIRE(std::string("world") == variant[vla]);
+    REQUIRE("world"_s == variant[vla]);
   }
 #endif
 }

+ 4 - 2
extras/tests/JsonVariant/unbound.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("Unbound JsonVariant") {
   JsonVariant variant;
 
@@ -48,7 +50,7 @@ TEST_CASE("Unbound JsonVariant") {
     CHECK_FALSE(variant.set(42L));
     CHECK_FALSE(variant.set(42U));
     CHECK_FALSE(variant.set(serialized("42")));
-    CHECK_FALSE(variant.set(serialized(std::string("42"))));
+    CHECK_FALSE(variant.set(serialized("42"_s)));
     CHECK_FALSE(variant.set(true));
     CHECK_FALSE(variant.set(MsgPackBinary("hello", 5)));
     CHECK_FALSE(variant.set(MsgPackExtension(1, "hello", 5)));
@@ -68,7 +70,7 @@ TEST_CASE("Unbound JsonVariant") {
     CHECK(variant["key"].isNull());
     CHECK_FALSE(variant[0].set(1));
     CHECK_FALSE(variant["key"].set(1));
-    CHECK_FALSE(variant[std::string("key")].set(1));
+    CHECK_FALSE(variant["key"_s].set(1));
   }
 
   SECTION("containsKey()") {

+ 4 - 2
extras/tests/JsonVariantConst/as.cpp

@@ -6,6 +6,8 @@
 #include <stdint.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariantConst::as<T>()") {
   JsonDocument doc;
   JsonVariantConst var = doc.to<JsonVariant>();
@@ -14,8 +16,8 @@ TEST_CASE("JsonVariantConst::as<T>()") {
 
   REQUIRE(var.as<bool>() == true);
   REQUIRE(var.as<long>() == 0L);
-  REQUIRE(var.as<const char*>() == std::string("hello"));
-  REQUIRE(var.as<std::string>() == std::string("hello"));
+  REQUIRE(var.as<const char*>() == "hello"_s);
+  REQUIRE(var.as<std::string>() == "hello"_s);
 }
 
 TEST_CASE("Invalid conversions") {

+ 4 - 2
extras/tests/JsonVariantConst/containsKey.cpp

@@ -6,6 +6,8 @@
 #include <stdint.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariantConst::containsKey()") {
   JsonDocument doc;
   doc["hello"] = "world";
@@ -17,8 +19,8 @@ TEST_CASE("JsonVariantConst::containsKey()") {
   }
 
   SECTION("support std::string") {
-    REQUIRE(var.containsKey(std::string("hello")) == true);
-    REQUIRE(var.containsKey(std::string("world")) == false);
+    REQUIRE(var.containsKey("hello"_s) == true);
+    REQUIRE(var.containsKey("world"_s) == false);
   }
 
 #ifdef HAS_VARIABLE_LENGTH_ARRAY

+ 12 - 11
extras/tests/JsonVariantConst/subscript.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 TEST_CASE("JsonVariantConst::operator[]") {
   JsonDocument doc;
   JsonVariantConst var = doc.to<JsonVariant>();
@@ -28,10 +30,9 @@ TEST_CASE("JsonVariantConst::operator[]") {
     array.add("B");
 
     SECTION("int") {
-      REQUIRE(std::string("A") == var[0]);
-      REQUIRE(std::string("B") == var[1]);
-      REQUIRE(std::string("A") ==
-              var[static_cast<unsigned char>(0)]);  // issue #381
+      REQUIRE("A"_s == var[0]);
+      REQUIRE("B"_s == var[1]);
+      REQUIRE("A"_s == var[static_cast<unsigned char>(0)]);  // issue #381
       REQUIRE(var[666].isNull());
       REQUIRE(var[3].isNull());
     }
@@ -42,7 +43,7 @@ TEST_CASE("JsonVariantConst::operator[]") {
 
     SECTION("JsonVariant") {
       array.add(1);
-      REQUIRE(var[var[2]] == std::string("B"));
+      REQUIRE(var[var[2]] == "B"_s);
       REQUIRE(var[var[3]].isNull());
     }
   }
@@ -53,16 +54,16 @@ TEST_CASE("JsonVariantConst::operator[]") {
     object["b"] = "B";
 
     SECTION("supports const char*") {
-      REQUIRE(std::string("A") == var["a"]);
-      REQUIRE(std::string("B") == var["b"]);
+      REQUIRE("A"_s == var["a"]);
+      REQUIRE("B"_s == var["b"]);
       REQUIRE(var["c"].isNull());
       REQUIRE(var[0].isNull());
     }
 
     SECTION("supports std::string") {
-      REQUIRE(std::string("A") == var[std::string("a")]);
-      REQUIRE(std::string("B") == var[std::string("b")]);
-      REQUIRE(var[std::string("c")].isNull());
+      REQUIRE("A"_s == var["a"_s]);
+      REQUIRE("B"_s == var["b"_s]);
+      REQUIRE(var["c"_s].isNull());
     }
 
 #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
@@ -72,7 +73,7 @@ TEST_CASE("JsonVariantConst::operator[]") {
       char vla[i];
       strcpy(vla, "a");
 
-      REQUIRE(std::string("A") == var[vla]);
+      REQUIRE("A"_s == var[vla]);
     }
 #endif
 

+ 3 - 2
extras/tests/Misc/StringWriter.cpp

@@ -9,6 +9,7 @@
 
 #include <catch.hpp>
 
+#include "Literals.hpp"
 #include "custom_string.hpp"
 
 using namespace ArduinoJson::detail;
@@ -36,13 +37,13 @@ void common_tests(StringWriter& writer, const String& output) {
 
   SECTION("OneString") {
     REQUIRE(4 == print(writer, "ABCD"));
-    REQUIRE(std::string("ABCD") == output);
+    REQUIRE("ABCD"_s == output);
   }
 
   SECTION("TwoStrings") {
     REQUIRE(4 == print(writer, "ABCD"));
     REQUIRE(4 == print(writer, "EFGH"));
-    REQUIRE(std::string("ABCDEFGH") == output);
+    REQUIRE("ABCDEFGH"_s == output);
   }
 }
 

+ 11 - 9
extras/tests/Misc/unsigned_char.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 #if defined(__clang__)
 #  define CONFLICTS_WITH_BUILTIN_OPERATOR
 #endif
@@ -111,7 +113,7 @@ TEST_CASE("unsigned char[]") {
       deserializeJson(doc, "{\"hello\":\"world\"}");
       JsonVariant variant = doc.as<JsonVariant>();
 
-      REQUIRE(std::string("world") == variant[key]);
+      REQUIRE("world"_s == variant[key]);
     }
 #endif
 
@@ -122,7 +124,7 @@ TEST_CASE("unsigned char[]") {
       deserializeJson(doc, "{\"hello\":\"world\"}");
       const JsonVariant variant = doc.as<JsonVariant>();
 
-      REQUIRE(std::string("world") == variant[key]);
+      REQUIRE("world"_s == variant[key]);
     }
 #endif
 
@@ -160,7 +162,7 @@ TEST_CASE("unsigned char[]") {
       JsonObject obj = doc.to<JsonObject>();
       obj[key] = "world";
 
-      REQUIRE(std::string("world") == obj["hello"]);
+      REQUIRE("world"_s == obj["hello"]);
     }
 
     SECTION("JsonObject::operator[] const") {
@@ -170,7 +172,7 @@ TEST_CASE("unsigned char[]") {
       deserializeJson(doc, "{\"hello\":\"world\"}");
 
       JsonObject obj = doc.as<JsonObject>();
-      REQUIRE(std::string("world") == obj[key]);
+      REQUIRE("world"_s == obj[key]);
     }
 #endif
 
@@ -203,7 +205,7 @@ TEST_CASE("unsigned char[]") {
       JsonObject obj = doc.to<JsonObject>();
       obj["hello"] = value;
 
-      REQUIRE(std::string("world") == obj["hello"]);
+      REQUIRE("world"_s == obj["hello"]);
     }
 
     SECTION("set()") {
@@ -213,7 +215,7 @@ TEST_CASE("unsigned char[]") {
       JsonObject obj = doc.to<JsonObject>();
       obj["hello"].set(value);
 
-      REQUIRE(std::string("world") == obj["hello"]);
+      REQUIRE("world"_s == obj["hello"]);
     }
   }
 
@@ -225,7 +227,7 @@ TEST_CASE("unsigned char[]") {
       JsonArray arr = doc.to<JsonArray>();
       arr.add(value);
 
-      REQUIRE(std::string("world") == arr[0]);
+      REQUIRE("world"_s == arr[0]);
     }
   }
 
@@ -238,7 +240,7 @@ TEST_CASE("unsigned char[]") {
       arr.add("hello");
       arr[0].set(value);
 
-      REQUIRE(std::string("world") == arr[0]);
+      REQUIRE("world"_s == arr[0]);
     }
 
     SECTION("operator=") {
@@ -249,7 +251,7 @@ TEST_CASE("unsigned char[]") {
       arr.add("hello");
       arr[0] = value;
 
-      REQUIRE(std::string("world") == arr[0]);
+      REQUIRE("world"_s == arr[0]);
     }
   }
 }

+ 3 - 1
extras/tests/MixedConfiguration/string_length_size_1.cpp

@@ -4,6 +4,8 @@
 #include <catch.hpp>
 #include <string>
 
+#include "Literals.hpp"
+
 TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") {
   JsonDocument doc;
 
@@ -87,7 +89,7 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") {
     }
 
     SECTION("returns NoMemory if string length >= 256") {
-      auto input = std::string("\xda\x01\x00", 3) + std::string(256, '?');
+      auto input = "\xda\x01\x00"_s + std::string(256, '?');
 
       auto err = deserializeMsgPack(doc, input);
 

+ 3 - 2
extras/tests/MixedConfiguration/string_length_size_2.cpp

@@ -4,6 +4,8 @@
 #include <catch.hpp>
 #include <string>
 
+#include "Literals.hpp"
+
 TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") {
   JsonDocument doc;
 
@@ -87,8 +89,7 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") {
     }
 
     SECTION("returns NoMemory if string length >= 65536") {
-      auto input =
-          std::string("\xdb\x00\x01\x00\x00", 5) + std::string(65536, '?');
+      auto input = "\xdb\x00\x01\x00\x00"_s + std::string(65536, '?');
 
       auto err = deserializeMsgPack(doc, input);
 

+ 6 - 4
extras/tests/MixedConfiguration/string_length_size_4.cpp

@@ -4,6 +4,8 @@
 #include <catch.hpp>
 #include <string>
 
+#include "Literals.hpp"
+
 TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") {
   JsonDocument doc;
 
@@ -74,7 +76,7 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") {
 
   SECTION("bin 32 deserialization") {
     auto str = std::string(65536, '?');
-    auto input = std::string("\xc6\x00\x01\x00\x00", 5) + str;
+    auto input = "\xc6\x00\x01\x00\x00"_s + str;
 
     auto err = deserializeMsgPack(doc, input);
 
@@ -95,12 +97,12 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") {
     auto result = serializeMsgPack(doc, output);
 
     REQUIRE(result == 5 + str.size());
-    REQUIRE(output == std::string("\xc6\x00\x01\x00\x00", 5) + str);
+    REQUIRE(output == "\xc6\x00\x01\x00\x00"_s + str);
   }
 
   SECTION("ext 32 deserialization") {
     auto str = std::string(65536, '?');
-    auto input = std::string("\xc9\x00\x01\x00\x00\x2a", 6) + str;
+    auto input = "\xc9\x00\x01\x00\x00\x2a"_s + str;
 
     auto err = deserializeMsgPack(doc, input);
 
@@ -122,6 +124,6 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") {
     auto result = serializeMsgPack(doc, output);
 
     REQUIRE(result == 6 + str.size());
-    REQUIRE(output == std::string("\xc9\x00\x01\x00\x00\x2a", 6) + str);
+    REQUIRE(output == "\xc9\x00\x01\x00\x00\x2a"_s + str);
   }
 }

+ 7 - 6
extras/tests/MsgPackDeserializer/deserializeVariant.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 template <typename T>
 static void checkValue(const char* input, T expected) {
@@ -123,21 +124,21 @@ TEST_CASE("deserialize MsgPack value") {
 
   SECTION("fixstr") {
     checkValue<std::string>("\xA0", std::string(""));
-    checkValue<std::string>("\xABhello world", std::string("hello world"));
+    checkValue<std::string>("\xABhello world", "hello world"_s);
     checkValue<std::string>("\xBFhello world hello world hello !",
-                            std::string("hello world hello world hello !"));
+                            "hello world hello world hello !"_s);
   }
 
   SECTION("str 8") {
-    checkValue<std::string>("\xd9\x05hello", std::string("hello"));
+    checkValue<std::string>("\xd9\x05hello", "hello"_s);
   }
 
   SECTION("str 16") {
-    checkValue<std::string>("\xda\x00\x05hello", std::string("hello"));
+    checkValue<std::string>("\xda\x00\x05hello", "hello"_s);
   }
 
   SECTION("str 32") {
-    checkValue<std::string>("\xdb\x00\x00\x00\x05hello", std::string("hello"));
+    checkValue<std::string>("\xdb\x00\x00\x00\x05hello", "hello"_s);
   }
 
   SECTION("bin 8") {
@@ -156,7 +157,7 @@ TEST_CASE("deserialize MsgPack value") {
   SECTION("bin 16") {
     JsonDocument doc;
     auto str = std::string(256, '?');
-    auto input = std::string("\xc5\x01\x00", 3) + str;
+    auto input = "\xc5\x01\x00"_s + str;
 
     DeserializationError error = deserializeMsgPack(doc, input);
 

+ 5 - 4
extras/tests/MsgPackDeserializer/destination_types.cpp

@@ -8,6 +8,7 @@
 #include <string>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofArray;
 using ArduinoJson::detail::sizeofObject;
@@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject;
 TEST_CASE("deserializeMsgPack(JsonDocument&)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc.add(std::string("hello"));
+  doc.add("hello"_s);
   spy.clearLog();
 
   auto err = deserializeMsgPack(doc, "\x91\x2A");
@@ -34,7 +35,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
   SECTION("variant is bound") {
     SpyingAllocator spy;
     JsonDocument doc(&spy);
-    doc.add(std::string("hello"));
+    doc.add("hello"_s);
     spy.clearLog();
 
     JsonVariant variant = doc[0];
@@ -60,7 +61,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
 TEST_CASE("deserializeMsgPack(ElementProxy)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc.add(std::string("hello"));
+  doc.add("hello"_s);
   spy.clearLog();
 
   SECTION("element already exists") {
@@ -85,7 +86,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
 TEST_CASE("deserializeMsgPack(MemberProxy)") {
   SpyingAllocator spy;
   JsonDocument doc(&spy);
-  doc[std::string("hello")] = std::string("world");
+  doc["hello"_s] = "world"_s;
   spy.clearLog();
 
   SECTION("member already exists") {

+ 4 - 3
extras/tests/MsgPackDeserializer/filter.cpp

@@ -8,6 +8,7 @@
 #include <sstream>
 
 #include "Allocators.hpp"
+#include "Literals.hpp"
 
 using namespace ArduinoJson::detail;
 
@@ -1552,7 +1553,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, Filter") {
-    deserializeMsgPack(doc, std::string("{}"), Filter(filter));
+    deserializeMsgPack(doc, "{}"_s, Filter(filter));
   }
 
   SECTION("std::istream&, Filter") {
@@ -1580,7 +1581,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, Filter, NestingLimit") {
-    deserializeMsgPack(doc, std::string("{}"), Filter(filter), NestingLimit(5));
+    deserializeMsgPack(doc, "{}"_s, Filter(filter), NestingLimit(5));
   }
 
   SECTION("std::istream&, Filter, NestingLimit") {
@@ -1608,7 +1609,7 @@ TEST_CASE("Overloads") {
   }
 
   SECTION("const std::string&, NestingLimit, Filter") {
-    deserializeMsgPack(doc, std::string("{}"), NestingLimit(5), Filter(filter));
+    deserializeMsgPack(doc, "{}"_s, NestingLimit(5), Filter(filter));
   }
 
   SECTION("std::istream&, NestingLimit, Filter") {

+ 5 - 6
extras/tests/MsgPackDeserializer/input_types.cpp

@@ -6,6 +6,7 @@
 #include <catch.hpp>
 
 #include "CustomReader.hpp"
+#include "Literals.hpp"
 
 using ArduinoJson::detail::sizeofObject;
 
@@ -21,8 +22,7 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
   }
 
   SECTION("should accept temporary string") {
-    DeserializationError err =
-        deserializeMsgPack(doc, std::string("\x92\x01\x02"));
+    DeserializationError err = deserializeMsgPack(doc, "\x92\x01\x02"_s);
 
     REQUIRE(err == DeserializationError::Ok);
   }
@@ -35,12 +35,11 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
 
     JsonArray array = doc.as<JsonArray>();
     REQUIRE(err == DeserializationError::Ok);
-    REQUIRE(std::string("hello") == array[0]);
+    REQUIRE("hello"_s == array[0]);
   }
 
   SECTION("should accept a zero in input") {
-    DeserializationError err =
-        deserializeMsgPack(doc, std::string("\x92\x00\x02", 3));
+    DeserializationError err = deserializeMsgPack(doc, "\x92\x00\x02"_s);
 
     REQUIRE(err == DeserializationError::Ok);
     JsonArray arr = doc.as<JsonArray>();
@@ -53,7 +52,7 @@ TEST_CASE("deserializeMsgPack(std::istream&)") {
   JsonDocument doc;
 
   SECTION("should accept a zero in input") {
-    std::istringstream input(std::string("\x92\x00\x02", 3));
+    std::istringstream input("\x92\x00\x02"_s);
 
     DeserializationError err = deserializeMsgPack(doc, input);
 

+ 3 - 2
extras/tests/MsgPackSerializer/serializeArray.cpp

@@ -7,6 +7,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 static void check(const JsonArray array, const char* expected_data,
                   size_t expected_len) {
   std::string expected(expected_data, expected_data + expected_len);
@@ -57,7 +59,6 @@ TEST_CASE("serialize MsgPack array") {
       array.add(nil);
     REQUIRE(array.size() == 65536);
 
-    check(array,
-          std::string("\xDD\x00\x01\x00\x00", 5) + std::string(65536, '\xc0'));
+    check(array, "\xDD\x00\x01\x00\x00"_s + std::string(65536, '\xc0'));
   }
 }

+ 3 - 1
extras/tests/MsgPackSerializer/serializeObject.cpp

@@ -6,6 +6,8 @@
 #include <stdio.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 static void check(const JsonObject object, const char* expected_data,
                   size_t expected_len) {
   std::string expected(expected_data, expected_data + expected_len);
@@ -77,7 +79,7 @@ TEST_CASE("serialize MsgPack object") {
   }
 
   SECTION("serialized(std::string)") {
-    object["hello"] = serialized(std::string("\xDB\x00\x01\x00\x00", 5));
+    object["hello"] = serialized("\xDB\x00\x01\x00\x00"_s);
     check(object, "\x81\xA5hello\xDB\x00\x01\x00\x00");
   }
 }

+ 7 - 7
extras/tests/MsgPackSerializer/serializeVariant.cpp

@@ -5,6 +5,8 @@
 #include <ArduinoJson.h>
 #include <catch.hpp>
 
+#include "Literals.hpp"
+
 template <typename T>
 static void checkVariant(T value, const char* expected_data,
                          size_t expected_len) {
@@ -129,16 +131,15 @@ TEST_CASE("serialize MsgPack value") {
 
   SECTION("str 16") {
     std::string shortest(256, '?');
-    checkVariant(shortest.c_str(), std::string("\xDA\x01\x00", 3) + shortest);
+    checkVariant(shortest.c_str(), "\xDA\x01\x00"_s + shortest);
 
     std::string longest(65535, '?');
-    checkVariant(longest.c_str(), std::string("\xDA\xFF\xFF", 3) + longest);
+    checkVariant(longest.c_str(), "\xDA\xFF\xFF"_s + longest);
   }
 
   SECTION("str 32") {
     std::string shortest(65536, '?');
-    checkVariant(shortest.c_str(),
-                 std::string("\xDB\x00\x01\x00\x00", 5) + shortest);
+    checkVariant(shortest.c_str(), "\xDB\x00\x01\x00\x00"_s + shortest);
   }
 
   SECTION("serialized(const char*)") {
@@ -152,8 +153,7 @@ TEST_CASE("serialize MsgPack value") {
 
   SECTION("bin 16") {
     auto str = std::string(256, '?');
-    checkVariant(MsgPackBinary(str.data(), str.size()),
-                 std::string("\xC5\x01\x00", 3) + str);
+    checkVariant(MsgPackBinary(str.data(), str.size()), "\xC5\x01\x00"_s + str);
   }
 
   // bin 32 is tested in string_length_size_4.cpp
@@ -194,7 +194,7 @@ TEST_CASE("serialize MsgPack value") {
   SECTION("ext 16") {
     auto str = std::string(256, '?');
     checkVariant(MsgPackExtension(2, str.data(), str.size()),
-                 std::string("\xC8\x01\x00\x02", 4) + str);
+                 "\xC8\x01\x00\x02"_s + str);
   }
 
   SECTION("serialize round double as integer") {  // Issue #1718