summaryrefslogtreecommitdiff
path: root/tomlplusplus/tests/manipulating_parse_result.cpp
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
commit0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch)
treef2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/tests/manipulating_parse_result.cpp
parentb85e90fc3480da0e6a48da73201a0b22488cc650 (diff)
parent1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff)
downloadProject-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/manipulating_parse_result.cpp')
-rw-r--r--tomlplusplus/tests/manipulating_parse_result.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/tomlplusplus/tests/manipulating_parse_result.cpp b/tomlplusplus/tests/manipulating_parse_result.cpp
new file mode 100644
index 0000000000..c0ef4bea66
--- /dev/null
+++ b/tomlplusplus/tests/manipulating_parse_result.cpp
@@ -0,0 +1,115 @@
+// This file is a part of toml++ and is subject to the the terms of the MIT license.
+// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
+// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
+// SPDX-License-Identifier: MIT
+
+#include "tests.hpp"
+
+#if !TOML_EXCEPTIONS
+
+TEST_CASE("parse_result - good parse")
+{
+ auto result = "key = true"_toml;
+ static_assert(std::is_same_v<decltype(result), parse_result>);
+ static_assert(!std::is_same_v<decltype(result), table>);
+
+ REQUIRE(result.succeeded());
+ REQUIRE(!result.failed());
+ REQUIRE(result);
+
+ REQUIRE(!result.table().empty());
+ REQUIRE(result.table().size() == 1);
+ REQUIRE(!std::move(result).table().empty());
+ REQUIRE(!static_cast<const parse_result&>(result).table().empty());
+
+ REQUIRE(!static_cast<table&>(result).empty());
+ REQUIRE(!static_cast<table&&>(result).empty());
+ REQUIRE(!static_cast<const table&>(result).empty());
+
+ auto& tbl = static_cast<table&>(result);
+ CHECK(tbl["key"sv]);
+ CHECK(result["key"sv]);
+ CHECK(&result["key"sv].ref<bool>() == &tbl["key"sv].ref<bool>());
+ CHECK(result.begin() == tbl.begin());
+ CHECK(result.end() == tbl.end());
+ CHECK(result.begin() != tbl.end());
+ CHECK(result.cbegin() == tbl.cbegin());
+ CHECK(result.cend() == tbl.cend());
+ CHECK(result.cbegin() != tbl.cend());
+
+ auto& cresult = static_cast<const parse_result&>(result);
+ auto& ctbl = static_cast<const table&>(cresult);
+ CHECK(cresult.begin() == ctbl.begin());
+ CHECK(cresult.end() == ctbl.end());
+ CHECK(cresult.begin() != ctbl.end());
+ CHECK(cresult.cbegin() == ctbl.cbegin());
+ CHECK(cresult.cend() == ctbl.cend());
+ CHECK(cresult.cbegin() != ctbl.cend());
+ CHECK(ctbl["key"sv]);
+ CHECK(cresult["key"sv]);
+ CHECK(&cresult["key"sv].ref<bool>() == &ctbl["key"sv].ref<bool>());
+
+ size_t tbl_iterations{};
+ for (auto&& [k, v] : tbl)
+ {
+ (void)k;
+ (void)v;
+ tbl_iterations++;
+ }
+ size_t result_iterations{};
+ for (auto& [k, v] : result)
+ {
+ (void)k;
+ (void)v;
+ result_iterations++;
+ }
+ size_t cresult_iterations{};
+ for (auto [k, v] : cresult)
+ {
+ (void)k;
+ (void)v;
+ cresult_iterations++;
+ }
+ CHECK(tbl_iterations == tbl.size());
+ CHECK(tbl_iterations == result_iterations);
+ CHECK(tbl_iterations == cresult_iterations);
+}
+
+TEST_CASE("parse_result - bad parse")
+{
+ auto result = "key = trUe"_toml;
+ static_assert(std::is_same_v<decltype(result), parse_result>);
+ static_assert(!std::is_same_v<decltype(result), table>);
+
+ REQUIRE(!result.succeeded());
+ REQUIRE(result.failed());
+ REQUIRE(!result);
+
+ CHECK(!result["key"sv]);
+ CHECK(result.begin() == decltype(result.begin()){});
+ CHECK(result.end() == decltype(result.end()){});
+ CHECK(result.cbegin() == decltype(result.cbegin()){});
+ CHECK(result.cend() == decltype(result.cend()){});
+
+ auto& cresult = static_cast<const parse_result&>(result);
+ CHECK(!result["key"sv]);
+ CHECK(cresult.begin() == decltype(cresult.begin()){});
+ CHECK(cresult.end() == decltype(cresult.end()){});
+ CHECK(cresult.cbegin() == decltype(cresult.cbegin()){});
+ CHECK(cresult.cend() == decltype(cresult.cend()){});
+
+ for (auto [k, v] : result)
+ {
+ (void)k;
+ (void)v;
+ FAIL("This code should not run");
+ }
+ for (auto [k, v] : cresult)
+ {
+ (void)k;
+ (void)v;
+ FAIL("This code should not run");
+ }
+}
+
+#endif //!TOML_EXCEPTIONS