2020-07-13 18:18:04 +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-07-13 18:18:04 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#if TOML_WINDOWS_COMPAT
|
|
|
|
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_DISABLE_WARNINGS;
|
2020-09-30 13:14:25 +00:00
|
|
|
#include <windows.h>
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_ENABLE_WARNINGS;
|
2020-07-18 12:10:19 +00:00
|
|
|
|
2020-07-13 18:18:04 +00:00
|
|
|
TEST_CASE("windows compat")
|
|
|
|
{
|
|
|
|
static constexpr auto toml_text = R"(
|
|
|
|
[library]
|
|
|
|
name = "toml++"
|
|
|
|
authors = ["Mark Gillard <mark.gillard@outlook.com.au>"]
|
2020-07-18 12:10:19 +00:00
|
|
|
free = true
|
|
|
|
|
2020-07-13 18:18:04 +00:00
|
|
|
[dependencies]
|
|
|
|
cpp = 17
|
|
|
|
)"sv;
|
|
|
|
|
|
|
|
auto res = toml::parse(toml_text, L"kek.toml");
|
2021-10-26 13:49:23 +00:00
|
|
|
#if !TOML_EXCEPTIONS
|
|
|
|
REQUIRE(res.succeeded());
|
|
|
|
#endif
|
2020-07-13 18:18:04 +00:00
|
|
|
toml::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
|
2020-07-18 12:10:19 +00:00
|
|
|
REQUIRE(tbl.get("library") != nullptr);
|
|
|
|
CHECK(tbl.get("library") == tbl.get("library"sv));
|
|
|
|
CHECK(tbl.get("library") == tbl.get("library"s));
|
2020-07-13 18:18:04 +00:00
|
|
|
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));
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl.get(L"library") == tbl.get("library"));
|
2020-07-13 18:18:04 +00:00
|
|
|
|
|
|
|
// 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<std::wstring>() == 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
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl[L"library"][L"name"] == "toml++"sv);
|
|
|
|
CHECK(tbl[L"library"][L"name"] == "toml++"s);
|
|
|
|
CHECK(tbl[L"library"][L"name"] == "toml++");
|
2020-07-13 18:18:04 +00:00
|
|
|
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");
|
2020-07-18 12:10:19 +00:00
|
|
|
REQUIRE(tbl.contains("foo"));
|
2020-07-13 18:18:04 +00:00
|
|
|
REQUIRE(tbl.contains(L"foo"));
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["foo"] == "bar");
|
2020-07-13 18:18:04 +00:00
|
|
|
tbl.insert_or_assign(L"foo", L"kek");
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["foo"] == "kek");
|
2020-07-13 18:18:04 +00:00
|
|
|
tbl.erase(L"foo");
|
2020-07-18 12:10:19 +00:00
|
|
|
REQUIRE(!tbl.contains("foo"));
|
2020-07-13 18:18:04 +00:00
|
|
|
REQUIRE(!tbl.contains(L"foo"));
|
2020-07-18 12:10:19 +00:00
|
|
|
|
|
|
|
// windows types
|
|
|
|
CHECK(tbl[L"library"][L"free"].value<BOOL>() == 1);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<BOOL>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<SHORT>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<INT>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<LONG>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<INT_PTR>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<LONG_PTR>() == 17);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<USHORT>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<UINT>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<ULONG>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<UINT_PTR>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<ULONG_PTR>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<WORD>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<DWORD>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<DWORD32>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<DWORD64>() == 17u);
|
|
|
|
CHECK(tbl[L"dependencies"][L"cpp"].value<DWORDLONG>() == 17u);
|
2020-07-13 18:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TOML_WINDOWS_COMPAT
|