reset node hasBegun flags at the EndedGroup method. Fix #902

This commit is contained in:
Raffaello Bertini 2020-06-22 15:44:55 +01:00
parent 97d1ae547c
commit 8c55a70548
2 changed files with 40 additions and 1 deletions

View File

@ -175,8 +175,11 @@ void EmitterState::EndedGroup(GroupType::value type) {
// some global settings that we changed may have been overridden
// by a local setting we just popped, so we need to restore them
m_globalModifiedSettings.restore();
ClearModifiedSettings();
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
EmitterNodeType::value EmitterState::CurGroupNodeType() const {

View File

@ -1212,6 +1212,42 @@ TEST_F(EmitterTest, NaN) {
"bar: .nan");
}
TEST_F(EmitterTest, ComplexFlowSeqEmbeddingAMapWithNewLine) {
out << YAML::BeginMap;
out << YAML::Key << "NodeA" << YAML::Value << YAML::BeginMap;
out << YAML::Key << "k" << YAML::Value << YAML::Flow << YAML::BeginSeq;
out << YAML::BeginMap << YAML::Key << "i" << YAML::Value << 0 << YAML::EndMap
<< YAML::Newline;
out << YAML::BeginMap << YAML::Key << "i" << YAML::Value << 1 << YAML::EndMap
<< YAML::Newline;
out << YAML::EndSeq;
out << YAML::EndMap;
out << YAML::Key << "NodeB" << YAML::Value << YAML::BeginMap;
out << YAML::Key << "k" << YAML::Value << YAML::Flow << YAML::BeginSeq;
out << YAML::BeginMap << YAML::Key << "i" << YAML::Value << 0 << YAML::EndMap
<< YAML::Newline;
out << YAML::BeginMap << YAML::Key << "i" << YAML::Value << 1 << YAML::EndMap
<< YAML::Newline;
out << YAML::EndSeq;
out << YAML::EndMap;
out << YAML::EndMap;
ExpectEmit(
"NodeA:\n"
" k: [{i: 0},\n"
" {i: 1},\n"
" ]\n"
"NodeB:\n"
" k: [{i: 0},\n"
" {i: 1},\n"
" ]"
);
}
class EmitterErrorTest : public ::testing::Test {
protected:
void ExpectEmitError(const std::string& expectedError) {