mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fixed bug with omitted keys/values in a flow map
This commit is contained in:
@@ -220,6 +220,42 @@ namespace Test
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlowMapWithOmittedKey()
|
||||
{
|
||||
std::string input = "{: omitted key}";
|
||||
std::stringstream stream(input);
|
||||
YAML::Parser parser(stream);
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
std::string output;
|
||||
doc[YAML::Null] >> output;
|
||||
if(output != "omitted key")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlowMapWithOmittedValue()
|
||||
{
|
||||
std::string input = "{a: b, c:, d:}";
|
||||
std::stringstream stream(input);
|
||||
YAML::Parser parser(stream);
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
std::string output;
|
||||
doc["a"] >> output;
|
||||
if(output != "b")
|
||||
return false;
|
||||
if(!IsNull(doc["c"]))
|
||||
return false;
|
||||
if(!IsNull(doc["d"]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuotedSimpleKeys()
|
||||
{
|
||||
std::string KeyValue[3] = { "\"double\": double\n", "'single': single\n", "plain: plain\n" };
|
||||
|
@@ -262,6 +262,8 @@ namespace Test
|
||||
RunParserTest(&Parser::SimpleMap, "simple map", passed);
|
||||
RunParserTest(&Parser::FlowSeq, "flow seq", passed);
|
||||
RunParserTest(&Parser::FlowMap, "flow map", passed);
|
||||
RunParserTest(&Parser::FlowMapWithOmittedKey, "flow map with omitted key", passed);
|
||||
RunParserTest(&Parser::FlowMapWithOmittedValue, "flow map with omitted value", passed);
|
||||
RunParserTest(&Parser::QuotedSimpleKeys, "quoted simple keys", passed);
|
||||
RunParserTest(&Parser::CompressedMapAndSeq, "compressed map and seq", passed);
|
||||
RunParserTest(&Parser::NullBlockSeqEntry, "null block seq entry", passed);
|
||||
|
@@ -33,6 +33,8 @@ namespace Test {
|
||||
bool SimpleMap();
|
||||
bool FlowSeq();
|
||||
bool FlowMap();
|
||||
bool FlowMapWithOmittedKey();
|
||||
bool FlowMapWithOmittedValue();
|
||||
bool QuotedSimpleKeys();
|
||||
bool CompressedMapAndSeq();
|
||||
bool NullBlockSeqEntry();
|
||||
|
Reference in New Issue
Block a user