| 
									
										
										
										
											2021-03-29 17:14:01 +02:00
										 |  |  | // ArduinoJson - https://arduinojson.org
 | 
					
						
							| 
									
										
										
										
											2024-01-03 08:47:06 +01:00
										 |  |  | // Copyright © 2014-2024, Benoit BLANCHON
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:55:51 +01:00
										 |  |  | // MIT License
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <ArduinoJson.h>
 | 
					
						
							|  |  |  | #include <catch.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("JsonObject::nesting()") { | 
					
						
							| 
									
										
										
										
											2023-07-17 18:15:13 +02:00
										 |  |  |   JsonDocument doc; | 
					
						
							| 
									
										
										
										
											2019-01-17 09:55:51 +01:00
										 |  |  |   JsonObject obj = doc.to<JsonObject>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("return 0 if uninitialized") { | 
					
						
							|  |  |  |     JsonObject unitialized; | 
					
						
							|  |  |  |     REQUIRE(unitialized.nesting() == 0); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns 1 for empty object") { | 
					
						
							|  |  |  |     REQUIRE(obj.nesting() == 1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns 1 for flat object") { | 
					
						
							|  |  |  |     obj["hello"] = "world"; | 
					
						
							|  |  |  |     REQUIRE(obj.nesting() == 1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns 2 with nested array") { | 
					
						
							| 
									
										
										
										
											2023-08-09 11:31:29 +02:00
										 |  |  |     obj["nested"].to<JsonArray>(); | 
					
						
							| 
									
										
										
										
											2019-01-17 09:55:51 +01:00
										 |  |  |     REQUIRE(obj.nesting() == 2); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns 2 with nested object") { | 
					
						
							| 
									
										
										
										
											2023-08-09 11:31:29 +02:00
										 |  |  |     obj["nested"].to<JsonObject>(); | 
					
						
							| 
									
										
										
										
											2019-01-17 09:55:51 +01:00
										 |  |  |     REQUIRE(obj.nesting() == 2); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |