From 261a86a99a0b2969e91fd538d556217240ec3aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20Gr=C3=B6n?= Date: Wed, 21 Aug 2024 13:24:37 +0300 Subject: [PATCH] Add sequence num_children checks to quickstart This is to give a hint that sequences also use children for iteration and counting --- samples/quickstart.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/samples/quickstart.cpp b/samples/quickstart.cpp index 06724aca..34283ff8 100644 --- a/samples/quickstart.cpp +++ b/samples/quickstart.cpp @@ -391,6 +391,7 @@ john: doe)"; CHECK(tree["bar"].is_seq()); CHECK(tree["bar"].has_key()); CHECK(tree["bar"].key() == "bar"); + CHECK(tree["bar"].num_children() == 2); // maps use string keys, seqs use index keys: CHECK(tree["bar"][0].val() == "2"); CHECK(tree["bar"][1].val() == "3"); @@ -593,6 +594,7 @@ john: doe)"; // In this case it is OK because those are static strings, located // in the executable's static section, and will outlive the tree. CHECK(root["foo"].val() == "says you"); + CHECK(root["bar"].num_children() == 2); CHECK(root["bar"][0].val() == "-2"); CHECK(root["bar"][1].val() == "-3"); CHECK(root["john"].val() == "ron"); @@ -1797,6 +1799,7 @@ void sample_parse_in_place() CHECK(root["bar"].is_seq()); CHECK(root["bar"].has_key()); CHECK(root["bar"].key() == "bar"); + CHECK(root["bar"].num_children() == 2); CHECK(root["bar"][0].val() == "2"); CHECK(root["bar"][1].val() == "3"); @@ -1849,6 +1852,7 @@ void sample_parse_in_arena() CHECK(root["bar"].is_seq()); CHECK(root["bar"].has_key()); CHECK(root["bar"].key() == "bar"); + CHECK(root["bar"].num_children() == 2); CHECK(root["bar"][0].val() == "2"); CHECK(root["bar"][1].val() == "3"); @@ -1906,6 +1910,7 @@ bar: [2, 3] CHECK(root["bar"].is_seq()); CHECK(root["bar"].has_key()); CHECK(root["bar"].key() == "bar"); + CHECK(root["bar"].num_children() == 2); CHECK(root["bar"][0].val() == "2"); CHECK(root["bar"][1].val() == "3"); CHECK(ryml::emitrs_yaml(tree) == R"(foo: 1 @@ -1926,6 +1931,7 @@ bar2: [22,32] CHECK(root["bar2"].is_seq()); CHECK(root["bar2"].has_key()); CHECK(root["bar2"].key() == "bar2"); + CHECK(root["bar2"].num_children() == 2); CHECK(root["bar2"][0].val() == "22"); CHECK(root["bar2"][1].val() == "32"); @@ -1951,6 +1957,7 @@ bar2: [22,32] coffee: Arabica )"); CHECK(root.is_seq()); + CHECK(root.num_children() == 4); CHECK(root[0].val() == "a"); CHECK(root[1].val() == "b"); CHECK(root[2].is_map());