mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			701 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			701 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| // ArduinoJson - https://arduinojson.org
 | |
| // Copyright © 2014-2022, Benoit BLANCHON
 | |
| // MIT License
 | |
| 
 | |
| #include <ArduinoJson.h>
 | |
| #include <catch.hpp>
 | |
| 
 | |
| static void eraseString(std::string& str) {
 | |
|   char* p = const_cast<char*>(str.c_str());
 | |
|   while (*p)
 | |
|     *p++ = '*';
 | |
| }
 | |
| 
 | |
| TEST_CASE("std::string") {
 | |
|   DynamicJsonDocument doc(4096);
 | |
|   JsonArray array = doc.to<JsonArray>();
 | |
| 
 | |
|   SECTION("add()") {
 | |
|     std::string value("hello");
 | |
|     array.add(value);
 | |
|     eraseString(value);
 | |
|     REQUIRE(std::string("hello") == array[0]);
 | |
|   }
 | |
| 
 | |
|   SECTION("operator[]") {
 | |
|     std::string value("world");
 | |
|     array.add("hello");
 | |
|     array[0] = value;
 | |
|     eraseString(value);
 | |
|     REQUIRE(std::string("world") == array[0]);
 | |
|   }
 | |
| }
 |