mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added JsonArray::clear() (fixes #1597)
This commit is contained in:
		| @@ -4,6 +4,7 @@ | ||||
|  | ||||
| add_executable(JsonArrayTests  | ||||
| 	add.cpp | ||||
| 	clear.cpp | ||||
| 	copyArray.cpp | ||||
| 	createNested.cpp | ||||
| 	equals.cpp | ||||
|   | ||||
							
								
								
									
										25
									
								
								extras/tests/JsonArray/clear.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								extras/tests/JsonArray/clear.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| // ArduinoJson - https://arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2021 | ||||
| // MIT License | ||||
|  | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| TEST_CASE("JsonArray::clear()") { | ||||
|   SECTION("No-op on null JsonArray") { | ||||
|     JsonArray array; | ||||
|     array.clear(); | ||||
|     REQUIRE(array.isNull() == true); | ||||
|     REQUIRE(array.size() == 0); | ||||
|   } | ||||
|  | ||||
|   SECTION("Removes all elements") { | ||||
|     StaticJsonDocument<64> doc; | ||||
|     JsonArray array = doc.to<JsonArray>(); | ||||
|     array.add(1); | ||||
|     array.add(2); | ||||
|     array.clear(); | ||||
|     REQUIRE(array.size() == 0); | ||||
|     REQUIRE(array.isNull() == false); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user