The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

76 lines
2.6 KiB

2 months ago
  1. #include "handler_test.h"
  2. #include "specexamples.h" // IWYU pragma: keep
  3. #include "yaml-cpp/yaml.h" // IWYU pragma: keep
  4. #include "gmock/gmock.h"
  5. #include "gtest/gtest.h"
  6. using ::testing::_;
  7. #define EXPECT_THROW_PARSER_EXCEPTION(statement, message) \
  8. ASSERT_THROW(statement, ParserException); \
  9. try { \
  10. statement; \
  11. } catch (const ParserException& e) { \
  12. EXPECT_EQ(e.msg, message); \
  13. }
  14. namespace YAML {
  15. namespace {
  16. TEST_F(HandlerTest, NoEndOfMapFlow) {
  17. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse("---{header: {id: 1"),
  18. ErrorMsg::END_OF_MAP_FLOW);
  19. }
  20. TEST_F(HandlerTest, PlainScalarStartingWithQuestionMark) {
  21. EXPECT_CALL(handler, OnDocumentStart(_));
  22. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  23. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  24. EXPECT_CALL(handler, OnScalar(_, "?", 0, "?bar"));
  25. EXPECT_CALL(handler, OnMapEnd());
  26. EXPECT_CALL(handler, OnDocumentEnd());
  27. Parse("foo: ?bar");
  28. }
  29. TEST_F(HandlerTest, NullStringScalar) {
  30. EXPECT_CALL(handler, OnDocumentStart(_));
  31. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  32. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  33. EXPECT_CALL(handler, OnNull(_, 0));
  34. EXPECT_CALL(handler, OnMapEnd());
  35. EXPECT_CALL(handler, OnDocumentEnd());
  36. Parse("foo: null");
  37. }
  38. TEST_F(HandlerTest, CommentOnNewlineOfMapValueWithNoSpaces) {
  39. EXPECT_CALL(handler, OnDocumentStart(_));
  40. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  41. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  42. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  43. EXPECT_CALL(handler, OnMapEnd());
  44. EXPECT_CALL(handler, OnDocumentEnd());
  45. Parse("key: value\n# comment");
  46. }
  47. TEST_F(HandlerTest, CommentOnNewlineOfMapValueWithOneSpace) {
  48. EXPECT_CALL(handler, OnDocumentStart(_));
  49. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  50. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  51. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  52. EXPECT_CALL(handler, OnMapEnd());
  53. EXPECT_CALL(handler, OnDocumentEnd());
  54. Parse("key: value\n # comment");
  55. }
  56. TEST_F(HandlerTest, CommentOnNewlineOfMapValueWithManySpace) {
  57. EXPECT_CALL(handler, OnDocumentStart(_));
  58. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  59. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  60. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  61. EXPECT_CALL(handler, OnMapEnd());
  62. EXPECT_CALL(handler, OnDocumentEnd());
  63. Parse("key: value\n # comment");
  64. }
  65. } // namespace
  66. } // namespace YAML