Fixed bug with explicit doc start introduced in last commit

This commit is contained in:
Jesse Beder
2009-08-26 16:15:27 +00:00
parent 4b6a0b382c
commit 1b240d3576
4 changed files with 59 additions and 2 deletions

View File

@@ -294,7 +294,7 @@ namespace YAML
} }
// PopAllIndents // 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. // and enqueues the proper token each time.
void Scanner::PopAllIndents() void Scanner::PopAllIndents()
{ {
@@ -303,9 +303,14 @@ namespace YAML
return; return;
// now pop away // 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();
} }
}
// PopIndent // PopIndent
// . Pops a single indent, pushing the proper token // . Pops a single indent, pushing the proper token

View File

@@ -370,5 +370,53 @@ namespace Test
return true; 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;
}
} }
} }

View File

@@ -269,6 +269,8 @@ namespace Test
RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed); RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed);
RunParserTest(&Parser::SimpleAlias, "simple alias", passed); RunParserTest(&Parser::SimpleAlias, "simple alias", passed);
RunParserTest(&Parser::AliasWithNull, "alias with null", 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, false, "UTF-8, no BOM", passed);
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed); RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed);

View File

@@ -40,6 +40,8 @@ namespace Test {
bool NullBlockMapValue(); bool NullBlockMapValue();
bool SimpleAlias(); bool SimpleAlias();
bool AliasWithNull(); bool AliasWithNull();
bool ExplicitDoc();
bool MultipleDocs();
} }
namespace Emitter { namespace Emitter {