Changed the rules of string duplication (fixes #658)

This commit is contained in:
Benoit Blanchon
2018-01-14 13:46:28 +01:00
parent 5c33fd4b94
commit e92612b511
22 changed files with 416 additions and 224 deletions

View File

@ -9,11 +9,6 @@ TEST_CASE("JsonArray::add()") {
DynamicJsonBuffer _jsonBuffer;
JsonArray& _array = _jsonBuffer.createArray();
SECTION("SizeIncreased_WhenValuesAreAdded") {
_array.add("hello");
REQUIRE(1U == _array.size());
}
SECTION("int") {
_array.add(123);
REQUIRE(123 == _array[0].as<int>());
@ -38,7 +33,7 @@ TEST_CASE("JsonArray::add()") {
SECTION("const char*") {
const char* str = "hello";
_array.add(str);
REQUIRE(str == _array[0].as<const char*>());
REQUIRE(str == _array[0].as<std::string>());
REQUIRE(_array[0].is<const char*>());
REQUIRE_FALSE(_array[0].is<int>());
}
@ -82,4 +77,22 @@ TEST_CASE("JsonArray::add()") {
REQUIRE(str == _array[0]);
}
SECTION("should not duplicate const char*") {
_array.add("world");
const size_t expectedSize = JSON_ARRAY_SIZE(1);
REQUIRE(expectedSize == _jsonBuffer.size());
}
SECTION("should duplicate char*") {
_array.add(const_cast<char*>("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
REQUIRE(expectedSize == _jsonBuffer.size());
}
SECTION("should duplicate std::string") {
_array.add(std::string("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
REQUIRE(expectedSize == _jsonBuffer.size());
}
}