Fixed bug in anchors with no content. This involved refactoring the 'implicit sequence' concept (where a map and a sequence start on the same indent, but we read the sequence as more indented since the '-' is visually an indent).

This commit is contained in:
Jesse Beder
2009-08-24 22:56:54 +00:00
parent abe0af76c5
commit a1460169e6
12 changed files with 183 additions and 36 deletions

View File

@@ -272,6 +272,16 @@ namespace Test
desiredOutput = "- &fred\n name: Fred\n age: 42\n- *fred";
}
void AliasAndAnchorWithNull(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginSeq;
out << YAML::Anchor("fred") << YAML::Null;
out << YAML::Alias("fred");
out << YAML::EndSeq;
desiredOutput = "- &fred ~\n- *fred";
}
void ComplexDoc(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::BeginMap;

View File

@@ -248,6 +248,30 @@ namespace Test
return true;
}
bool CompressedMapAndSeq()
{
std::string input = "key:\n- one\n- two";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
const YAML::Node& seq = doc["key"];
if(seq.size() != 2)
return false;
std::string output;
seq[0] >> output;
if(output != "one")
return false;
seq[1] >> output;
if(output != "two")
return false;
return true;
}
bool NullBlockSeqEntry()
{
std::string input = "- hello\n-\n- world";
@@ -301,5 +325,50 @@ namespace Test
return true;
}
bool SimpleAlias()
{
std::string input = "- &alias test\n- *alias";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
std::string output;
doc[0] >> output;
if(output != "test")
return false;
doc[1] >> output;
if(output != "test")
return false;
if(doc.size() != 2)
return false;
return true;
}
bool AliasWithNull()
{
std::string input = "- &alias\n- *alias";
std::stringstream stream(input);
YAML::Parser parser(stream);
YAML::Node doc;
parser.GetNextDocument(doc);
if(!IsNull(doc[0]))
return false;
if(!IsNull(doc[1]))
return false;
if(doc.size() != 2)
return false;
return true;
}
}
}

View File

@@ -263,9 +263,12 @@ namespace Test
RunParserTest(&Parser::FlowSeq, "flow seq", passed);
RunParserTest(&Parser::FlowMap, "flow map", passed);
RunParserTest(&Parser::QuotedSimpleKeys, "quoted simple keys", passed);
RunParserTest(&Parser::CompressedMapAndSeq, "compressed map and seq", passed);
RunParserTest(&Parser::NullBlockSeqEntry, "null block seq entry", passed);
RunParserTest(&Parser::NullBlockMapKey, "null block map key", passed);
RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed);
RunParserTest(&Parser::SimpleAlias, "simple alias", passed);
RunParserTest(&Parser::AliasWithNull, "alias with null", passed);
RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed);
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed);
@@ -346,6 +349,7 @@ namespace Test
RunEmitterTest(&Emitter::LongKeyFlowMap, "long key flow map", passed);
RunEmitterTest(&Emitter::BlockMapAsKey, "block map as key", passed);
RunEmitterTest(&Emitter::AliasAndAnchor, "alias and anchor", passed);
RunEmitterTest(&Emitter::AliasAndAnchorWithNull, "alias and anchor with null", passed);
RunEmitterTest(&Emitter::ComplexDoc, "complex doc", passed);
RunEmitterTest(&Emitter::STLContainers, "STL containers", passed);
RunEmitterTest(&Emitter::SimpleComment, "simple comment", passed);

View File

@@ -34,9 +34,12 @@ namespace Test {
bool FlowSeq();
bool FlowMap();
bool QuotedSimpleKeys();
bool CompressedMapAndSeq();
bool NullBlockSeqEntry();
bool NullBlockMapKey();
bool NullBlockMapValue();
bool SimpleAlias();
bool AliasWithNull();
}
namespace Emitter {
@@ -63,6 +66,7 @@ namespace Test {
void LongKeyFlowMap(YAML::Emitter& out, std::string& desiredOutput);
void BlockMapAsKey(YAML::Emitter& out, std::string& desiredOutput);
void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput);
void AliasAndAnchorWithNull(YAML::Emitter& out, std::string& desiredOutput);
void ComplexDoc(YAML::Emitter& out, std::string& desiredOutput);
void STLContainers(YAML::Emitter& out, std::string& desiredOutput);
void SimpleComment(YAML::Emitter& out, std::string& desiredOutput);