mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Allow using a Node as the key in force_insert.
Node::force_insert() uses convert<> to convert its key to a node. Add a specialization for convert<Node>.
This commit is contained in:

committed by
Jesse Beder

parent
03d6e7d672
commit
320b02b14a
@@ -43,6 +43,17 @@ inline bool IsNaN(const std::string& input) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node
|
||||||
|
template <>
|
||||||
|
struct convert<Node> {
|
||||||
|
static Node encode(const Node& rhs) { return rhs; }
|
||||||
|
|
||||||
|
static bool decode(const Node& node, Node& rhs) {
|
||||||
|
rhs.reset(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// std::string
|
// std::string
|
||||||
template <>
|
template <>
|
||||||
struct convert<std::string> {
|
struct convert<std::string> {
|
||||||
|
@@ -80,6 +80,25 @@ TEST(NodeTest, MapWithUndefinedValues) {
|
|||||||
EXPECT_EQ(2, node.size());
|
EXPECT_EQ(2, node.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, MapForceInsert) {
|
||||||
|
Node node;
|
||||||
|
Node k1("k1");
|
||||||
|
Node k2("k2");
|
||||||
|
Node v1("v1");
|
||||||
|
Node v2("v2");
|
||||||
|
node[k1] = v1;
|
||||||
|
node[k2] = v1;
|
||||||
|
EXPECT_TRUE(node.IsMap());
|
||||||
|
EXPECT_EQ("v1", node["k1"].as<std::string>());
|
||||||
|
EXPECT_EQ("v1", node["k2"].as<std::string>());
|
||||||
|
EXPECT_EQ(2, node.size());
|
||||||
|
|
||||||
|
node.force_insert(k2, v2);
|
||||||
|
EXPECT_EQ("v1", node["k1"].as<std::string>());
|
||||||
|
EXPECT_EQ("v2", node["k2"].as<std::string>());
|
||||||
|
EXPECT_EQ(2, node.size());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(NodeTest, UndefinedConstNodeWithFallback) {
|
TEST(NodeTest, UndefinedConstNodeWithFallback) {
|
||||||
Node node;
|
Node node;
|
||||||
const Node& cn = node;
|
const Node& cn = node;
|
||||||
|
Reference in New Issue
Block a user