| 
									
										
										
										
											2021-03-29 17:14:01 +02:00
										 |  |  | // ArduinoJson - https://arduinojson.org
 | 
					
						
							| 
									
										
										
										
											2023-02-16 11:45:01 +01:00
										 |  |  | // Copyright © 2014-2023, Benoit BLANCHON
 | 
					
						
							| 
									
										
										
										
											2019-03-22 08:40:46 +01:00
										 |  |  | // MIT License
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <ArduinoJson.h>
 | 
					
						
							|  |  |  | #include <catch.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("JsonDocument::containsKey()") { | 
					
						
							| 
									
										
										
										
											2023-03-20 10:49:01 +01:00
										 |  |  |   JsonDocument doc(4096); | 
					
						
							| 
									
										
										
										
											2019-03-22 08:40:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns true on object") { | 
					
						
							|  |  |  |     doc["hello"] = "world"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey("hello") == true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns true when value is null") { | 
					
						
							|  |  |  |     doc["hello"] = static_cast<const char*>(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey("hello") == true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns true when key is a std::string") { | 
					
						
							|  |  |  |     doc["hello"] = "world"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey(std::string("hello")) == true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns false  on object") { | 
					
						
							|  |  |  |     doc["world"] = "hello"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey("hello") == false); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns false on array") { | 
					
						
							|  |  |  |     doc.add("hello"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey("hello") == false); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   SECTION("returns false on null") { | 
					
						
							|  |  |  |     REQUIRE(doc.containsKey("hello") == false); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |