Commit a165f555 authored by TH3CHARLie's avatar TH3CHARLie Committed by Alexander Alekhin

Merge pull request #15842 from TH3CHARLie:yaml-fix

* fix yaml parse

* add test for YAML parse multiple documents

* remove trailing whitespace in test
parent 0d7f7709
......@@ -770,7 +770,7 @@ public:
bool first = true;
bool ok = true;
FileNode root_collection(fs->getFS(), 0, 0);
FileNode root_node = fs->addNode(root_collection, std::string(), FileNode::NONE);
for(;;)
{
// 0. skip leading comments and directives and ...
......@@ -821,7 +821,6 @@ public:
if( memcmp( ptr, "...", 3 ) != 0 )
{
// 2. parse the collection
FileNode root_node = fs->addNode(root_collection, std::string(), FileNode::NONE);
ptr = parseValue( ptr, root_node, 0, false );
if( !root_node.isMap() && !root_node.isSeq() )
......
......@@ -1640,4 +1640,23 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
ASSERT_EQ(0, std::remove(fileName.c_str()));
}
TEST(Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
{
const std::string filename = "FileStorage_YAML_parse_multiple_documents.yml";
FileStorage fs;
fs.open(filename, FileStorage::WRITE);
fs << "a" << 42;
fs.release();
fs.open(filename, FileStorage::APPEND);
fs << "b" << 1988;
fs.release();
fs.open(filename, FileStorage::READ);
ASSERT_EQ(42, (int)fs["a"]);
ASSERT_EQ(1988, (int)fs["b"]);
fs.release();
}
}} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment