Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,5 +1946,55 @@ TEST_F(EmitterTest, ShowTrailingZero) {
- .nan)");
}

TEST_F(EmitterTest, EmitEmptyNode) {
Node node;
out << node;
ExpectEmit("");
}

TEST_F(EmitterTest, SetVerbatimTag) {
Node node, root;
node = 42;
node.SetTag("hello");
root["num"] = node;

out << root;
ExpectEmit("num: !<hello> 42");
}

// Regression for #1373: emitting a node whose tag begins with "!!"
// (a YAML secondary tag handle, e.g. "!!str") used to bail out with
// INVALID_TAG and truncate the output after the first '!'.
TEST_F(EmitterTest, EmitSetTagSecondaryHandle) {
Node root;
Node string_node{"hello"};
string_node.SetTag("!!str");
root["some_string"] = string_node;
root["some_int"] = 2;

out << root;
ExpectEmit("some_string: !!str hello\nsome_int: 2");
}

TEST_F(EmitterTest, EmitSetTagPrimaryHandle) {
Node root;
Node string_node{"hello"};
string_node.SetTag("!mytag");
root["v"] = string_node;

out << root;
ExpectEmit("v: !mytag hello");
}

TEST_F(EmitterTest, EmitSetLocalTagInNameHandle) {
Node node, root;
node = 42;
node.SetTag("!a!foo");
root["num"] = node;

out << root;
ExpectEmit("num: !a!foo 42");
}

} // namespace
} // namespace YAML
58 changes: 1 addition & 57 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,62 +224,6 @@ TEST(LoadNodeTest, DereferenceIteratorError) {
EXPECT_THROW(node.begin()->begin()->Type(), InvalidNode);
}

TEST(NodeTest, EmitEmptyNode) {
Node node;
Emitter emitter;
emitter << node;
EXPECT_EQ("", std::string(emitter.c_str()));
}

TEST(NodeTest, SetVerbatimTag) {
Node node, root;
node = 42;
node.SetTag("hello");
root["num"] = node;

Emitter emitter;
emitter << root;
EXPECT_EQ("num: !<hello> 42", std::string(emitter.c_str()));
}

// Regression for #1373: emitting a node whose tag begins with "!!"
// (a YAML secondary tag handle, e.g. "!!str") used to bail out with
// INVALID_TAG and truncate the output after the first '!'.
TEST(NodeTest, EmitSetTagSecondaryHandle) {
Node root;
Node string_node{"hello"};
string_node.SetTag("!!str");
root["some_string"] = string_node;
root["some_int"] = 2;

Emitter emitter;
emitter << root;
EXPECT_EQ("some_string: !!str hello\nsome_int: 2",
std::string(emitter.c_str()));
}

TEST(NodeTest, EmitSetTagPrimaryHandle) {
Node root;
Node string_node{"hello"};
string_node.SetTag("!mytag");
root["v"] = string_node;

Emitter emitter;
emitter << root;
EXPECT_EQ("v: !mytag hello", std::string(emitter.c_str()));
}

TEST(NodeTest, EmitSetLocalTagInNameHandle) {
Node node, root;
node = 42;
node.SetTag("!a!foo");
root["num"] = node;

Emitter emitter;
emitter << root;
EXPECT_EQ("num: !a!foo 42", std::string(emitter.c_str()));
}

TEST(NodeTest, ParseNodeStyle) {
EXPECT_EQ(EmitterStyle::Flow, Load("[1, 2, 3]").Style());
EXPECT_EQ(EmitterStyle::Flow, Load("{foo: bar}").Style());
Expand Down Expand Up @@ -519,4 +463,4 @@ TEST(LoadNodeTest, NonUniqueMapKey) {
}

} // namespace
} // namespace YAML
} // namespace YAML
Loading