ensuring local tags are retained after loading a node + test

This commit is contained in:
IMaloney
2025-04-19 21:51:07 +01:00
committed by Oliver Hamlet
parent 19c9d39716
commit 43e4353550
2 changed files with 18 additions and 2 deletions
+7 -2
View File
@@ -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));
}
+11
View File
@@ -627,6 +627,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";