// This file is a part of toml++ and is subject to the the terms of the MIT license. // Copyright (c) Mark Gillard // See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. // SPDX-License-Identifier: MIT #include "tests.h" #if TOML_ENABLE_WINDOWS_COMPAT TOML_DISABLE_WARNINGS; #include TOML_ENABLE_WARNINGS; TEST_CASE("windows compat") { static constexpr auto toml_text = R"( [library] name = "toml++" authors = ["Mark Gillard "] free = true [dependencies] cpp = 17 )"sv; auto res = toml::parse(toml_text, L"kek.toml"); #if !TOML_EXCEPTIONS REQUIRE(res.succeeded()); #endif table& tbl = res; // source paths REQUIRE(tbl.source().path != nullptr); CHECK(*tbl.source().path == "kek.toml"sv); CHECK(tbl.source().wide_path().has_value()); CHECK(tbl.source().wide_path().value() == L"kek.toml"sv); // direct lookups from tables REQUIRE(tbl.get("library") != nullptr); CHECK(tbl.get("library") == tbl.get("library"sv)); CHECK(tbl.get("library") == tbl.get("library"s)); CHECK(tbl.get(L"library") != nullptr); CHECK(tbl.get(L"library") == tbl.get(L"library"sv)); CHECK(tbl.get(L"library") == tbl.get(L"library"s)); CHECK(tbl.get(L"library") == tbl.get("library")); // node-view lookups CHECK(tbl[L"library"].node() != nullptr); CHECK(tbl[L"library"].node() == tbl.get(L"library")); // value queries REQUIRE(tbl[L"library"][L"name"].as_string() != nullptr); CHECK(tbl[L"library"][L"name"].value() == L"toml++"s); CHECK(tbl[L"library"][L"name"].value_or(L""sv) == L"toml++"s); CHECK(tbl[L"library"][L"name"].value_or(L""s) == L"toml++"s); CHECK(tbl[L"library"][L"name"].value_or(L"") == L"toml++"s); // node-view comparisons CHECK(tbl[L"library"][L"name"] == "toml++"sv); CHECK(tbl[L"library"][L"name"] == "toml++"s); CHECK(tbl[L"library"][L"name"] == "toml++"); CHECK(tbl[L"library"][L"name"] == L"toml++"sv); CHECK(tbl[L"library"][L"name"] == L"toml++"s); CHECK(tbl[L"library"][L"name"] == L"toml++"); // table manipulation tbl.insert(L"foo", L"bar"); REQUIRE(tbl.contains("foo")); REQUIRE(tbl.contains(L"foo")); CHECK(tbl["foo"] == "bar"); tbl.insert_or_assign(L"foo", L"kek"); CHECK(tbl["foo"] == "kek"); tbl.erase(L"foo"); REQUIRE(!tbl.contains("foo")); REQUIRE(!tbl.contains(L"foo")); // windows types CHECK(tbl[L"library"][L"free"].value() == 1); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); CHECK(tbl[L"dependencies"][L"cpp"].value() == 17u); } #endif // TOML_ENABLE_WINDOWS_COMPAT