mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 00:32:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // ArduinoJson - https://arduinojson.org
 | |
| // Copyright © 2014-2022, Benoit BLANCHON
 | |
| // MIT License
 | |
| 
 | |
| #include <catch.hpp>
 | |
| 
 | |
| #include <ArduinoJson/Json/TextFormatter.hpp>
 | |
| #include <ArduinoJson/Serialization/Writers/StaticStringWriter.hpp>
 | |
| 
 | |
| using namespace ArduinoJson::detail;
 | |
| 
 | |
| void check(const char* input, std::string expected) {
 | |
|   char output[64] = {0};
 | |
|   StaticStringWriter sb(output, sizeof(output));
 | |
|   TextFormatter<StaticStringWriter> writer(sb);
 | |
|   writer.writeString(input);
 | |
|   REQUIRE(expected == output);
 | |
|   REQUIRE(writer.bytesWritten() == expected.size());
 | |
| }
 | |
| 
 | |
| TEST_CASE("TextFormatter::writeString()") {
 | |
|   SECTION("EmptyString") {
 | |
|     check("", "\"\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("QuotationMark") {
 | |
|     check("\"", "\"\\\"\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("ReverseSolidus") {
 | |
|     check("\\", "\"\\\\\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("Solidus") {
 | |
|     check("/", "\"/\"");  // but the JSON format allows \/
 | |
|   }
 | |
| 
 | |
|   SECTION("Backspace") {
 | |
|     check("\b", "\"\\b\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("Formfeed") {
 | |
|     check("\f", "\"\\f\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("Newline") {
 | |
|     check("\n", "\"\\n\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("CarriageReturn") {
 | |
|     check("\r", "\"\\r\"");
 | |
|   }
 | |
| 
 | |
|   SECTION("HorizontalTab") {
 | |
|     check("\t", "\"\\t\"");
 | |
|   }
 | |
| }
 |