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

This commit is contained in:
Benoit Blanchon
2024-06-07 09:35:45 +02:00
parent 5b88b2c1f6
commit 45611924f3
55 changed files with 316 additions and 229 deletions

View File

@ -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