| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
- #include "CppUnitTest.h"
- #include "JsonParser.h"
- using namespace Microsoft::VisualStudio::CppUnitTestFramework;
- using namespace ArduinoJson::Parser;
- namespace ArduinoJsonParserTests
- {
- TEST_CLASS(JsonStringTests)
- {
- const char* actual;
- char json[256];
- JsonParser<32> parser;
- public:
- TEST_METHOD(EmptyString)
- {
- whenInputIs("");
- outputMustBe(0);
- }
- TEST_METHOD(JustOneQuote)
- {
- whenInputIs("\"");
- outputMustBe(0);
- }
- TEST_METHOD(SimpleString)
- {
- whenInputIs("\"Hi!\"");
- outputMustBe("Hi!");
- }
- TEST_METHOD(EscapedQuote)
- {
- whenInputIs("\"12\\\"34\""); // ie 12\"34
- outputMustBe("12\"34");
- }
- TEST_METHOD(EscapedReverseSolidus)
- {
- whenInputIs("\"12\\\\34\""); // ie 12\\34
- outputMustBe("12\\34");
- }
- TEST_METHOD(EscapedSolidus)
- {
- whenInputIs("\"12\\/34\"");
- outputMustBe("12/34");
- }
- TEST_METHOD(EscapedBackspace)
- {
- whenInputIs("\"12\\b34\"");
- outputMustBe("12\b34");
- }
- TEST_METHOD(EscapedFormfeed)
- {
- whenInputIs("\"12\\f34\"");
- outputMustBe("12\f34");
- }
-
- TEST_METHOD(EscapedNewline)
- {
- whenInputIs("\"12\\n34\"");
- outputMustBe("12\n34");
- }
- TEST_METHOD(EscapedCarriageReturn)
- {
- whenInputIs("\"12\\r34\"");
- outputMustBe("12\r34");
- }
- TEST_METHOD(EscapedTab)
- {
- whenInputIs("\"12\\t34\"");
- outputMustBe("12\t34");
- }
- TEST_METHOD(AllEscapedCharsTogether)
- {
- whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
- outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
- }
- private:
- void whenInputIs(const char* input)
- {
- strcpy(json, input);
- actual = parser.parse(json);
- }
- void outputMustBe(const char* expected)
- {
- Assert::AreEqual(expected, actual);
- }
- };
- }
|