mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fix size()
This commit is contained in:
		| @@ -51,3 +51,24 @@ TEST_CASE("JsonVariant::link()") { | ||||
|     CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}"); | ||||
|   } | ||||
| } | ||||
|  | ||||
| TEST_CASE("Linked document") { | ||||
|   StaticJsonDocument<1024> doc1, doc2; | ||||
|   JsonVariant variant = doc1.to<JsonVariant>(); | ||||
|   doc2["hello"] = "world"; | ||||
|   variant.link(doc2); | ||||
|  | ||||
|   // TODO: move in size.cpp | ||||
|   SECTION("size()") { | ||||
|     CHECK(doc1.size() == 1); | ||||
|   } | ||||
|  | ||||
|   SECTION("is<T>()") { | ||||
|     CHECK(doc1.is<JsonObject>() == true); | ||||
|     CHECK(doc1.is<JsonArray>() == false); | ||||
|   } | ||||
|  | ||||
|   SECTION("get member") { | ||||
|     CHECK(doc1["hello"].as<std::string>() == "world"); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -117,6 +117,10 @@ class VariantData { | ||||
|     return (_flags & COLLECTION_MASK) != 0; | ||||
|   } | ||||
|  | ||||
|   bool isPointer() const { | ||||
|     return type() == VALUE_IS_POINTER; | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   bool isInteger() const { | ||||
|     switch (type()) { | ||||
| @@ -259,7 +263,9 @@ class VariantData { | ||||
|   } | ||||
|  | ||||
|   size_t size() const { | ||||
|     return isCollection() ? _content.asCollection.size() : 0; | ||||
|     return isPointer()      ? _content.asPointer->size() | ||||
|            : isCollection() ? _content.asCollection.size() | ||||
|                             : 0; | ||||
|   } | ||||
|  | ||||
|   VariantData *addElement(MemoryPool *pool) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user