mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Fix operator bool() exception on zombie node
This commit is contained in:
@@ -60,8 +60,9 @@ inline void Node::EnsureNodeExists() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool Node::IsDefined() const {
|
inline bool Node::IsDefined() const {
|
||||||
if (!m_isValid)
|
if (!m_isValid) {
|
||||||
throw InvalidNode();
|
return false;
|
||||||
|
}
|
||||||
return m_pNode ? m_pNode->is_defined() : true;
|
return m_pNode ? m_pNode->is_defined() : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -181,8 +181,8 @@ TEST(LoadNodeTest, DereferenceIteratorError) {
|
|||||||
EXPECT_THROW(node.begin()->first.as<int>(), InvalidNode);
|
EXPECT_THROW(node.begin()->first.as<int>(), InvalidNode);
|
||||||
EXPECT_EQ(true, (*node.begin()).IsMap());
|
EXPECT_EQ(true, (*node.begin()).IsMap());
|
||||||
EXPECT_EQ(true, node.begin()->IsMap());
|
EXPECT_EQ(true, node.begin()->IsMap());
|
||||||
EXPECT_THROW((*node.begin()->begin()).IsDefined(), InvalidNode);
|
EXPECT_THROW((*node.begin()->begin()).Type(), InvalidNode);
|
||||||
EXPECT_THROW(node.begin()->begin()->IsDefined(), InvalidNode);
|
EXPECT_THROW(node.begin()->begin()->Type(), InvalidNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NodeTest, EmitEmptyNode) {
|
TEST(NodeTest, EmitEmptyNode) {
|
||||||
|
@@ -281,6 +281,13 @@ TEST(NodeTest, DefaultNodeStyle) {
|
|||||||
EXPECT_EQ(EmitterStyle::Default, node.Style());
|
EXPECT_EQ(EmitterStyle::Default, node.Style());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, AccessNonexistentKeyOnConstNode) {
|
||||||
|
YAML::Node node;
|
||||||
|
node["3"] = "4";
|
||||||
|
const YAML::Node& other = node;
|
||||||
|
ASSERT_FALSE(other["5"]);
|
||||||
|
}
|
||||||
|
|
||||||
class NodeEmitterTest : public ::testing::Test {
|
class NodeEmitterTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void ExpectOutput(const std::string& output, const Node& node) {
|
void ExpectOutput(const std::string& output, const Node& node) {
|
||||||
|
Reference in New Issue
Block a user