mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Moved ancillary files to extras/ (fixes #1011)
				
					
				
			This commit is contained in:
		
							
								
								
									
										61
									
								
								extras/tests/TextFormatter/writeString.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								extras/tests/TextFormatter/writeString.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| // ArduinoJson - arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2019 | ||||
| // MIT License | ||||
|  | ||||
| #include <catch.hpp> | ||||
|  | ||||
| #include <ArduinoJson/Json/TextFormatter.hpp> | ||||
| #include <ArduinoJson/Serialization/StaticStringWriter.hpp> | ||||
|  | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| void check(const char* input, std::string expected) { | ||||
|   char output[1024]; | ||||
|   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("Null") { | ||||
|     check(0, "null"); | ||||
|   } | ||||
|  | ||||
|   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\""); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user