diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:05 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:05 +0300 |
| commit | 0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch) | |
| tree | f2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/tests/using_iterators.cpp | |
| parent | b85e90fc3480da0e6a48da73201a0b22488cc650 (diff) | |
| parent | 1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff) | |
| download | Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.tar.gz Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.zip | |
Add 'tomlplusplus/' from commit '1c8b7466e4946fcc3bf20484c0e1d001202cca5a'
git-subtree-dir: tomlplusplus
git-subtree-mainline: b85e90fc3480da0e6a48da73201a0b22488cc650
git-subtree-split: 1c8b7466e4946fcc3bf20484c0e1d001202cca5a
Diffstat (limited to 'tomlplusplus/tests/using_iterators.cpp')
| -rw-r--r-- | tomlplusplus/tests/using_iterators.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tomlplusplus/tests/using_iterators.cpp b/tomlplusplus/tests/using_iterators.cpp new file mode 100644 index 0000000000..cbc4bbe636 --- /dev/null +++ b/tomlplusplus/tests/using_iterators.cpp @@ -0,0 +1,52 @@ +#include "tests.hpp" + +TOML_DISABLE_WARNINGS; +#include <algorithm> +TOML_ENABLE_WARNINGS; + +TEST_CASE("using iterators") +{ + constexpr auto data = R"(array=[1,"Foo",true] +string="Bar" +number=5)"sv; + parsing_should_succeed( + FILE_LINE_ARGS, + data, + [](auto&& tbl) + { + const auto tbl_begin = tbl.begin(); + const auto tbl_end = tbl.end(); + + auto count_table_lambda = [tbl_begin, tbl_end](node_type type) noexcept { + return std::count_if(tbl_begin, + tbl_end, + [type](const auto& pair) noexcept { return pair.second.type() == type; }); + }; + + CHECK(std::distance(tbl_begin, tbl_end) == 3); + CHECK(count_table_lambda(node_type::table) == 0); + CHECK(count_table_lambda(node_type::integer) == 1); + CHECK(count_table_lambda(node_type::string) == 1); + CHECK(std::next(tbl_begin, 3) == tbl_end); + + const auto arr_iter = + std::find_if(tbl_begin, tbl_end, [](const auto& pair) noexcept { return pair.second.is_array(); }); + + REQUIRE(arr_iter != tbl_end); + const auto& arr = arr_iter->second.as_array(); + const auto arr_begin = arr->begin(); + const auto arr_end = arr->end(); + + auto count_array_lambda = [arr_begin, arr_end](node_type type) noexcept { + return std::count_if(arr_begin, + arr_end, + [type](const auto& node) noexcept { return node.type() == type; }); + }; + + CHECK(std::distance(arr_begin, arr_end) == 3); + CHECK(count_array_lambda(node_type::table) == 0); + CHECK(count_array_lambda(node_type::integer) == 1); + CHECK(count_array_lambda(node_type::string) == 1); + CHECK(std::next(arr_begin, 2) != arr_end); + }); +} |
