mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
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:
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user