Skip to content

Commit

Permalink
fix noderef tests which were optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Apr 4, 2024
1 parent e99e44e commit 04a8579
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 123 deletions.
8 changes: 4 additions & 4 deletions src/c4/yml/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ struct RoNodeMethods
C4_ALWAYS_INLINE bool parent_is_seq() const RYML_NOEXCEPT { _C4RV(); return tree_->parent_is_seq(id_); }
C4_ALWAYS_INLINE bool parent_is_map() const RYML_NOEXCEPT { _C4RV(); return tree_->parent_is_map(id_); }

RYML_DEPRECATED("use has_key_anchor()") C4_ALWAYS_INLINE C4_PURE bool is_key_anchor() const noexcept { _C4RV(); return tree_->has_key_anchor(id_); }
RYML_DEPRECATED("use has_val_anchor()") C4_ALWAYS_INLINE C4_PURE bool is_val_hanchor() const noexcept { _C4RV(); return tree_->has_val_anchor(id_); }
RYML_DEPRECATED("use has_anchor()") C4_ALWAYS_INLINE C4_PURE bool is_anchor() const noexcept { _C4RV(); return tree_->has_anchor(id_); }
RYML_DEPRECATED("use has_anchor() || is_ref()") C4_ALWAYS_INLINE C4_PURE bool is_anchor_or_ref() const noexcept { _C4RV(); return tree_->is_anchor_or_ref(id_); }
RYML_DEPRECATED("use has_key_anchor()") C4_ALWAYS_INLINE bool is_key_anchor() const noexcept { _C4RV(); return tree_->has_key_anchor(id_); }
RYML_DEPRECATED("use has_val_anchor()") C4_ALWAYS_INLINE bool is_val_hanchor() const noexcept { _C4RV(); return tree_->has_val_anchor(id_); }
RYML_DEPRECATED("use has_anchor()") C4_ALWAYS_INLINE bool is_anchor() const noexcept { _C4RV(); return tree_->has_anchor(id_); }
RYML_DEPRECATED("use has_anchor() || is_ref()") C4_ALWAYS_INLINE bool is_anchor_or_ref() const noexcept { _C4RV(); return tree_->is_anchor_or_ref(id_); }

/** @} */

Expand Down
5 changes: 5 additions & 0 deletions test/test_lib/test_case_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "test_lib/test_case.hpp"
#include <gtest/gtest.h>

C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")

namespace c4 {
namespace yml {

Expand Down Expand Up @@ -258,5 +261,7 @@ void TestCaseNode::recreate(yml::NodeRef *n) const
}
}

C4_SUPPRESS_WARNING_GCC_CLANG_PUSH

} // namespace yml
} // namespace c4
257 changes: 138 additions & 119 deletions test/test_noderef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,154 +222,173 @@ TEST(NodeRef, valid_vs_seed_vs_readable)
EXPECT_FALSE(none.readable());
}

#define _TEST_FAIL(method_expr) \
{ \
SCOPED_TRACE(#method_expr); \
if(tree) \
ExpectError::check_assertion(tree, [&]{ (void)(method_expr); }); \
else \
ExpectError::check_assertion([&]{ (void)(method_expr); }); \
#define _TEST_FAIL(tree, method_expr) \
{ \
SCOPED_TRACE(#method_expr); \
ExpectError::check_assertion(tree, [&]{ \
C4_DONT_OPTIMIZE(method_expr); \
}); \
}
#define _TEST_SUCCEED(method_expr) \
{ \
SCOPED_TRACE(#method_expr); \
if(tree) \
ExpectError::check_success(tree, [&]{ (void)(method_expr); }); \
else \
ExpectError::check_success([&]{ (void)(method_expr); }); \
#define _TEST_SUCCEED(tree, method_expr) \
{ \
SCOPED_TRACE(#method_expr); \
ExpectError::check_success(tree, [&]{ \
C4_DONT_OPTIMIZE(method_expr); \
}); \
}

template<class NodeT>
void test_fail_read(Tree *tree, NodeT node)
{
_TEST_SUCCEED(node.get())
_TEST_FAIL(node.type())
_TEST_FAIL(node.type_str())
_TEST_FAIL(node.key())
_TEST_FAIL(node.key_tag())
_TEST_FAIL(node.key_anchor())
_TEST_FAIL(node.key_ref())
_TEST_FAIL(node.key_is_null())
_TEST_FAIL(node.keysc())
_TEST_FAIL(node.val())
_TEST_FAIL(node.val_tag())
_TEST_FAIL(node.val_anchor())
_TEST_FAIL(node.val_ref())
_TEST_FAIL(node.val_is_null())
_TEST_FAIL(node.valsc())
_TEST_FAIL(node.is_map())
_TEST_FAIL(node.empty())
_TEST_FAIL(node.is_stream())
_TEST_FAIL(node.is_doc())
_TEST_FAIL(node.is_container())
_TEST_FAIL(node.is_map())
_TEST_FAIL(node.is_seq())
_TEST_FAIL(node.has_val())
_TEST_FAIL(node.has_key())
_TEST_FAIL(node.is_keyval())
_TEST_FAIL(node.has_key_tag())
_TEST_FAIL(node.has_val_tag())
_TEST_FAIL(node.has_key_anchor())
_TEST_FAIL(node.has_val_anchor())
_TEST_FAIL(node.has_anchor())
_TEST_FAIL(node.is_key_ref())
_TEST_FAIL(node.is_val_ref())
_TEST_FAIL(node.is_ref())
_TEST_FAIL(node.is_key_quoted())
_TEST_FAIL(node.is_val_quoted())
_TEST_FAIL(node.parent_is_seq())
_TEST_FAIL(node.parent_is_map())
_TEST_FAIL(node.is_root())
_TEST_FAIL(node.has_parent())
_TEST_FAIL(node.has_child(0))
_TEST_FAIL(node.has_child("key"))
_TEST_FAIL(node.has_children())
_TEST_FAIL(node.has_sibling("key"))
_TEST_FAIL(node.has_other_siblings())
_TEST_FAIL(node.doc(0))
_TEST_FAIL(node.parent())
_TEST_FAIL(node.num_children())
_TEST_FAIL(node.first_child())
_TEST_FAIL(node.last_child())
_TEST_FAIL(node.child(0))
_TEST_FAIL(node.find_child("key"))
_TEST_FAIL(node.prev_sibling())
_TEST_FAIL(node.next_sibling())
_TEST_FAIL(node.first_sibling())
_TEST_FAIL(node.last_sibling())
_TEST_FAIL(node.sibling(0))
_TEST_FAIL(node.find_sibling("key"))
_TEST_FAIL(node.num_children())
_TEST_FAIL(node.num_siblings())
_TEST_FAIL(node.num_other_siblings())
_TEST_FAIL(node["key"])
_TEST_FAIL(node[0])
_TEST_FAIL(node.at("key"))
_TEST_FAIL(node.at(0))
_TEST_SUCCEED(tree, node.get())
_TEST_FAIL(tree, node.type())
_TEST_FAIL(tree, node.type_str())
_TEST_FAIL(tree, node.key())
_TEST_FAIL(tree, node.key_tag())
_TEST_FAIL(tree, node.key_anchor())
_TEST_FAIL(tree, node.key_ref())
_TEST_FAIL(tree, node.key_is_null())
_TEST_FAIL(tree, node.keysc())
_TEST_FAIL(tree, node.val())
_TEST_FAIL(tree, node.val_tag())
_TEST_FAIL(tree, node.val_anchor())
_TEST_FAIL(tree, node.val_ref())
_TEST_FAIL(tree, node.val_is_null())
_TEST_FAIL(tree, node.valsc())
_TEST_FAIL(tree, node.is_map())
_TEST_FAIL(tree, node.empty())
_TEST_FAIL(tree, node.is_stream())
_TEST_FAIL(tree, node.is_doc())
_TEST_FAIL(tree, node.is_container())
_TEST_FAIL(tree, node.is_map())
_TEST_FAIL(tree, node.is_seq())
_TEST_FAIL(tree, node.has_val())
_TEST_FAIL(tree, node.has_key())
_TEST_FAIL(tree, node.is_keyval())
_TEST_FAIL(tree, node.has_key_tag())
_TEST_FAIL(tree, node.has_val_tag())
_TEST_FAIL(tree, node.has_key_anchor())
_TEST_FAIL(tree, node.has_val_anchor())
_TEST_FAIL(tree, node.has_anchor())
_TEST_FAIL(tree, node.is_key_ref())
_TEST_FAIL(tree, node.is_val_ref())
_TEST_FAIL(tree, node.is_ref())
_TEST_FAIL(tree, node.parent_is_seq())
_TEST_FAIL(tree, node.parent_is_map())
_TEST_FAIL(tree, node.type_has_any(MAP|SEQ))
_TEST_FAIL(tree, node.type_has_all(MAP|SEQ))
_TEST_FAIL(tree, node.type_has_none(MAP|SEQ))
_TEST_FAIL(tree, node.is_container_styled())
_TEST_FAIL(tree, node.is_block())
_TEST_FAIL(tree, node.is_flow())
_TEST_FAIL(tree, node.is_flow_sl())
_TEST_FAIL(tree, node.is_flow_ml())
_TEST_FAIL(tree, node.is_key_styled())
_TEST_FAIL(tree, node.is_val_styled())
_TEST_FAIL(tree, node.is_key_literal())
_TEST_FAIL(tree, node.is_val_literal())
_TEST_FAIL(tree, node.is_key_folded())
_TEST_FAIL(tree, node.is_val_folded())
_TEST_FAIL(tree, node.is_key_squo())
_TEST_FAIL(tree, node.is_val_squo())
_TEST_FAIL(tree, node.is_key_dquo())
_TEST_FAIL(tree, node.is_val_dquo())
_TEST_FAIL(tree, node.is_key_plain())
_TEST_FAIL(tree, node.is_val_plain())
_TEST_FAIL(tree, node.is_key_quoted())
_TEST_FAIL(tree, node.is_val_quoted())
_TEST_FAIL(tree, node.is_quoted())
_TEST_FAIL(tree, node.is_root())
_TEST_FAIL(tree, node.has_parent())
_TEST_FAIL(tree, node.has_child(0))
_TEST_FAIL(tree, node.has_child("key"))
_TEST_FAIL(tree, node.has_children())
_TEST_FAIL(tree, node.has_sibling("key"))
_TEST_FAIL(tree, node.has_other_siblings())
_TEST_FAIL(tree, node.doc(0))
_TEST_FAIL(tree, node.parent())
_TEST_FAIL(tree, node.num_children())
_TEST_FAIL(tree, node.first_child())
_TEST_FAIL(tree, node.last_child())
_TEST_FAIL(tree, node.child(0))
_TEST_FAIL(tree, node.find_child("key"))
_TEST_FAIL(tree, node.prev_sibling())
_TEST_FAIL(tree, node.next_sibling())
_TEST_FAIL(tree, node.first_sibling())
_TEST_FAIL(tree, node.last_sibling())
_TEST_FAIL(tree, node.sibling(0))
_TEST_FAIL(tree, node.find_sibling("key"))
_TEST_FAIL(tree, node.num_children())
_TEST_FAIL(tree, node.num_siblings())
_TEST_FAIL(tree, node.num_other_siblings())
_TEST_FAIL(tree, node["key"])
_TEST_FAIL(tree, node[0])
_TEST_FAIL(tree, node.at("key"))
_TEST_FAIL(tree, node.at(0))
int val;
_TEST_FAIL(node >> val)
_TEST_FAIL(node >> key(val))
_TEST_FAIL(node >> fmt::base64(val))
_TEST_FAIL(node >> key(fmt::base64(val)))
_TEST_FAIL(node.deserialize_key(fmt::base64(val)))
_TEST_FAIL(node.deserialize_val(fmt::base64(val)))
_TEST_FAIL(node.get_if("key", &val));
_TEST_FAIL(node.get_if("key", &val, 0));
_TEST_FAIL(tree, node >> val)
_TEST_FAIL(tree, node >> key(val))
_TEST_FAIL(tree, node >> fmt::base64(val))
_TEST_FAIL(tree, node >> key(fmt::base64(val)))
_TEST_FAIL(tree, node.deserialize_key(fmt::base64(val)))
_TEST_FAIL(tree, node.deserialize_val(fmt::base64(val)))
_TEST_FAIL(tree, node.get_if("key", &val));
_TEST_FAIL(tree, node.get_if("key", &val, 0));
const NodeT const_node = node;
_TEST_FAIL(node.begin());
_TEST_FAIL(node.cbegin());
_TEST_FAIL(const_node.begin());
_TEST_FAIL(const_node.cbegin());
_TEST_FAIL(node.end());
_TEST_FAIL(node.end());
_TEST_FAIL(const_node.end());
_TEST_FAIL(const_node.end());
_TEST_FAIL(node.children());
_TEST_FAIL(node.children());
_TEST_FAIL(const_node.children());
_TEST_FAIL(const_node.children());
_TEST_FAIL(node.siblings());
_TEST_FAIL(node.siblings());
_TEST_FAIL(const_node.siblings());
_TEST_FAIL(const_node.siblings());
//_TEST_FAIL(node.visit([](NodeT &n, size_t level){ (void)n; (void)level; return false; }));
//_TEST_FAIL(const_node.visit([](const NodeT &n, size_t level){ (void)n; (void)level; return false; }));
_TEST_SUCCEED(const_node == node);
_TEST_SUCCEED(const_node != node);
_TEST_SUCCEED(const_node == nullptr);
_TEST_SUCCEED(const_node != nullptr);
_TEST_FAIL(const_node == "val");
_TEST_FAIL(const_node != "val");
_TEST_FAIL(tree, node.begin());
_TEST_FAIL(tree, node.cbegin());
_TEST_FAIL(tree, const_node.begin());
_TEST_FAIL(tree, const_node.cbegin());
_TEST_FAIL(tree, node.end());
_TEST_FAIL(tree, node.end());
_TEST_FAIL(tree, const_node.end());
_TEST_FAIL(tree, const_node.end());
_TEST_FAIL(tree, node.children());
_TEST_FAIL(tree, node.children());
_TEST_FAIL(tree, const_node.children());
_TEST_FAIL(tree, const_node.children());
_TEST_FAIL(tree, node.siblings());
_TEST_FAIL(tree, node.siblings());
_TEST_FAIL(tree, const_node.siblings());
_TEST_FAIL(tree, const_node.siblings());
//_TEST_FAIL(tree, node.visit([](NodeT &n, size_t level){ (void)n; (void)level; return false; }));
//_TEST_FAIL(tree, const_node.visit([](const NodeT &n, size_t level){ (void)n; (void)level; return false; }));
_TEST_SUCCEED(tree, const_node == node);
_TEST_SUCCEED(tree, const_node != node);
_TEST_SUCCEED(tree, const_node == nullptr);
_TEST_SUCCEED(tree, const_node != nullptr);
_TEST_FAIL(tree, const_node == "val");
_TEST_FAIL(tree, const_node != "val");
if(std::is_same<NodeT, NodeRef>::value)
{
ConstNodeRef other;
_TEST_SUCCEED(node == other);
_TEST_SUCCEED(node != node);
_TEST_SUCCEED(tree, node == other);
_TEST_SUCCEED(tree, node != node);
}
}
template<class NodeT>
void test_fail_read_subject(Tree *tree, NodeT node, NodeT subject)
{
if(node.readable())
{
_TEST_SUCCEED(node.has_child(subject))
_TEST_SUCCEED(node.has_sibling(subject))
_TEST_SUCCEED(tree, node.has_child(subject))
_TEST_SUCCEED(tree, node.has_sibling(subject))
}
else
{
_TEST_FAIL(node.has_child(subject))
_TEST_FAIL(node.has_sibling(subject))
_TEST_FAIL(tree, node.has_child(subject))
_TEST_FAIL(tree, node.has_sibling(subject))
}
_TEST_FAIL(node.child_pos(subject))
_TEST_FAIL(node.sibling_pos(subject))
_TEST_FAIL(tree, node.child_pos(subject))
_TEST_FAIL(tree, node.sibling_pos(subject))
}
#undef _TEST_FAIL_READ
#undef _TEST_SUCCEED_READ

TEST(NodeRef, cannot_read_from_invalid)
{
SCOPED_TRACE("here");
NodeRef none;
SCOPED_TRACE("here");
ASSERT_EQ(none.tree(), nullptr);
ASSERT_EQ(none.id(), NONE);
EXPECT_FALSE(none.valid());
Expand Down

0 comments on commit 04a8579

Please sign in to comment.