From 1b240d3576882383949996e6b7a85f1cc62029bb Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Wed, 26 Aug 2009 16:15:27 +0000 Subject: [PATCH] Fixed bug with explicit doc start introduced in last commit --- src/scanner.cpp | 9 +++++-- yaml-reader/parsertests.cpp | 48 +++++++++++++++++++++++++++++++++++++ yaml-reader/tests.cpp | 2 ++ yaml-reader/tests.h | 2 ++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/scanner.cpp b/src/scanner.cpp index 83a16fb..7429084 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -294,7 +294,7 @@ namespace YAML } // PopAllIndents - // . Pops all indentations off the stack, + // . Pops all indentations (except for the base empty one) off the stack, // and enqueues the proper token each time. void Scanner::PopAllIndents() { @@ -303,8 +303,13 @@ namespace YAML return; // now pop away - while(!m_indents.empty()) + while(!m_indents.empty()) { + const IndentMarker& indent = m_indents.top(); + if(indent.type == IndentMarker::NONE) + break; + PopIndent(); + } } // PopIndent diff --git a/yaml-reader/parsertests.cpp b/yaml-reader/parsertests.cpp index 03c833e..d0342e2 100644 --- a/yaml-reader/parsertests.cpp +++ b/yaml-reader/parsertests.cpp @@ -370,5 +370,53 @@ namespace Test return true; } + + bool ExplicitDoc() + { + std::string input = "---\n- one\n- two"; + + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + if(doc.size() != 2) + return false; + + std::string output; + doc[0] >> output; + if(output != "one") + return false; + doc[1] >> output; + if(output != "two") + return false; + + return true; + } + + bool MultipleDocs() + { + std::string input = "---\nname: doc1\n---\nname: doc2"; + + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + std::string output; + doc["name"] >> output; + if(output != "doc1") + return false; + + if(!parser) + return false; + + parser.GetNextDocument(doc); + doc["name"] >> output; + if(output != "doc2") + return false; + + return true; + } } } diff --git a/yaml-reader/tests.cpp b/yaml-reader/tests.cpp index 00c5132..9796b63 100644 --- a/yaml-reader/tests.cpp +++ b/yaml-reader/tests.cpp @@ -269,6 +269,8 @@ namespace Test RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed); RunParserTest(&Parser::SimpleAlias, "simple alias", passed); RunParserTest(&Parser::AliasWithNull, "alias with null", passed); + RunParserTest(&Parser::ExplicitDoc, "explicit doc", passed); + RunParserTest(&Parser::MultipleDocs, "multiple docs", passed); RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed); RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed); diff --git a/yaml-reader/tests.h b/yaml-reader/tests.h index f8b3205..91f7def 100644 --- a/yaml-reader/tests.h +++ b/yaml-reader/tests.h @@ -40,6 +40,8 @@ namespace Test { bool NullBlockMapValue(); bool SimpleAlias(); bool AliasWithNull(); + bool ExplicitDoc(); + bool MultipleDocs(); } namespace Emitter {