enable_comments_0.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #define ARDUINOJSON_ENABLE_COMMENTS 0
  5. #include <ArduinoJson.h>
  6. #include <catch.hpp>
  7. TEST_CASE("Comments should produce InvalidInput") {
  8. DynamicJsonDocument doc(2048);
  9. const char* testCases[] = {
  10. "/*COMMENT*/ [\"hello\"]",
  11. "[/*COMMENT*/ \"hello\"]",
  12. "[\"hello\"/*COMMENT*/]",
  13. "[\"hello\"/*COMMENT*/,\"world\"]",
  14. "[\"hello\",/*COMMENT*/ \"world\"]",
  15. "[/*/\n]",
  16. "[/*COMMENT]",
  17. "[/*COMMENT*]",
  18. "//COMMENT\n\t[\"hello\"]",
  19. "[//COMMENT\n\"hello\"]",
  20. "[\"hello\"//COMMENT\r\n]",
  21. "[\"hello\"//COMMENT\n,\"world\"]",
  22. "[\"hello\",//COMMENT\n\"world\"]",
  23. "[/COMMENT\n]",
  24. "[//COMMENT",
  25. "/*COMMENT*/ {\"hello\":\"world\"}",
  26. "{/*COMMENT*/\"hello\":\"world\"}",
  27. "{\"hello\"/*COMMENT*/:\"world\"}",
  28. "{\"hello\":/*COMMENT*/\"world\"}",
  29. "{\"hello\":\"world\"/*COMMENT*/}",
  30. "//COMMENT\n {\"hello\":\"world\"}",
  31. "{//COMMENT\n\"hello\":\"world\"}",
  32. "{\"hello\"//COMMENT\n:\"world\"}",
  33. "{\"hello\"://COMMENT\n\"world\"}",
  34. "{\"hello\":\"world\"//COMMENT\n}",
  35. "/{\"hello\":\"world\"}",
  36. "{/\"hello\":\"world\"}",
  37. "{\"hello\"/:\"world\"}",
  38. "{\"hello\":/\"world\"}",
  39. "{\"hello\":\"world\"/}",
  40. "{\"hello\":\"world\"/,\"answer\":42}",
  41. "{\"hello\":\"world\",/\"answer\":42}",
  42. };
  43. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  44. for (size_t i = 0; i < testCount; i++) {
  45. const char* input = testCases[i];
  46. CAPTURE(input);
  47. REQUIRE(deserializeJson(doc, input) == DeserializationError::InvalidInput);
  48. }
  49. }