Skip to content

Commit

Permalink
ensuring local tags are retained after loading a node + test
Browse files Browse the repository at this point in the history
  • Loading branch information
IMaloney authored and jbeder committed Dec 17, 2024
1 parent f878043 commit 1da813f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/emitfromevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ void EmitFromEvents::BeginNode() {
}

void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
if (!tag.empty() && tag != "?" && tag != "!")
m_emitter << VerbatimTag(tag);
if (!tag.empty() && tag != "?" && tag != "!"){
if (tag[0] == '!') {
m_emitter << LocalTag(std::string(tag.begin()+1, tag.end()));
} else {
m_emitter << VerbatimTag(tag);
}
}
if (anchor)
m_emitter << Anchor(ToString(anchor));
}
Expand Down
11 changes: 11 additions & 0 deletions test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ TEST_F(EmitterTest, LocalTagWithScalar) {
ExpectEmit("!foo bar");
}

TEST_F(EmitterTest, LocalTagRetainedAfterLoadingNode) {
Node n = Node("hello");
out << LocalTag("foo") << n;
std::string expected = "!foo hello";
ExpectEmit(expected);
Node yamlNode = Load(out.c_str());
Emitter emitter;
emitter << yamlNode;
EXPECT_EQ(expected, emitter.c_str());
}

TEST_F(EmitterTest, ComplexDoc) {
out << BeginMap;
out << Key << "receipt";
Expand Down

0 comments on commit 1da813f

Please sign in to comment.