@@ -265,6 +265,52 @@ TEST(NodeTest, IncompleteJson) {
265265 }
266266}
267267
268+ struct SingleNodeTestCase {
269+ std::string input;
270+ NodeType::value nodeType;
271+ int nodeSize;
272+ std::string expected_content;
273+ };
274+
275+ TEST (NodeTest, SpecialFlow) {
276+ std::vector<SingleNodeTestCase> tests = {
277+ {" [:]" , NodeType::Sequence, 1 , " [{~: ~}]" },
278+ {" [a:]" , NodeType::Sequence, 1 , " [{a: ~}]" },
279+ {" [:a]" , NodeType::Sequence, 1 , " [:a]" },
280+ {" [,]" , NodeType::Sequence, 1 , " [~]" },
281+ {" [a:,]" , NodeType::Sequence, 1 , " [{a: ~}]" },
282+ {" {:}" , NodeType::Map, 1 , " {~: ~}" },
283+ {" {a:}" , NodeType::Map, 1 , " {a: ~}" },
284+ {" {:a}" , NodeType::Map, 1 , " {:a: ~}" },
285+ {" {,}" , NodeType::Map, 1 , " {~: ~}" },
286+ {" {a:,}" , NodeType::Map, 1 , " {a: ~}" },
287+ };
288+ for (const SingleNodeTestCase& test : tests) {
289+ Node node = Load (test.input );
290+ Emitter emitter;
291+ emitter << node;
292+ EXPECT_EQ (test.nodeType , node.Type ());
293+ EXPECT_EQ (test.nodeSize , node.size ());
294+ EXPECT_EQ (test.expected_content , std::string (emitter.c_str ()));
295+ }
296+ }
297+
298+ TEST (NodeTest, IncorrectFlow) {
299+ std::vector<ParserExceptionTestCase> tests = {
300+ {" Incorrect yaml: \" {:]\" " , " {:]" , ErrorMsg::FLOW_END},
301+ {" Incorrect yaml: \" [:}\" " , " [:}" , ErrorMsg::FLOW_END},
302+ };
303+ for (const ParserExceptionTestCase test : tests) {
304+ try {
305+ Load (test.input );
306+ FAIL () << " Expected exception " << test.expected_exception << " for "
307+ << test.name << " , input: " << test.input ;
308+ } catch (const ParserException& e) {
309+ EXPECT_EQ (test.expected_exception , e.msg );
310+ }
311+ }
312+ }
313+
268314TEST (NodeTest, LoadTildeAsNull) {
269315 Node node = Load (" ~" );
270316 ASSERT_TRUE (node.IsNull ());
0 commit comments