2020-06-26 18:01:27 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-06-26 18:01:27 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-04-03 13:33:02 +00:00
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2020-07-20 14:13:52 +00:00
|
|
|
REQUIRE(!result.table().empty());
|
|
|
|
REQUIRE(result.table().size() == 1);
|
|
|
|
REQUIRE(!std::move(result).table().empty());
|
|
|
|
REQUIRE(!static_cast<const parse_result&>(result).table().empty());
|
2020-04-03 13:33:02 +00:00
|
|
|
|
|
|
|
REQUIRE(!static_cast<table&>(result).empty());
|
|
|
|
REQUIRE(!static_cast<table&&>(result).empty());
|
|
|
|
REQUIRE(!static_cast<const table&>(result).empty());
|
2021-10-26 13:49:23 +00:00
|
|
|
|
2020-04-03 13:33:02 +00:00
|
|
|
auto& tbl = static_cast<table&>(result);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["key"sv]);
|
|
|
|
CHECK(result["key"sv]);
|
|
|
|
CHECK(&result["key"sv].ref<bool>() == &tbl["key"sv].ref<bool>());
|
2020-04-03 13:33:02 +00:00
|
|
|
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);
|
2021-10-26 13:49:23 +00:00
|
|
|
auto& ctbl = static_cast<const table&>(cresult);
|
2020-04-03 13:33:02 +00:00
|
|
|
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());
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(ctbl["key"sv]);
|
|
|
|
CHECK(cresult["key"sv]);
|
|
|
|
CHECK(&cresult["key"sv].ref<bool>() == &ctbl["key"sv].ref<bool>());
|
2020-04-03 13:33:02 +00:00
|
|
|
|
|
|
|
size_t tbl_iterations{};
|
2020-06-08 15:31:23 +00:00
|
|
|
for (auto&& [k, v] : tbl)
|
2020-04-03 13:33:02 +00:00
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
(void)k;
|
|
|
|
(void)v;
|
2020-04-03 13:33:02 +00:00
|
|
|
tbl_iterations++;
|
|
|
|
}
|
|
|
|
size_t result_iterations{};
|
2020-06-08 15:31:23 +00:00
|
|
|
for (auto& [k, v] : result)
|
2020-04-03 13:33:02 +00:00
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
(void)k;
|
|
|
|
(void)v;
|
2020-04-03 13:33:02 +00:00
|
|
|
result_iterations++;
|
|
|
|
}
|
|
|
|
size_t cresult_iterations{};
|
2020-04-08 13:33:57 +00:00
|
|
|
for (auto [k, v] : cresult)
|
2020-04-03 13:33:02 +00:00
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
(void)k;
|
|
|
|
(void)v;
|
2020-04-03 13:33:02 +00:00
|
|
|
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);
|
|
|
|
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(!result["key"sv]);
|
2020-04-03 13:33:02 +00:00
|
|
|
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);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(!result["key"sv]);
|
2020-04-03 13:33:02 +00:00
|
|
|
CHECK(cresult.begin() == decltype(cresult.begin()){});
|
|
|
|
CHECK(cresult.end() == decltype(cresult.end()){});
|
|
|
|
CHECK(cresult.cbegin() == decltype(cresult.cbegin()){});
|
|
|
|
CHECK(cresult.cend() == decltype(cresult.cend()){});
|
|
|
|
|
2020-04-08 13:33:57 +00:00
|
|
|
for (auto [k, v] : result)
|
2020-04-03 13:33:02 +00:00
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
(void)k;
|
|
|
|
(void)v;
|
2020-04-03 13:33:02 +00:00
|
|
|
FAIL("This code should not run");
|
|
|
|
}
|
2020-04-08 13:33:57 +00:00
|
|
|
for (auto [k, v] : cresult)
|
2020-04-03 13:33:02 +00:00
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
(void)k;
|
|
|
|
(void)v;
|
2020-04-03 13:33:02 +00:00
|
|
|
FAIL("This code should not run");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //!TOML_EXCEPTIONS
|