diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index 80236af..6136307 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -198,5 +198,33 @@ TEST(NodeTest, ParseNodeStyle) { EXPECT_EQ(EmitterStyle::Block, Load("- foo\n- bar").Style()); EXPECT_EQ(EmitterStyle::Block, Load("foo: bar").Style()); } + +struct ParserExceptionTestCase { + std::string name; + std::string input; + std::string expected_exception; +}; + +TEST(NodeTest, IncompleteJson) { + std::vector tests = { + {"JSON map without value", "{\"access\"", ErrorMsg::END_OF_MAP_FLOW}, + {"JSON map with colon but no value", "{\"access\":", + ErrorMsg::END_OF_MAP_FLOW}, + {"JSON map with unclosed value quote", "{\"access\":\"", + ErrorMsg::END_OF_MAP_FLOW}, + {"JSON map without end brace", "{\"access\":\"abc\"", + ErrorMsg::END_OF_MAP_FLOW}, + }; + for (const ParserExceptionTestCase test : tests) { + try { + Load(test.input); + FAIL() << "Expected exception " << test.expected_exception << " for " + << test.name << ", input: " << test.input; + } catch (const ParserException& e) { + EXPECT_EQ(test.expected_exception, e.msg); + } + } } -} + +} // namespace +} // namespace YAML