mirror of
https://github.com/biojppm/rapidyaml.git
synced 2026-01-18 13:31:19 +01:00
fix use of size_t, should be id_type
This commit is contained in:
@@ -19,6 +19,10 @@ Most of the changes are from the giant Parser refactor described below. Before g
|
||||
NodeRef::depth_asc() const;
|
||||
NodeRef::depth_desc() const;
|
||||
```
|
||||
- [#PR432](https://github.com/biojppm/rapidyaml/pull/432) - Added a function to estimate the required tree capacity, based on yaml markup:
|
||||
```cpp
|
||||
size_t estimate_tree_capacity(csubstr); // estimate number of nodes resulting from yaml
|
||||
```
|
||||
|
||||
|
||||
------
|
||||
|
||||
@@ -357,8 +357,8 @@ john: doe)";
|
||||
// The lower level index API is based on the indices of nodes,
|
||||
// where the node's id is the node's position in the tree's data
|
||||
// array. This API is very efficient, but somewhat difficult to use:
|
||||
size_t root_id = tree.root_id();
|
||||
size_t bar_id = tree.find_child(root_id, "bar"); // need to get the index right
|
||||
ryml::id_type root_id = tree.root_id();
|
||||
ryml::id_type bar_id = tree.find_child(root_id, "bar"); // need to get the index right
|
||||
CHECK(tree.is_map(root_id)); // all of the index methods are in the tree
|
||||
CHECK(tree.is_seq(bar_id)); // ... and receive the subject index
|
||||
|
||||
@@ -426,14 +426,14 @@ john: doe)";
|
||||
|
||||
// IMPORTANT. The ryml tree uses an index-based linked list for
|
||||
// storing children, so the complexity of
|
||||
// `Tree::operator[csubstr]` and `Tree::operator[size_t]` is O(n),
|
||||
// `Tree::operator[csubstr]` and `Tree::operator[id_type]` is O(n),
|
||||
// linear on the number of root children. If you use
|
||||
// `Tree::operator[]` with a large tree where the root has many
|
||||
// children, you will see a performance hit.
|
||||
//
|
||||
// To avoid this hit, you can create your own accelerator
|
||||
// structure. For example, before doing a lookup, do a single
|
||||
// traverse at the root level to fill an `map<csubstr,size_t>`
|
||||
// traverse at the root level to fill an `map<csubstr,id_type>`
|
||||
// mapping key names to node indices; with a node index, a lookup
|
||||
// (via `Tree::get()`) is O(1), so this way you can get O(log n)
|
||||
// lookup from a key. (But please do not use `std::map` if you
|
||||
@@ -479,20 +479,20 @@ john: doe)";
|
||||
ryml::csubstr expected_keys[] = {"foo", "bar", "john"};
|
||||
// iterate children using the high-level node API:
|
||||
{
|
||||
size_t count = 0;
|
||||
ryml::id_type count = 0;
|
||||
for(ryml::ConstNodeRef const& child : root.children())
|
||||
CHECK(child.key() == expected_keys[count++]);
|
||||
}
|
||||
// iterate siblings using the high-level node API:
|
||||
{
|
||||
size_t count = 0;
|
||||
ryml::id_type count = 0;
|
||||
for(ryml::ConstNodeRef const& child : root["foo"].siblings())
|
||||
CHECK(child.key() == expected_keys[count++]);
|
||||
}
|
||||
// iterate children using the lower-level tree index API:
|
||||
{
|
||||
size_t count = 0;
|
||||
for(size_t child_id = tree.first_child(root_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id))
|
||||
ryml::id_type count = 0;
|
||||
for(ryml::id_type child_id = tree.first_child(root_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id))
|
||||
CHECK(tree.key(child_id) == expected_keys[count++]);
|
||||
}
|
||||
// iterate siblings using the lower-level tree index API:
|
||||
@@ -500,8 +500,8 @@ john: doe)";
|
||||
// preamble, which calls tree.first_sibling(bar_id) instead of
|
||||
// tree.first_child(root_id))
|
||||
{
|
||||
size_t count = 0;
|
||||
for(size_t child_id = tree.first_sibling(bar_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id))
|
||||
ryml::id_type count = 0;
|
||||
for(ryml::id_type child_id = tree.first_sibling(bar_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id))
|
||||
CHECK(tree.key(child_id) == expected_keys[count++]);
|
||||
}
|
||||
}
|
||||
@@ -3629,7 +3629,7 @@ void write(ryml::NodeRef *n, my_type const& val)
|
||||
template<class T>
|
||||
bool read(ryml::ConstNodeRef const& n, my_seq_type<T> *seq)
|
||||
{
|
||||
seq->seq_member.resize(n.num_children()); // num_children() is O(N)
|
||||
seq->seq_member.resize(static_cast<size_t>(n.num_children())); // num_children() is O(N)
|
||||
size_t pos = 0;
|
||||
for(auto const ch : n.children())
|
||||
ch >> seq->seq_member[pos++];
|
||||
@@ -3813,7 +3813,7 @@ void sample_float_precision()
|
||||
CHECK(output.size() == reference.size());
|
||||
for(size_t i = 0; i < reference.size(); ++i)
|
||||
{
|
||||
CHECK(get_num_digits(tree[i].val()) == num_digits_original);
|
||||
CHECK(get_num_digits(tree[(ryml::id_type)i].val()) == num_digits_original);
|
||||
CHECK(fabs(output[i] - reference[i]) < precision_safe);
|
||||
}
|
||||
}
|
||||
@@ -4577,12 +4577,12 @@ d: 3
|
||||
CHECK(tree.docref(1).id() == stream.child(1).id());
|
||||
CHECK(tree.docref(2).id() == stream.child(2).id());
|
||||
// equivalent: using the lower level index API
|
||||
const size_t stream_id = tree.root_id();
|
||||
const ryml::id_type stream_id = tree.root_id();
|
||||
CHECK(tree.is_root(stream_id));
|
||||
CHECK(tree.is_stream(stream_id));
|
||||
CHECK(!tree.is_doc(stream_id));
|
||||
CHECK(tree.num_children(stream_id) == 3);
|
||||
for(size_t doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(stream_id))
|
||||
for(ryml::id_type doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(stream_id))
|
||||
CHECK(tree.is_doc(doc_id));
|
||||
CHECK(tree.doc(0) == tree.child(stream_id, 0));
|
||||
CHECK(tree.doc(1) == tree.child(stream_id, 1));
|
||||
@@ -4594,7 +4594,7 @@ d: 3
|
||||
CHECK(stream[0]["a"].val() == "0");
|
||||
CHECK(stream[0]["b"].val() == "1");
|
||||
// equivalent: using the index API
|
||||
const size_t doc0_id = tree.first_child(stream_id);
|
||||
const ryml::id_type doc0_id = tree.first_child(stream_id);
|
||||
CHECK(tree.is_doc(doc0_id));
|
||||
CHECK(tree.is_map(doc0_id));
|
||||
CHECK(tree.val(tree.find_child(doc0_id, "a")) == "0");
|
||||
@@ -4606,7 +4606,7 @@ d: 3
|
||||
CHECK(stream[1]["c"].val() == "2");
|
||||
CHECK(stream[1]["d"].val() == "3");
|
||||
// equivalent: using the index API
|
||||
const size_t doc1_id = tree.next_sibling(doc0_id);
|
||||
const ryml::id_type doc1_id = tree.next_sibling(doc0_id);
|
||||
CHECK(tree.is_doc(doc1_id));
|
||||
CHECK(tree.is_map(doc1_id));
|
||||
CHECK(tree.val(tree.find_child(doc1_id, "c")) == "2");
|
||||
@@ -4620,7 +4620,7 @@ d: 3
|
||||
CHECK(stream[2][2].val() == "6");
|
||||
CHECK(stream[2][3].val() == "7");
|
||||
// equivalent: using the index API
|
||||
const size_t doc2_id = tree.next_sibling(doc1_id);
|
||||
const ryml::id_type doc2_id = tree.next_sibling(doc1_id);
|
||||
CHECK(tree.is_doc(doc2_id));
|
||||
CHECK(tree.is_seq(doc2_id));
|
||||
CHECK(tree.val(tree.child(doc2_id, 0)) == "4");
|
||||
@@ -4644,18 +4644,18 @@ d: 3
|
||||
};
|
||||
// using the node API
|
||||
{
|
||||
size_t count = 0;
|
||||
ryml::id_type count = 0;
|
||||
const ryml::ConstNodeRef stream = tree.rootref();
|
||||
CHECK(stream.num_children() == C4_COUNTOF(expected_json));
|
||||
CHECK(stream.num_children() == (ryml::id_type)C4_COUNTOF(expected_json));
|
||||
for(ryml::ConstNodeRef doc : stream.children())
|
||||
CHECK(ryml::emitrs_json<std::string>(doc) == expected_json[count++]);
|
||||
}
|
||||
// equivalent: using the index API
|
||||
{
|
||||
size_t count = 0;
|
||||
const size_t stream_id = tree.root_id();
|
||||
CHECK(tree.num_children(stream_id) == C4_COUNTOF(expected_json));
|
||||
for(size_t doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(doc_id))
|
||||
ryml::id_type count = 0;
|
||||
const ryml::id_type stream_id = tree.root_id();
|
||||
CHECK(tree.num_children(stream_id) == (ryml::id_type)C4_COUNTOF(expected_json));
|
||||
for(ryml::id_type doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(doc_id))
|
||||
CHECK(ryml::emitrs_json<std::string>(tree, doc_id) == expected_json[count++]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ void Emitter<Writer>::_emit_yaml(id_type id)
|
||||
break;
|
||||
++end;
|
||||
}
|
||||
const size_t parent = m_tree->parent(next_node);
|
||||
const id_type parent = m_tree->parent(next_node);
|
||||
for( ; tagds.b != end; ++tagds.b)
|
||||
{
|
||||
if(next_node != m_tree->first_child(parent))
|
||||
@@ -199,7 +199,7 @@ void Emitter<Writer>::_write_doc(id_type id)
|
||||
}
|
||||
else // docval
|
||||
{
|
||||
RYML_ASSERT(m_tree->has_val(id));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->has_val(id));
|
||||
// some plain scalars such as '...' and '---' must not
|
||||
// appear at 0-indentation
|
||||
const csubstr val = m_tree->val(id);
|
||||
@@ -245,9 +245,9 @@ void Emitter<Writer>::_do_visit_flow_sl(id_type node, id_type depth, id_type ile
|
||||
{
|
||||
const bool prev_flow = m_flow;
|
||||
m_flow = true;
|
||||
RYML_ASSERT(!m_tree->is_stream(node));
|
||||
RYML_ASSERT(m_tree->is_container(node) || m_tree->is_doc(node));
|
||||
RYML_ASSERT(m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node)));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->is_stream(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_container(node) || m_tree->is_doc(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node)));
|
||||
if(C4_UNLIKELY(depth > m_opts.max_depth()))
|
||||
_RYML_CB_ERR(m_tree->callbacks(), "max depth exceeded");
|
||||
|
||||
@@ -273,7 +273,7 @@ void Emitter<Writer>::_do_visit_flow_sl(id_type node, id_type depth, id_type ile
|
||||
}
|
||||
else if(m_tree->is_container(node))
|
||||
{
|
||||
RYML_ASSERT(m_tree->is_map(node) || m_tree->is_seq(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_map(node) || m_tree->is_seq(node));
|
||||
|
||||
bool spc = false; // write a space
|
||||
|
||||
@@ -451,9 +451,9 @@ void Emitter<Writer>::_do_visit_block_container(id_type node, id_type depth, id_
|
||||
template<class Writer>
|
||||
void Emitter<Writer>::_do_visit_block(id_type node, id_type depth, id_type ilevel, id_type do_indent)
|
||||
{
|
||||
RYML_ASSERT(!m_tree->is_stream(node));
|
||||
RYML_ASSERT(m_tree->is_container(node) || m_tree->is_doc(node));
|
||||
RYML_ASSERT(m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node)));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->is_stream(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_container(node) || m_tree->is_doc(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node)));
|
||||
if(C4_UNLIKELY(depth > m_opts.max_depth()))
|
||||
_RYML_CB_ERR(m_tree->callbacks(), "max depth exceeded");
|
||||
if(m_tree->is_doc(node))
|
||||
@@ -464,7 +464,7 @@ void Emitter<Writer>::_do_visit_block(id_type node, id_type depth, id_type ileve
|
||||
}
|
||||
else if(m_tree->is_container(node))
|
||||
{
|
||||
RYML_ASSERT(m_tree->is_map(node) || m_tree->is_seq(node));
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_map(node) || m_tree->is_seq(node));
|
||||
bool spc = false; // write a space
|
||||
bool nl = false; // write a newline
|
||||
if(m_tree->has_key(node))
|
||||
@@ -672,9 +672,9 @@ size_t Emitter<Writer>::_write_escaped_newlines(csubstr s, size_t i)
|
||||
this->Writer::_do_write('\n'); // write the newline again
|
||||
++i; // increase the outer loop counter!
|
||||
} while(i < s.len && s.str[i] == '\n');
|
||||
RYML_ASSERT(i > 0);
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), i > 0);
|
||||
--i;
|
||||
RYML_ASSERT(s.str[i] == '\n');
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), s.str[i] == '\n');
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -690,10 +690,10 @@ template<class Writer>
|
||||
size_t Emitter<Writer>::_write_indented_block(csubstr s, size_t i, id_type ilevel)
|
||||
{
|
||||
//_c4dbgpf("indblock@i={} rem=[{}]~~~\n{}~~~", i, s.sub(i).len, s.sub(i));
|
||||
RYML_ASSERT(i > 0);
|
||||
RYML_ASSERT(s.str[i-1] == '\n');
|
||||
RYML_ASSERT(i < s.len);
|
||||
RYML_ASSERT(s.str[i] == ' ' || s.str[i] == '\t' || s.str[i] == '\n');
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), i > 0);
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), s.str[i-1] == '\n');
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), i < s.len);
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), s.str[i] == ' ' || s.str[i] == '\t' || s.str[i] == '\n');
|
||||
again:
|
||||
size_t pos = s.find("\n ", i);
|
||||
if(pos == npos)
|
||||
@@ -725,7 +725,7 @@ again:
|
||||
template<class Writer>
|
||||
void Emitter<Writer>::_write_scalar_literal(csubstr s, id_type ilevel, bool explicit_key)
|
||||
{
|
||||
RYML_ASSERT(s.find("\r") == csubstr::npos);
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), s.find("\r") == csubstr::npos);
|
||||
if(explicit_key)
|
||||
this->Writer::_do_write("? ");
|
||||
csubstr trimmed = s.trimr('\n');
|
||||
@@ -773,7 +773,7 @@ void Emitter<Writer>::_write_scalar_folded(csubstr s, id_type ilevel, bool expli
|
||||
{
|
||||
if(explicit_key)
|
||||
this->Writer::_do_write("? ");
|
||||
RYML_ASSERT(s.find("\r") == csubstr::npos);
|
||||
_RYML_CB_ASSERT(m_tree->callbacks(), s.find("\r") == csubstr::npos);
|
||||
csubstr trimmed = s.trimr('\n');
|
||||
const size_t numnewlines_at_end = s.len - trimmed.len;
|
||||
const bool is_newline_only = (trimmed.len == 0 && (s.len > 0));
|
||||
|
||||
@@ -1007,7 +1007,7 @@ public:
|
||||
NodeRef(Tree *t, id_type id, csubstr seed_key) : m_tree(t), m_id(id), m_seed(seed_key) {}
|
||||
NodeRef(std::nullptr_t) : m_tree(nullptr), m_id(NONE), m_seed() {}
|
||||
|
||||
inline void _clear_seed() { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = NONE; }
|
||||
inline void _clear_seed() { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = npos; }
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ struct ParserState
|
||||
void reset_after_push()
|
||||
{
|
||||
node_id = NONE;
|
||||
indref = NONE;
|
||||
indref = npos;
|
||||
more_indented = false;
|
||||
++level;
|
||||
has_children = false;
|
||||
|
||||
@@ -24,7 +24,9 @@ void write(c4::yml::NodeRef *n, std::vector<V, Alloc> const& vec)
|
||||
template<class V, class Alloc>
|
||||
bool read(c4::yml::ConstNodeRef const& n, std::vector<V, Alloc> *vec)
|
||||
{
|
||||
vec->resize(n.num_children());
|
||||
C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
|
||||
vec->resize(static_cast<size_t>(n.num_children()));
|
||||
C4_SUPPRESS_WARNING_GCC_POP
|
||||
size_t pos = 0;
|
||||
for(ConstNodeRef const child : n)
|
||||
child >> (*vec)[pos++];
|
||||
@@ -36,7 +38,9 @@ bool read(c4::yml::ConstNodeRef const& n, std::vector<V, Alloc> *vec)
|
||||
template<class Alloc>
|
||||
bool read(c4::yml::ConstNodeRef const& n, std::vector<bool, Alloc> *vec)
|
||||
{
|
||||
vec->resize(n.num_children());
|
||||
C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
|
||||
vec->resize(static_cast<size_t>(n.num_children()));
|
||||
C4_SUPPRESS_WARNING_GCC_POP
|
||||
size_t pos = 0;
|
||||
bool tmp = {};
|
||||
for(ConstNodeRef const child : n)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace c4 {
|
||||
namespace yml {
|
||||
|
||||
static_assert(std::is_same<std::underlying_type<decltype(c4::yml::npos)>::type, size_t>::value, "invalid type");
|
||||
static_assert(std::is_same<std::underlying_type<decltype(c4::yml::NONE)>::type, size_t>::value, "invalid type");
|
||||
static_assert(std::is_same<std::underlying_type<decltype(c4::yml::NONE)>::type, id_type>::value, "invalid type");
|
||||
static_assert(size_t(c4::yml::npos) == ((size_t)-1), "invalid value"); // some debuggers show the wrong value...
|
||||
static_assert(size_t(c4::yml::NONE) == ((size_t)-1), "invalid value"); // some debuggers show the wrong value...
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ TEST(github, 277)
|
||||
#endif
|
||||
ConstNodeRef root = tree.crootref();
|
||||
ASSERT_TRUE(root["B"].is_map());
|
||||
size_t num_childs = root["B"].num_children();
|
||||
size_t child = 0;
|
||||
id_type num_childs = root["B"].num_children();
|
||||
id_type child = 0;
|
||||
ASSERT_EQ(num_childs, 3);
|
||||
for (const auto node : root["B"].children())
|
||||
{
|
||||
@@ -54,7 +54,7 @@ TEST(github, 277)
|
||||
// test whether the tree is corrupted
|
||||
test_invariants(tree);
|
||||
child = num_childs;
|
||||
for (size_t n = tree.last_child(root["B"].id()); n != NONE; n = tree.prev_sibling(n))
|
||||
for (id_type n = tree.last_child(root["B"].id()); n != NONE; n = tree.prev_sibling(n))
|
||||
{
|
||||
ASSERT_NE(child, 0);
|
||||
EXPECT_EQ(tree.key(n), csubstr(keys[child - 1], 1));
|
||||
|
||||
@@ -487,7 +487,7 @@ void test_invariants(ConstNodeRef const& n)
|
||||
EXPECT_EQ(n.parent().num_children() > 1, n.has_other_siblings());
|
||||
EXPECT_TRUE(n.parent().has_child(n));
|
||||
EXPECT_EQ(n.parent().num_children(), n.num_siblings());
|
||||
EXPECT_EQ(n.parent().num_children(), n.num_other_siblings()+1u);
|
||||
EXPECT_EQ(n.parent().num_children(), n.num_other_siblings()+id_type(1));
|
||||
// doc parent must be a seq and a stream
|
||||
if(n.is_doc())
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ void test_ints()
|
||||
ASSERT_EQ(parsed["bin"].num_children(), values.size());
|
||||
ASSERT_EQ(parsed["oct"].num_children(), values.size());
|
||||
ASSERT_EQ(parsed["versions"].num_children(), 4u);
|
||||
size_t pos = 0;
|
||||
id_type pos = 0;
|
||||
for(I val : values)
|
||||
{
|
||||
I out = notval(val);
|
||||
@@ -86,7 +86,7 @@ void test_ints()
|
||||
ASSERT_EQ(parsed["bin"].num_children(), values.size());
|
||||
ASSERT_EQ(parsed["oct"].num_children(), values.size());
|
||||
ASSERT_EQ(parsed["versions"].num_children(), 4u);
|
||||
size_t pos = 0;
|
||||
id_type pos = 0;
|
||||
for(I val : values)
|
||||
{
|
||||
I out = notval(val);
|
||||
|
||||
@@ -381,19 +381,17 @@ TEST(Parser, filename_and_buffer_are_stored)
|
||||
|
||||
TEST(Parser, estimate_tree_capacity)
|
||||
{
|
||||
Parser::handler_type evt_handler = {};
|
||||
Parser parser(&evt_handler);
|
||||
EXPECT_EQ(2, parser.estimate_tree_capacity(R"([])"));
|
||||
EXPECT_EQ(2, parser.estimate_tree_capacity(R"([a])"));
|
||||
EXPECT_EQ(3, parser.estimate_tree_capacity(R"([a, b])"));
|
||||
EXPECT_EQ(4, parser.estimate_tree_capacity(R"([a, b, c])"));
|
||||
EXPECT_EQ(5, parser.estimate_tree_capacity(R"([a, b, c, d])"));
|
||||
EXPECT_EQ(2, parser.estimate_tree_capacity(R"({})"));
|
||||
EXPECT_EQ(2, parser.estimate_tree_capacity(R"({a: 0})"));
|
||||
EXPECT_EQ(3, parser.estimate_tree_capacity(R"({a: 0, b: 1})"));
|
||||
EXPECT_EQ(4, parser.estimate_tree_capacity(R"({a: 0, b: 1, c: 2})"));
|
||||
EXPECT_EQ(5, parser.estimate_tree_capacity(R"({a: 0, b: 1, c: 2, d: 3})"));
|
||||
EXPECT_EQ(9, parser.estimate_tree_capacity(R"(- {a: 0, b: 1, c: 2, d: 3}
|
||||
EXPECT_EQ(2, estimate_tree_capacity(R"([])"));
|
||||
EXPECT_EQ(2, estimate_tree_capacity(R"([a])"));
|
||||
EXPECT_EQ(3, estimate_tree_capacity(R"([a, b])"));
|
||||
EXPECT_EQ(4, estimate_tree_capacity(R"([a, b, c])"));
|
||||
EXPECT_EQ(5, estimate_tree_capacity(R"([a, b, c, d])"));
|
||||
EXPECT_EQ(2, estimate_tree_capacity(R"({})"));
|
||||
EXPECT_EQ(2, estimate_tree_capacity(R"({a: 0})"));
|
||||
EXPECT_EQ(3, estimate_tree_capacity(R"({a: 0, b: 1})"));
|
||||
EXPECT_EQ(4, estimate_tree_capacity(R"({a: 0, b: 1, c: 2})"));
|
||||
EXPECT_EQ(5, estimate_tree_capacity(R"({a: 0, b: 1, c: 2, d: 3})"));
|
||||
EXPECT_EQ(9, estimate_tree_capacity(R"(- {a: 0, b: 1, c: 2, d: 3}
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
@@ -444,8 +442,8 @@ TEST(parse_in_place, overloads)
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
size_t e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (size_t)NONE);
|
||||
id_type e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (id_type)NONE);
|
||||
parse_in_place(src1_, &tree, e);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
@@ -456,8 +454,8 @@ TEST(parse_in_place, overloads)
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
size_t e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (size_t)NONE);
|
||||
id_type e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (id_type)NONE);
|
||||
parse_in_place("src1", src1_, &tree, e);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
@@ -493,27 +491,27 @@ TEST(parse_in_arena, overloads)
|
||||
Tree tree = parse_in_arena(src1);
|
||||
EXPECT_EQ(tree["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
}
|
||||
{
|
||||
Tree tree = parse_in_arena("src1", src1);
|
||||
EXPECT_EQ(tree["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
}
|
||||
{
|
||||
Tree tree;
|
||||
parse_in_arena(src1, &tree);
|
||||
EXPECT_EQ(tree["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
}
|
||||
{
|
||||
Tree tree;
|
||||
parse_in_arena("src1", src1, &tree);
|
||||
EXPECT_EQ(tree["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
}
|
||||
{
|
||||
Tree tree = parse_in_arena(src2);
|
||||
@@ -521,16 +519,16 @@ TEST(parse_in_arena, overloads)
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
size_t e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (size_t)NONE);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
id_type e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (id_type)NONE);
|
||||
parse_in_arena(src1, &tree, e);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
EXPECT_EQ(tree["e"]["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
}
|
||||
{
|
||||
Tree tree = parse_in_arena("src2", src2);
|
||||
@@ -538,16 +536,16 @@ TEST(parse_in_arena, overloads)
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
size_t e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (size_t)NONE);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
id_type e = tree.find_child(tree.root_id(), "e");
|
||||
ASSERT_NE(e, (id_type)NONE);
|
||||
parse_in_arena("src1", src1, &tree, e);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
EXPECT_EQ(tree["e"]["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
}
|
||||
{
|
||||
Tree tree = parse_in_arena(src2);
|
||||
@@ -555,14 +553,14 @@ TEST(parse_in_arena, overloads)
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
parse_in_arena(src1, tree["e"]);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
EXPECT_EQ(tree["e"]["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
}
|
||||
{
|
||||
Tree tree = parse_in_arena("src2", src2);
|
||||
@@ -570,14 +568,14 @@ TEST(parse_in_arena, overloads)
|
||||
EXPECT_EQ(tree["e"].is_map(), true);
|
||||
EXPECT_EQ(tree["e"].has_children(), false);
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
parse_in_arena("src1", src1, tree["e"]);
|
||||
EXPECT_EQ(tree["c"].val(), "d");
|
||||
EXPECT_EQ(tree["e"].has_children(), true);
|
||||
EXPECT_EQ(tree["e"]["a"].val(), "b");
|
||||
EXPECT_FALSE(tree.arena().empty());
|
||||
EXPECT_NE(tree.arena().find(src1), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src2), (size_t)npos);
|
||||
EXPECT_NE(tree.arena().find(src1), npos);
|
||||
EXPECT_NE(tree.arena().find(src2), npos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1984,7 +1982,7 @@ TEST_F(ParseToMapFlowTest, map_flow__to__map_flow__root)
|
||||
{
|
||||
NodeRef dst = dst_map_flow.rootref();
|
||||
parse_in_arena(to_csubstr(map_flow), dst);
|
||||
const Tree expected = parse_in_arena("map: flow\nyes: it is\n");
|
||||
const Tree expected = parse_in_arena("{map: flow, yes: it is}");
|
||||
_c4dbg_tree("expected", expected);
|
||||
_c4dbg_tree("actual", dst_map_flow);
|
||||
test_compare(dst_map_flow, expected);
|
||||
@@ -1994,7 +1992,7 @@ TEST_F(ParseToMapFlowTest, map_flow__to__map_flow__new_child)
|
||||
{
|
||||
NodeRef dst = dst_map_flow.rootref().append_child({KEY, "dst"});
|
||||
parse_in_arena(to_csubstr(map_flow), dst);
|
||||
const Tree expected = parse_in_arena("dst:\n map: flow\n yes: it is\n");
|
||||
const Tree expected = parse_in_arena("{dst: {map: flow, yes: it is}}");
|
||||
_c4dbg_tree("expected", expected);
|
||||
_c4dbg_tree("actual", dst_map_flow);
|
||||
test_compare(dst_map_flow, expected);
|
||||
|
||||
@@ -93,7 +93,7 @@ TEST(simple_seq, deeply_nested_to_cover_parse_stack_resizes)
|
||||
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[0, 1, 2, 3, 4, 5, 6, 7]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
||||
)";
|
||||
Tree t = parse_in_arena(yaml);
|
||||
size_t id = t.root_id();
|
||||
id_type id = t.root_id();
|
||||
while(t.has_children(id))
|
||||
id = t.first_child(id);
|
||||
ASSERT_TRUE(t.cref(id).has_parent());
|
||||
|
||||
@@ -495,23 +495,23 @@ reference_list:
|
||||
)";
|
||||
|
||||
Tree tree;
|
||||
const size_t root_id = tree.root_id();
|
||||
const id_type root_id = tree.root_id();
|
||||
tree.to_map(root_id);
|
||||
|
||||
const size_t anchor_list_id = tree.append_child(root_id);
|
||||
const id_type anchor_list_id = tree.append_child(root_id);
|
||||
tree.to_seq(anchor_list_id, "anchor_objects");
|
||||
|
||||
const size_t anchor_map0 = tree.append_child(anchor_list_id);
|
||||
const id_type anchor_map0 = tree.append_child(anchor_list_id);
|
||||
tree.to_map(anchor_map0);
|
||||
tree.set_val_anchor(anchor_map0, "id001");
|
||||
|
||||
const size_t anchor_elem0 = tree.append_child(anchor_map0);
|
||||
const id_type anchor_elem0 = tree.append_child(anchor_map0);
|
||||
tree.to_keyval(anchor_elem0, "name", "a_name");
|
||||
|
||||
const size_t ref_list_id = tree.append_child(root_id);
|
||||
const id_type ref_list_id = tree.append_child(root_id);
|
||||
tree.to_seq(ref_list_id, "reference_list");
|
||||
|
||||
const size_t elem0_id = tree.append_child(ref_list_id);
|
||||
const id_type elem0_id = tree.append_child(ref_list_id);
|
||||
tree.set_val_ref(elem0_id, "id001");
|
||||
|
||||
EXPECT_EQ(emitrs_yaml<std::string>(tree), expected_yaml);
|
||||
|
||||
@@ -13,25 +13,26 @@ namespace c4 {
|
||||
namespace yml {
|
||||
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG("-Wuseless-cast")
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
using istack = stack<int, N>;
|
||||
using ip = int const*;
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void to_large(istack<N> *s)
|
||||
{
|
||||
size_t sz = 3u * N;
|
||||
id_type sz = 3u * N;
|
||||
s->reserve(sz);
|
||||
EXPECT_NE(s->m_stack, s->m_buf);
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void fill_to_large(istack<N> *s)
|
||||
{
|
||||
size_t sz = 3u * N;
|
||||
id_type sz = 3u * N;
|
||||
s->reserve(sz);
|
||||
for(int i = 0, e = (int)sz; i < e; ++i)
|
||||
s->push(i);
|
||||
@@ -43,18 +44,18 @@ void fill_to_large(istack<N> *s)
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_stack_small_vs_large()
|
||||
{
|
||||
istack<N> s;
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
s.push(static_cast<int>(i));
|
||||
EXPECT_EQ(s.size(), i+1);
|
||||
}
|
||||
EXPECT_EQ(s.size(), N);
|
||||
EXPECT_EQ(s.m_stack, s.m_buf);
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
EXPECT_EQ(s.top(N-1-i), static_cast<int>(i));
|
||||
}
|
||||
@@ -63,7 +64,7 @@ void test_stack_small_vs_large()
|
||||
EXPECT_EQ(s.top(), static_cast<int>(N));
|
||||
EXPECT_EQ(s.pop(), static_cast<int>(N));
|
||||
EXPECT_NE(s.m_stack, s.m_buf);
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
EXPECT_EQ(s.top(N-1-i), static_cast<int>(i));
|
||||
}
|
||||
@@ -82,13 +83,13 @@ TEST(stack, small_vs_large)
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_copy_ctor()
|
||||
{
|
||||
istack<N> src;
|
||||
|
||||
// small
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
src.push((int)i);
|
||||
}
|
||||
@@ -103,7 +104,7 @@ void test_copy_ctor()
|
||||
}
|
||||
|
||||
// large
|
||||
for(size_t i = 0; i < 2*N; ++i)
|
||||
for(id_type i = 0; i < 2*N; ++i)
|
||||
{
|
||||
src.push((int)i); // large
|
||||
}
|
||||
@@ -131,34 +132,34 @@ TEST(stack, copy_ctor)
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_move_ctor()
|
||||
{
|
||||
istack<N> src;
|
||||
|
||||
// small
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
src.push((int)i);
|
||||
}
|
||||
EXPECT_EQ(src.m_stack, src.m_buf);
|
||||
ip b = src.begin();
|
||||
size_t sz = src.size();
|
||||
id_type sz = src.size();
|
||||
{
|
||||
istack<N> dst(std::move(src));
|
||||
EXPECT_EQ(dst.size(), sz);
|
||||
EXPECT_EQ(dst.m_stack, dst.m_buf);
|
||||
EXPECT_NE(dst.m_stack, b);
|
||||
EXPECT_EQ(src.size(), size_t(0));
|
||||
EXPECT_EQ(src.size(), id_type(0));
|
||||
EXPECT_EQ((ip)src.begin(), src.m_buf);
|
||||
EXPECT_NE((ip)dst.begin(), b);
|
||||
}
|
||||
EXPECT_EQ(src.size(), size_t(0));
|
||||
EXPECT_EQ(src.size(), id_type(0));
|
||||
EXPECT_EQ(src.capacity(), N);
|
||||
EXPECT_EQ(src.m_stack, src.m_buf);
|
||||
|
||||
// redo
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
src.push((int)i);
|
||||
}
|
||||
@@ -166,7 +167,7 @@ void test_move_ctor()
|
||||
EXPECT_EQ(src.capacity(), N);
|
||||
EXPECT_EQ(src.m_stack, src.m_buf);
|
||||
// large
|
||||
for(size_t i = 0; i < 2*N; ++i)
|
||||
for(id_type i = 0; i < 2*N; ++i)
|
||||
{
|
||||
src.push((int)i); // large
|
||||
}
|
||||
@@ -180,7 +181,7 @@ void test_move_ctor()
|
||||
EXPECT_NE(dst.m_stack, dst.m_buf);
|
||||
EXPECT_EQ(dst.m_stack, b);
|
||||
EXPECT_EQ(src.capacity(), N);
|
||||
EXPECT_EQ(src.size(), size_t(0));
|
||||
EXPECT_EQ(src.size(), id_type(0));
|
||||
EXPECT_EQ((ip)src.begin(), src.m_buf);
|
||||
EXPECT_EQ((ip)dst.begin(), b);
|
||||
}
|
||||
@@ -198,19 +199,19 @@ TEST(stack, move_ctor)
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_copy_assign()
|
||||
{
|
||||
istack<N> dst;
|
||||
istack<N> srcs; // small
|
||||
istack<N> srcl; // large
|
||||
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
srcs.push((int)i); // small
|
||||
srcl.push((int)i); // large
|
||||
}
|
||||
for(size_t i = 0; i < 2*N; ++i)
|
||||
for(id_type i = 0; i < 2*N; ++i)
|
||||
{
|
||||
srcl.push((int)i); // large
|
||||
}
|
||||
@@ -257,17 +258,17 @@ TEST(stack, copy_assign)
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_move_assign()
|
||||
{
|
||||
istack<N> srcs, srcl, dst;
|
||||
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
for(id_type i = 0; i < N; ++i)
|
||||
{
|
||||
srcs.push((int)i); // small
|
||||
srcl.push((int)i); // large
|
||||
}
|
||||
for(size_t i = 0; i < 2*N; ++i)
|
||||
for(id_type i = 0; i < 2*N; ++i)
|
||||
{
|
||||
srcl.push((int)i); // large
|
||||
}
|
||||
@@ -275,7 +276,7 @@ void test_move_assign()
|
||||
EXPECT_NE(srcl.m_stack, srcl.m_buf);
|
||||
|
||||
ip bs = srcs.begin()/*, bl = srcl.begin()*/;
|
||||
size_t szs = srcs.size(), szl = srcl.size();
|
||||
id_type szs = srcs.size(), szl = srcl.size();
|
||||
|
||||
for(int i = 0; i < 10; ++i)
|
||||
{
|
||||
@@ -287,7 +288,7 @@ void test_move_assign()
|
||||
dst = std::move(srcs);
|
||||
EXPECT_TRUE(srcs.empty());
|
||||
EXPECT_FALSE(dst.empty());
|
||||
EXPECT_EQ(srcs.size(), size_t(0));
|
||||
EXPECT_EQ(srcs.size(), id_type(0));
|
||||
EXPECT_EQ(srcs.capacity(), N);
|
||||
EXPECT_EQ(dst.size(), szs);
|
||||
EXPECT_EQ(dst.m_stack, dst.m_buf);
|
||||
@@ -309,7 +310,7 @@ void test_move_assign()
|
||||
dst = std::move(srcl);
|
||||
EXPECT_TRUE(srcl.empty());
|
||||
EXPECT_FALSE(dst.empty());
|
||||
EXPECT_EQ(srcl.size(), size_t(0));
|
||||
EXPECT_EQ(srcl.size(), id_type(0));
|
||||
EXPECT_EQ(srcl.capacity(), N);
|
||||
EXPECT_EQ(dst.size(), szl);
|
||||
EXPECT_NE(dst.m_stack, dst.m_buf);
|
||||
@@ -332,7 +333,7 @@ TEST(stack, move_assign)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_default_ctor()
|
||||
{
|
||||
CallbacksTester td;
|
||||
@@ -349,7 +350,7 @@ TEST(stack, callbacks_default_ctor)
|
||||
test_callbacks_default_ctor<128>();
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_ctor()
|
||||
{
|
||||
CallbacksTester td;
|
||||
@@ -370,7 +371,7 @@ TEST(stack, callbacks_ctor)
|
||||
//-----------------------------------------------------------------------------
|
||||
// copy ctor
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_copy_ctor_small()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -397,7 +398,7 @@ void test_callbacks_copy_ctor_small()
|
||||
}
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_copy_ctor_large_unfilled()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -422,7 +423,7 @@ void test_callbacks_copy_ctor_large_unfilled()
|
||||
}
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_copy_ctor_large_filled()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -475,7 +476,7 @@ TEST(stack, callbacks_copy_ctor_large_filled)
|
||||
//-----------------------------------------------------------------------------
|
||||
// copy ctor
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_move_ctor_small()
|
||||
{
|
||||
CallbacksTester ts;
|
||||
@@ -493,7 +494,7 @@ void test_callbacks_move_ctor_small()
|
||||
EXPECT_EQ(ts.num_allocs, nbefore);
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_move_ctor_large_unfilled()
|
||||
{
|
||||
CallbacksTester ts;
|
||||
@@ -512,7 +513,7 @@ void test_callbacks_move_ctor_large_unfilled()
|
||||
EXPECT_EQ(ts.num_allocs, nbefore);
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_move_ctor_large_filled()
|
||||
{
|
||||
CallbacksTester ts;
|
||||
@@ -559,7 +560,7 @@ TEST(stack, callbacks_move_ctor_large_filled)
|
||||
//-----------------------------------------------------------------------------
|
||||
// copy assign
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_copy_assign_to_empty()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -590,7 +591,7 @@ TEST(stack, callbacks_copy_assign_to_empty)
|
||||
test_callbacks_copy_assign_to_empty<128>();
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_copy_assign_to_nonempty()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -681,7 +682,7 @@ TEST(stack, callbacks_move_assign_to_empty)
|
||||
test_callbacks_move_assign_to_empty<128>();
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_callbacks_move_assign_to_nonempty()
|
||||
{
|
||||
CallbacksTester ts("src");
|
||||
@@ -732,7 +733,7 @@ TEST(stack, callbacks_move_assign_to_nonempty)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<size_t N>
|
||||
template<id_type N>
|
||||
void test_reserve()
|
||||
{
|
||||
{
|
||||
@@ -777,7 +778,7 @@ TEST(stack, reserve_capacity)
|
||||
}
|
||||
|
||||
|
||||
template<size_t N, int NumTimes>
|
||||
template<id_type N, int NumTimes>
|
||||
void grow_to_large__push()
|
||||
{
|
||||
istack<N> s;
|
||||
@@ -792,7 +793,7 @@ void grow_to_large__push()
|
||||
}
|
||||
for(int i = 0; i < NumTimes * ni; ++i)
|
||||
{
|
||||
EXPECT_EQ(s.bottom((size_t)i), i);
|
||||
EXPECT_EQ(s.bottom((id_type)i), i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,7 +804,7 @@ TEST(stack, push_to_large_twice)
|
||||
grow_to_large__push<32, 8>();
|
||||
}
|
||||
|
||||
template<size_t N, int NumTimes>
|
||||
template<id_type N, int NumTimes>
|
||||
void grow_to_large__push_top()
|
||||
{
|
||||
istack<N> s;
|
||||
@@ -821,7 +822,7 @@ void grow_to_large__push_top()
|
||||
}
|
||||
for(int i = 0; i < NumTimes * ni; ++i)
|
||||
{
|
||||
EXPECT_EQ(s.bottom((size_t)i), i);
|
||||
EXPECT_EQ(s.bottom((id_type)i), i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ struct Scalar
|
||||
OptionalScalar tag = {};
|
||||
NodeType flags = {};
|
||||
inline operator bool() const { if(anchor || tag) { RYML_ASSERT(scalar); } return scalar.was_set; }
|
||||
void add_key_props(Tree *tree, size_t node) const
|
||||
void add_key_props(Tree *tree, id_type node) const
|
||||
{
|
||||
if(ref)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ struct Scalar
|
||||
tree->_add_flags(node, flags & KEY_STYLE);
|
||||
}
|
||||
}
|
||||
void add_val_props(Tree *tree, size_t node) const
|
||||
void add_val_props(Tree *tree, id_type node) const
|
||||
{
|
||||
if(ref)
|
||||
{
|
||||
@@ -303,7 +303,7 @@ bool compare_events(csubstr ref_evts, csubstr emt_evts, bool ignore_container_st
|
||||
|
||||
void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
{
|
||||
struct ParseLevel { size_t tree_node; };
|
||||
struct ParseLevel { id_type tree_node; };
|
||||
detail::stack<ParseLevel> m_stack = {};
|
||||
Tree &C4_RESTRICT tree = *tree_;
|
||||
size_t linenum = 0; (void)linenum;
|
||||
@@ -367,7 +367,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
ASSERT_FALSE(key);
|
||||
ASSERT_TRUE(curr);
|
||||
_nfo_logf("seq[{}]: adding child", top.tree_node);
|
||||
size_t node = tree.append_child(top.tree_node);
|
||||
id_type node = tree.append_child(top.tree_node);
|
||||
NodeType as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE;
|
||||
_nfo_logf("seq[{}]: child={} val='{}' as_doc=", top.tree_node, node, curr.scalar.maybe_get(), as_doc.type_str());
|
||||
tree.to_val(node, curr.filtered_scalar(&tree), as_doc);
|
||||
@@ -385,7 +385,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
else
|
||||
{
|
||||
_nfo_logf("map[{}]: adding child", top.tree_node);
|
||||
size_t node = tree.append_child(top.tree_node);
|
||||
id_type node = tree.append_child(top.tree_node);
|
||||
NodeType as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE;
|
||||
_nfo_logf("map[{}]: child={} key='{}' val='{}' as_doc={}", top.tree_node, node, key.scalar.maybe_get(), curr.scalar.maybe_get(), as_doc.type_str());
|
||||
tree.to_keyval(node, key.filtered_scalar(&tree), curr.filtered_scalar(&tree), as_doc);
|
||||
@@ -411,7 +411,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
{
|
||||
_nfo_logf("node[{}] is seq: set {} as val ref", top.tree_node, alias);
|
||||
ASSERT_FALSE(key);
|
||||
size_t node = tree.append_child(top.tree_node);
|
||||
id_type node = tree.append_child(top.tree_node);
|
||||
tree.to_val(node, alias);
|
||||
tree.set_val_ref(node, alias);
|
||||
}
|
||||
@@ -420,7 +420,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
if(key)
|
||||
{
|
||||
_nfo_logf("node[{}] is map and key '{}' is pending: set {} as val ref", top.tree_node, key.scalar.maybe_get(), alias);
|
||||
size_t node = tree.append_child(top.tree_node);
|
||||
id_type node = tree.append_child(top.tree_node);
|
||||
tree.to_keyval(node, key.filtered_scalar(&tree), alias);
|
||||
key.add_key_props(&tree, node);
|
||||
tree.set_val_ref(node, alias);
|
||||
@@ -459,7 +459,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
_nfo_log("seq is block");
|
||||
}
|
||||
parse_anchor_and_tag(more_tokens, &anchor, &tag);
|
||||
size_t node = tree.root_id();
|
||||
id_type node = tree.root_id();
|
||||
if(m_stack.empty())
|
||||
{
|
||||
_nfo_log("stack was empty, set root to SEQ");
|
||||
@@ -469,9 +469,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t parent = m_stack.top().tree_node;
|
||||
id_type parent = m_stack.top().tree_node;
|
||||
_nfo_logf("stack was not empty. parent={}", parent);
|
||||
ASSERT_NE(parent, (size_t)NONE);
|
||||
ASSERT_NE(parent, (id_type)NONE);
|
||||
if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent)))
|
||||
{
|
||||
_nfo_logf("set node to parent={}, add DOC", parent);
|
||||
@@ -534,7 +534,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
_nfo_log("map is block");
|
||||
}
|
||||
parse_anchor_and_tag(more_tokens, &anchor, &tag);
|
||||
size_t node = tree.root_id();
|
||||
id_type node = tree.root_id();
|
||||
if(m_stack.empty())
|
||||
{
|
||||
_nfo_log("stack was empty, set root to MAP");
|
||||
@@ -544,9 +544,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t parent = m_stack.top().tree_node;
|
||||
id_type parent = m_stack.top().tree_node;
|
||||
_nfo_logf("stack was not empty. parent={}", parent);
|
||||
ASSERT_NE(parent, (size_t)NONE);
|
||||
ASSERT_NE(parent, (id_type)NONE);
|
||||
if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent)))
|
||||
{
|
||||
_nfo_logf("set node to parent={}, add DOC", parent);
|
||||
@@ -592,7 +592,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
else if(line.begins_with("-SEQ"))
|
||||
{
|
||||
_nfo_logf("popping SEQ, empty={}", m_stack.empty());
|
||||
size_t node;
|
||||
id_type node;
|
||||
if(m_stack.empty())
|
||||
node = tree.root_id();
|
||||
else
|
||||
@@ -602,7 +602,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
else if(line.begins_with("-MAP"))
|
||||
{
|
||||
_nfo_logf("popping MAP, empty={}", m_stack.empty());
|
||||
size_t node;
|
||||
id_type node;
|
||||
if(m_stack.empty())
|
||||
node = tree.root_id();
|
||||
else
|
||||
@@ -613,7 +613,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
{
|
||||
csubstr rem = line.stripl("+DOC").triml(' ');
|
||||
_nfo_logf("pushing DOC: {}", rem);
|
||||
size_t node = tree.root_id();
|
||||
id_type node = tree.root_id();
|
||||
auto is_sep = rem.first_of_any("---\n", "--- ", "---\r") || rem.ends_with("---");
|
||||
ASSERT_EQ(key, false); // for the key to exist, the parent must exist and be a map
|
||||
if(m_stack.empty())
|
||||
@@ -660,9 +660,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_)
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t parent = m_stack.top().tree_node;
|
||||
id_type parent = m_stack.top().tree_node;
|
||||
_nfo_logf("add DOC to parent={}", parent);
|
||||
ASSERT_NE(parent, (size_t)NONE);
|
||||
ASSERT_NE(parent, (id_type)NONE);
|
||||
node = tree.append_child(parent);
|
||||
_nfo_logf("child DOC={}", node);
|
||||
tree.to_doc(node);
|
||||
|
||||
@@ -15,12 +15,12 @@ struct EventsEmitter
|
||||
std::string tagbuf;
|
||||
Tree const* C4_RESTRICT m_tree;
|
||||
EventsEmitter(Tree const& tree, substr buf_) : buf(buf_), pos(), m_tree(&tree) {}
|
||||
void emit_tag(csubstr tag, size_t node);
|
||||
void emit_tag(csubstr tag, id_type node);
|
||||
void emit_scalar(csubstr val, char openchar);
|
||||
void emit_key_anchor_tag(size_t node);
|
||||
void emit_val_anchor_tag(size_t node);
|
||||
void emit_events(size_t node);
|
||||
void emit_doc(size_t node);
|
||||
void emit_key_anchor_tag(id_type node);
|
||||
void emit_val_anchor_tag(id_type node);
|
||||
void emit_events(id_type node);
|
||||
void emit_doc(id_type node);
|
||||
void emit_events();
|
||||
template<size_t N>
|
||||
C4_ALWAYS_INLINE void pr(const char (&s)[N])
|
||||
@@ -81,11 +81,11 @@ inline char _ev_scalar_code_val(NodeType t)
|
||||
{
|
||||
return _ev_scalar_code(t & VAL_STYLE);
|
||||
}
|
||||
inline char _ev_scalar_code_key(Tree const* p, size_t node)
|
||||
inline char _ev_scalar_code_key(Tree const* p, id_type node)
|
||||
{
|
||||
return _ev_scalar_code(p->_p(node)->m_type & KEY_STYLE);
|
||||
}
|
||||
inline char _ev_scalar_code_val(Tree const* p, size_t node)
|
||||
inline char _ev_scalar_code_val(Tree const* p, id_type node)
|
||||
{
|
||||
return _ev_scalar_code(p->_p(node)->m_type & VAL_STYLE);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void EventsEmitter::emit_scalar(csubstr val, char openchar)
|
||||
pr(val.sub(prev)); // print remaining portion
|
||||
}
|
||||
|
||||
void EventsEmitter::emit_tag(csubstr tag, size_t node)
|
||||
void EventsEmitter::emit_tag(csubstr tag, id_type node)
|
||||
{
|
||||
size_t tagsize = m_tree->resolve_tag(to_substr(tagbuf), tag, node);
|
||||
if(tagsize)
|
||||
@@ -185,7 +185,7 @@ void EventsEmitter::emit_tag(csubstr tag, size_t node)
|
||||
}
|
||||
}
|
||||
|
||||
void EventsEmitter::emit_key_anchor_tag(size_t node)
|
||||
void EventsEmitter::emit_key_anchor_tag(id_type node)
|
||||
{
|
||||
if(m_tree->has_key_anchor(node))
|
||||
{
|
||||
@@ -199,7 +199,7 @@ void EventsEmitter::emit_key_anchor_tag(size_t node)
|
||||
}
|
||||
}
|
||||
|
||||
void EventsEmitter::emit_val_anchor_tag(size_t node)
|
||||
void EventsEmitter::emit_val_anchor_tag(id_type node)
|
||||
{
|
||||
if(m_tree->has_val_anchor(node))
|
||||
{
|
||||
@@ -213,7 +213,7 @@ void EventsEmitter::emit_val_anchor_tag(size_t node)
|
||||
}
|
||||
}
|
||||
|
||||
void EventsEmitter::emit_events(size_t node)
|
||||
void EventsEmitter::emit_events(id_type node)
|
||||
{
|
||||
if(m_tree->has_key(node))
|
||||
{
|
||||
@@ -264,7 +264,7 @@ void EventsEmitter::emit_events(size_t node)
|
||||
pr((m_tree->type(node) & CONTAINER_STYLE_FLOW) ? csubstr("+MAP {}") : csubstr("+MAP"));
|
||||
emit_val_anchor_tag(node);
|
||||
pr('\n');
|
||||
for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child))
|
||||
for(id_type child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child))
|
||||
emit_events(child);
|
||||
pr("-MAP\n");
|
||||
}
|
||||
@@ -273,13 +273,13 @@ void EventsEmitter::emit_events(size_t node)
|
||||
pr((m_tree->type(node) & CONTAINER_STYLE_FLOW) ? csubstr("+SEQ []") : csubstr("+SEQ"));
|
||||
emit_val_anchor_tag(node);
|
||||
pr('\n');
|
||||
for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child))
|
||||
for(id_type child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child))
|
||||
emit_events(child);
|
||||
pr("-SEQ\n");
|
||||
}
|
||||
}
|
||||
|
||||
void EventsEmitter::emit_doc(size_t node)
|
||||
void EventsEmitter::emit_doc(id_type node)
|
||||
{
|
||||
if(m_tree->type(node) == NOTYPE)
|
||||
return;
|
||||
@@ -308,9 +308,9 @@ void EventsEmitter::emit_events()
|
||||
pr("+STR\n");
|
||||
if(!m_tree->empty())
|
||||
{
|
||||
size_t root = m_tree->root_id();
|
||||
id_type root = m_tree->root_id();
|
||||
if(m_tree->is_stream(root))
|
||||
for(size_t node = m_tree->first_child(root); node != NONE; node = m_tree->next_sibling(node))
|
||||
for(id_type node = m_tree->first_child(root); node != NONE; node = m_tree->next_sibling(node))
|
||||
emit_doc(node);
|
||||
else
|
||||
emit_doc(root);
|
||||
|
||||
@@ -812,14 +812,14 @@ TEST(tags, parsing)
|
||||
TEST(tags, setting)
|
||||
{
|
||||
Tree t;
|
||||
size_t rid = t.root_id();
|
||||
id_type rid = t.root_id();
|
||||
t.to_map(rid);
|
||||
t.set_val_tag(rid, "!valtag");
|
||||
EXPECT_EQ(t.val_tag(rid), "!valtag");
|
||||
|
||||
// a keymap
|
||||
{
|
||||
size_t child = t.append_child(rid);
|
||||
id_type child = t.append_child(rid);
|
||||
t.to_seq(child, "key2");
|
||||
t.set_key_tag(child, "!keytag");
|
||||
t.set_val_tag(child, "!valtag2");
|
||||
@@ -832,7 +832,7 @@ TEST(tags, setting)
|
||||
|
||||
// a keyseq
|
||||
{
|
||||
size_t child = t.append_child(rid);
|
||||
id_type child = t.append_child(rid);
|
||||
t.to_seq(child, "key2");
|
||||
t.set_key_tag(child, "!keytag");
|
||||
t.set_val_tag(child, "!valtag2");
|
||||
@@ -845,7 +845,7 @@ TEST(tags, setting)
|
||||
|
||||
// a keyval
|
||||
{
|
||||
size_t child = t.append_child(rid);
|
||||
id_type child = t.append_child(rid);
|
||||
t.to_keyval(child, "key", "val");
|
||||
t.set_key_tag(child, "!keytag");
|
||||
t.set_val_tag(child, "!valtag");
|
||||
@@ -859,9 +859,9 @@ TEST(tags, setting)
|
||||
|
||||
// a val
|
||||
{
|
||||
size_t seqid = t[1].id();
|
||||
id_type seqid = t[1].id();
|
||||
ASSERT_TRUE(t.is_seq(seqid));
|
||||
size_t child = t.append_child(seqid);
|
||||
id_type child = t.append_child(seqid);
|
||||
t.to_val(child, "val");
|
||||
t.set_val_tag(child, "!valtag");
|
||||
EXPECT_FALSE(t.has_key(child));
|
||||
@@ -874,17 +874,17 @@ TEST(tags, setting)
|
||||
TEST(tags, errors)
|
||||
{
|
||||
Tree t = parse_in_arena("{key: val, keymap: {}, keyseq: [val]}");
|
||||
size_t keyval = t["keyval"].id();
|
||||
size_t keymap = t["keymap"].id();
|
||||
size_t keyseq = t["keyseq"].id();
|
||||
size_t val = t["keyseq"][0].id();
|
||||
size_t empty_keyval = t.append_child(keymap);
|
||||
size_t empty_val = t.append_child(keyseq);
|
||||
id_type keyval = t["keyval"].id();
|
||||
id_type keymap = t["keymap"].id();
|
||||
id_type keyseq = t["keyseq"].id();
|
||||
id_type val = t["keyseq"][0].id();
|
||||
id_type empty_keyval = t.append_child(keymap);
|
||||
id_type empty_val = t.append_child(keyseq);
|
||||
|
||||
ASSERT_NE(keyval, (size_t)npos);
|
||||
ASSERT_NE(keymap, (size_t)npos);
|
||||
ASSERT_NE(keyseq, (size_t)npos);
|
||||
ASSERT_NE(val, (size_t)npos);
|
||||
ASSERT_NE(keyval, (id_type)npos);
|
||||
ASSERT_NE(keymap, (id_type)npos);
|
||||
ASSERT_NE(keyseq, (id_type)npos);
|
||||
ASSERT_NE(val, (id_type)npos);
|
||||
|
||||
// cannot get key tag in a node that does not have a key tag
|
||||
EXPECT_FALSE(t.has_key_tag(empty_keyval));
|
||||
@@ -955,14 +955,14 @@ key: val
|
||||
keymap: {}
|
||||
keyseq: [val]
|
||||
)");
|
||||
size_t keyval = t["keyval"].id();
|
||||
size_t keymap = t["keymap"].id();
|
||||
size_t keyseq = t["keyseq"].id();
|
||||
size_t val = t["keyseq"][0].id();
|
||||
ASSERT_NE(keyval, (size_t)npos);
|
||||
ASSERT_NE(keymap, (size_t)npos);
|
||||
ASSERT_NE(keyseq, (size_t)npos);
|
||||
ASSERT_NE(val, (size_t)npos);
|
||||
id_type keyval = t["keyval"].id();
|
||||
id_type keymap = t["keymap"].id();
|
||||
id_type keyseq = t["keyseq"].id();
|
||||
id_type val = t["keyseq"][0].id();
|
||||
ASSERT_NE(keyval, (id_type)npos);
|
||||
ASSERT_NE(keymap, (id_type)npos);
|
||||
ASSERT_NE(keyseq, (id_type)npos);
|
||||
ASSERT_NE(val, (id_type)npos);
|
||||
|
||||
// without leading mark
|
||||
t.set_key_tag(keyseq, "keytag");
|
||||
|
||||
@@ -1363,9 +1363,9 @@ TEST(Tree, is_stream)
|
||||
Tree t = parse_in_arena(R"(---
|
||||
foo: bar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t keyval_id = t.first_child(doc_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type keyval_id = t.first_child(doc_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef keyval = t.ref(keyval_id);
|
||||
@@ -1403,10 +1403,10 @@ foo: bar
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t keyval_id = t.first_child(doc_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type keyval_id = t.first_child(doc_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef keyval = t.ref(keyval_id);
|
||||
@@ -1489,13 +1489,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -1578,13 +1578,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -1667,13 +1667,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -1756,13 +1756,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -1845,13 +1845,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -1933,13 +1933,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2022,13 +2022,13 @@ seq: [foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2107,15 +2107,15 @@ TEST(Tree, has_key_tag)
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t keyvalnotag_id = t.last_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t valnotag_id = t.last_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type keyvalnotag_id = t.last_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type valnotag_id = t.last_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2210,15 +2210,15 @@ seq: !seqtag [!footag foo, bar]
|
||||
---
|
||||
a scalar
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t keyvalnotag_id = t.last_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t valnotag_id = t.last_child(seq_id);
|
||||
const size_t docval_id = t.last_child(stream_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type keyvalnotag_id = t.last_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type valnotag_id = t.last_child(seq_id);
|
||||
const id_type docval_id = t.last_child(stream_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2311,14 +2311,14 @@ TEST(Tree, has_key_anchor)
|
||||
&mapanchor map: {&keyvalanchor foo: bar, anchor: none}
|
||||
&seqanchor seq: [&valanchor foo, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t keyvalnoanchor_id = t.last_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t valnoanchor_id = t.last_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type keyvalnoanchor_id = t.last_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type valnoanchor_id = t.last_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2404,14 +2404,14 @@ map: &mapanchor {foo: &keyvalanchor bar, anchor: none}
|
||||
seq: &seqanchor [&valanchor foo, bar]
|
||||
...)");
|
||||
_c4dbg_tree(t);
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t keyvalnoanchor_id = t.last_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t valnoanchor_id = t.last_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type keyvalnoanchor_id = t.last_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type valnoanchor_id = t.last_child(seq_id);
|
||||
ConstNodeRef stream = t.cref(stream_id);
|
||||
ConstNodeRef doc = t.cref(doc_id);
|
||||
ConstNodeRef map = t.cref(map_id);
|
||||
@@ -2502,14 +2502,14 @@ map: &mapanchor {foo: &keyvalanchor bar, anchor: none}
|
||||
&seqanchor seq: [&valanchor foo, bar]
|
||||
...)");
|
||||
_c4dbg_tree(t);
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t keyvalnoanchor_id = t.last_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const size_t valnoanchor_id = t.last_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type keyvalnoanchor_id = t.last_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
const id_type valnoanchor_id = t.last_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2591,12 +2591,12 @@ TEST(Tree, is_key_ref)
|
||||
*mapref : {foo: bar, notag: none}
|
||||
*seqref : [foo, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.cref(stream_id);
|
||||
ConstNodeRef doc = t.cref(doc_id);
|
||||
ConstNodeRef map = t.cref(map_id);
|
||||
@@ -2665,12 +2665,12 @@ TEST(Tree, is_val_ref)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2743,12 +2743,12 @@ TEST(Tree, is_ref)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -2817,9 +2817,9 @@ TEST(Tree, is_key_quoted)
|
||||
"quoted": foo
|
||||
notquoted: bar
|
||||
...)");
|
||||
const size_t map_id = t.first_child(t.root_id());
|
||||
const size_t quoted_id = t.first_child(map_id);
|
||||
const size_t notquoted_id = t.last_child(map_id);
|
||||
const id_type map_id = t.first_child(t.root_id());
|
||||
const id_type quoted_id = t.first_child(map_id);
|
||||
const id_type notquoted_id = t.last_child(map_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
ConstNodeRef quoted = t.ref(quoted_id);
|
||||
ConstNodeRef notquoted = t.ref(notquoted_id);
|
||||
@@ -2864,9 +2864,9 @@ TEST(Tree, is_val_quoted)
|
||||
"quoted": "foo"
|
||||
notquoted: bar
|
||||
...)");
|
||||
const size_t map_id = t.first_child(t.root_id());
|
||||
const size_t quoted_id = t.first_child(map_id);
|
||||
const size_t notquoted_id = t.last_child(map_id);
|
||||
const id_type map_id = t.first_child(t.root_id());
|
||||
const id_type quoted_id = t.first_child(map_id);
|
||||
const id_type notquoted_id = t.last_child(map_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
ConstNodeRef quoted = t.ref(quoted_id);
|
||||
ConstNodeRef notquoted = t.ref(notquoted_id);
|
||||
@@ -2921,14 +2921,14 @@ quoted5: 'foo'
|
||||
'quoted6': 'foo'
|
||||
notquoted: bar
|
||||
...)");
|
||||
const size_t map_id = t.first_child(t.root_id());
|
||||
const size_t quoted1_id = t.find_child(map_id, "quoted1");
|
||||
const size_t quoted2_id = t.find_child(map_id, "quoted2");
|
||||
const size_t quoted3_id = t.find_child(map_id, "quoted3");
|
||||
const size_t quoted4_id = t.find_child(map_id, "quoted4");
|
||||
const size_t quoted5_id = t.find_child(map_id, "quoted5");
|
||||
const size_t quoted6_id = t.find_child(map_id, "quoted6");
|
||||
const size_t notquoted_id = t.last_child(map_id);
|
||||
const id_type map_id = t.first_child(t.root_id());
|
||||
const id_type quoted1_id = t.find_child(map_id, "quoted1");
|
||||
const id_type quoted2_id = t.find_child(map_id, "quoted2");
|
||||
const id_type quoted3_id = t.find_child(map_id, "quoted3");
|
||||
const id_type quoted4_id = t.find_child(map_id, "quoted4");
|
||||
const id_type quoted5_id = t.find_child(map_id, "quoted5");
|
||||
const id_type quoted6_id = t.find_child(map_id, "quoted6");
|
||||
const id_type notquoted_id = t.last_child(map_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
ConstNodeRef quoted1 = t.ref(quoted1_id);
|
||||
ConstNodeRef quoted2 = t.ref(quoted2_id);
|
||||
@@ -3007,12 +3007,12 @@ TEST(Tree, parent_is_seq)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
ConstNodeRef keyval = t.ref(keyval_id);
|
||||
@@ -3065,12 +3065,12 @@ TEST(Tree, parent_is_map)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
ConstNodeRef keyval = t.ref(keyval_id);
|
||||
@@ -3124,12 +3124,12 @@ TEST(Tree, has_parent)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -3189,12 +3189,12 @@ TEST(Tree, num_children)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -3238,12 +3238,12 @@ TEST(Tree, child)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const size_t val_id = t.first_child(seq_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
const id_type val_id = t.first_child(seq_id);
|
||||
ConstNodeRef stream = t.ref(stream_id);
|
||||
ConstNodeRef doc = t.ref(doc_id);
|
||||
ConstNodeRef map = t.ref(map_id);
|
||||
@@ -3259,9 +3259,9 @@ seq: &seq [*valref, bar]
|
||||
EXPECT_EQ(t.child(stream_id, 0), doc_id);
|
||||
EXPECT_EQ(t.child(doc_id, 0), map_id);
|
||||
EXPECT_EQ(t.child(map_id, 0), keyval_id);
|
||||
EXPECT_EQ(t.child(keyval_id, 0), (size_t)NONE);
|
||||
EXPECT_EQ(t.child(keyval_id, 0), (id_type)NONE);
|
||||
EXPECT_EQ(t.child(seq_id, 0), val_id);
|
||||
EXPECT_EQ(t.child(val_id, 0), (size_t)NONE);
|
||||
EXPECT_EQ(t.child(val_id, 0), (id_type)NONE);
|
||||
EXPECT_EQ(stream.child(0).id(), t.child(stream_id, 0));
|
||||
EXPECT_EQ(doc.child(0).id(), t.child(doc_id, 0));
|
||||
EXPECT_EQ(map.child(0).id(), t.child(map_id, 0));
|
||||
@@ -3287,20 +3287,20 @@ TEST(Tree, find_child_by_name)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t keyval_id = t.first_child(map_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type keyval_id = t.first_child(map_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
ConstNodeRef doc = t.cref(doc_id);
|
||||
ConstNodeRef map = t.cref(map_id);
|
||||
NodeRef mdoc = t.ref(doc_id);
|
||||
NodeRef mmap = t.ref(map_id);
|
||||
EXPECT_EQ(t.find_child(doc_id, "map"), map_id);
|
||||
EXPECT_EQ(t.find_child(doc_id, "seq"), seq_id);
|
||||
EXPECT_EQ(t.find_child(doc_id, "..."), (size_t)NONE);
|
||||
EXPECT_EQ(t.find_child(doc_id, "..."), (id_type)NONE);
|
||||
EXPECT_EQ(t.find_child(map_id, "foo"), keyval_id);
|
||||
EXPECT_EQ(t.find_child(map_id, "bar"), (size_t)NONE);
|
||||
EXPECT_EQ(t.find_child(map_id, "bar"), (id_type)NONE);
|
||||
EXPECT_EQ(doc.find_child("map").id(), t.find_child(doc_id, "map"));
|
||||
EXPECT_EQ(doc.find_child("seq").id(), t.find_child(doc_id, "seq"));
|
||||
EXPECT_EQ(doc.find_child("...").id(), t.find_child(doc_id, "..."));
|
||||
@@ -3324,10 +3324,10 @@ TEST(Tree, find_sibling_by_name)
|
||||
map: {foo: *keyvalref, notag: none}
|
||||
seq: &seq [*valref, bar]
|
||||
...)");
|
||||
const size_t stream_id = t.root_id();
|
||||
const size_t doc_id = t.first_child(stream_id);
|
||||
const size_t map_id = t.first_child(doc_id);
|
||||
const size_t seq_id = t.last_child(doc_id);
|
||||
const id_type stream_id = t.root_id();
|
||||
const id_type doc_id = t.first_child(stream_id);
|
||||
const id_type map_id = t.first_child(doc_id);
|
||||
const id_type seq_id = t.last_child(doc_id);
|
||||
ConstNodeRef map = t.cref(map_id);
|
||||
ConstNodeRef seq = t.cref(seq_id);
|
||||
NodeRef mmap = t.ref(map_id);
|
||||
@@ -3335,10 +3335,10 @@ seq: &seq [*valref, bar]
|
||||
//
|
||||
EXPECT_EQ(t.find_sibling(map_id, "map"), map_id);
|
||||
EXPECT_EQ(t.find_sibling(map_id, "seq"), seq_id);
|
||||
EXPECT_EQ(t.find_sibling(map_id, "..."), (size_t)NONE);
|
||||
EXPECT_EQ(t.find_sibling(map_id, "..."), (id_type)NONE);
|
||||
EXPECT_EQ(t.find_sibling(seq_id, "map"), map_id);
|
||||
EXPECT_EQ(t.find_sibling(seq_id, "seq"), seq_id);
|
||||
EXPECT_EQ(t.find_sibling(seq_id, "..."), (size_t)NONE);
|
||||
EXPECT_EQ(t.find_sibling(seq_id, "..."), (id_type)NONE);
|
||||
//
|
||||
EXPECT_TRUE(t.has_sibling(map_id, "map"));
|
||||
EXPECT_TRUE(t.has_sibling(map_id, "seq"));
|
||||
@@ -3607,31 +3607,31 @@ a:
|
||||
|
||||
auto lp = t.lookup_path("x");
|
||||
EXPECT_FALSE(lp);
|
||||
EXPECT_EQ(lp.target, (size_t)NONE);
|
||||
EXPECT_EQ(lp.closest, (size_t)NONE);
|
||||
EXPECT_EQ(lp.target, (id_type)NONE);
|
||||
EXPECT_EQ(lp.closest, (id_type)NONE);
|
||||
EXPECT_EQ(lp.resolved(), "");
|
||||
EXPECT_EQ(lp.unresolved(), "x");
|
||||
lp = t.lookup_path("a.x");
|
||||
EXPECT_FALSE(lp);
|
||||
EXPECT_EQ(lp.target, (size_t)NONE);
|
||||
EXPECT_EQ(lp.target, (id_type)NONE);
|
||||
EXPECT_EQ(lp.closest, 1);
|
||||
EXPECT_EQ(lp.resolved(), "a");
|
||||
EXPECT_EQ(lp.unresolved(), "x");
|
||||
lp = t.lookup_path("a.b.x");
|
||||
EXPECT_FALSE(lp);
|
||||
EXPECT_EQ(lp.target, (size_t)NONE);
|
||||
EXPECT_EQ(lp.target, (id_type)NONE);
|
||||
EXPECT_EQ(lp.closest, 2);
|
||||
EXPECT_EQ(lp.resolved(), "a.b");
|
||||
EXPECT_EQ(lp.unresolved(), "x");
|
||||
lp = t.lookup_path("a.c.x");
|
||||
EXPECT_FALSE(lp);
|
||||
EXPECT_EQ(lp.target, (size_t)NONE);
|
||||
EXPECT_EQ(lp.target, (id_type)NONE);
|
||||
EXPECT_EQ(lp.closest, 3);
|
||||
EXPECT_EQ(lp.resolved(), "a.c");
|
||||
EXPECT_EQ(lp.unresolved(), "x");
|
||||
|
||||
size_t sz = t.size();
|
||||
EXPECT_EQ(t.lookup_path("x").target, (size_t)NONE);
|
||||
id_type sz = t.size();
|
||||
EXPECT_EQ(t.lookup_path("x").target, (id_type)NONE);
|
||||
EXPECT_EQ(t.lookup_path_or_modify("x", "x"), sz);
|
||||
EXPECT_EQ(t.lookup_path("x").target, sz);
|
||||
EXPECT_EQ(t.val(sz), "x");
|
||||
@@ -3641,7 +3641,7 @@ a:
|
||||
EXPECT_EQ(t.val(sz), "z");
|
||||
|
||||
sz = t.size();
|
||||
EXPECT_EQ(t.lookup_path("a.x").target, (size_t)NONE);
|
||||
EXPECT_EQ(t.lookup_path("a.x").target, (id_type)NONE);
|
||||
EXPECT_EQ(t.lookup_path_or_modify("x", "a.x"), sz);
|
||||
EXPECT_EQ(t.lookup_path("a.x").target, sz);
|
||||
EXPECT_EQ(t.val(sz), "x");
|
||||
@@ -3651,7 +3651,7 @@ a:
|
||||
EXPECT_EQ(t.val(sz), "z");
|
||||
|
||||
sz = t.size();
|
||||
EXPECT_EQ(t.lookup_path("a.c.x").target, (size_t)NONE);
|
||||
EXPECT_EQ(t.lookup_path("a.c.x").target, (id_type)NONE);
|
||||
EXPECT_EQ(t.lookup_path_or_modify("x", "a.c.x"), sz);
|
||||
EXPECT_EQ(t.lookup_path("a.c.x").target, sz);
|
||||
EXPECT_EQ(t.val(sz), "x");
|
||||
@@ -3679,11 +3679,11 @@ TEST(Tree, lookup_path_or_modify)
|
||||
t.rootref() |= MAP;
|
||||
csubstr bigpath = "newmap.newseq[0].newmap.newseq[0].first";
|
||||
auto result = t.lookup_path(bigpath);
|
||||
EXPECT_EQ(result.target, (size_t)NONE);
|
||||
EXPECT_EQ(result.closest, (size_t)NONE);
|
||||
EXPECT_EQ(result.target, (id_type)NONE);
|
||||
EXPECT_EQ(result.closest, (id_type)NONE);
|
||||
EXPECT_EQ(result.resolved(), "");
|
||||
EXPECT_EQ(result.unresolved(), bigpath);
|
||||
size_t sz = t.lookup_path_or_modify("x", bigpath);
|
||||
id_type sz = t.lookup_path_or_modify("x", bigpath);
|
||||
EXPECT_EQ(t.lookup_path(bigpath).target, sz);
|
||||
EXPECT_EQ(t.val(sz), "x");
|
||||
EXPECT_EQ(t["newmap"]["newseq"].num_children(), 1u);
|
||||
@@ -3693,7 +3693,7 @@ TEST(Tree, lookup_path_or_modify)
|
||||
EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"].num_children(), 1u);
|
||||
EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0].is_map(), true);
|
||||
EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0]["first"].val(), "x");
|
||||
size_t sz2 = t.lookup_path_or_modify("y", bigpath);
|
||||
id_type sz2 = t.lookup_path_or_modify("y", bigpath);
|
||||
EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0]["first"].val(), "y");
|
||||
EXPECT_EQ(sz2, sz);
|
||||
EXPECT_EQ(t.lookup_path(bigpath).target, sz);
|
||||
@@ -4057,7 +4057,7 @@ doc3
|
||||
---
|
||||
doc4
|
||||
)");
|
||||
size_t ir = t.root_id();
|
||||
id_type ir = t.root_id();
|
||||
ASSERT_EQ(t.num_children(ir), 5u);
|
||||
ASSERT_TRUE(t.is_stream(ir));
|
||||
EXPECT_EQ(t.child(ir, 0), t.doc(0));
|
||||
@@ -4124,9 +4124,9 @@ TEST(Tree, add_tag_directives)
|
||||
TagDirective{csubstr("!e!"), csubstr("!ey-"), 0u},
|
||||
};
|
||||
Tree t;
|
||||
auto check_up_to = [&](size_t num)
|
||||
auto check_up_to = [&](id_type num)
|
||||
{
|
||||
size_t pos = 0;
|
||||
id_type pos = 0;
|
||||
EXPECT_EQ(t.num_tag_directives(), num);
|
||||
for(TagDirective const& d : t.tag_directives())
|
||||
{
|
||||
|
||||
@@ -89,12 +89,12 @@ int main(int argc, const char *argv[])
|
||||
}
|
||||
{
|
||||
TS(tree_reserve);
|
||||
size_t cap;
|
||||
yml::id_type cap;
|
||||
{
|
||||
TS(estimate_capacity);
|
||||
cap = yml::estimate_tree_capacity(to_csubstr(contents));
|
||||
}
|
||||
fprintf(stderr, "reserving capacity=%zu\n", cap);
|
||||
fprintf(stderr, "reserving capacity=%zu\n", (size_t)cap);
|
||||
tree.reserve(cap);
|
||||
}
|
||||
{
|
||||
|
||||
@@ -107,7 +107,7 @@ int main(int argc, const char *argv[])
|
||||
std::string emit_events_from_tree(csubstr filename, substr filecontents)
|
||||
{
|
||||
Tree tree(create_custom_callbacks());
|
||||
tree.reserve(filecontents.count('\n'));
|
||||
tree.reserve(estimate_tree_capacity(filecontents));
|
||||
parse_in_place(filename, filecontents, &tree);
|
||||
return emit_events_from_tree<std::string>(tree);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user