File: windows_compat.cpp

package info (click to toggle)
tomlplusplus 3.3.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,184 kB
  • sloc: cpp: 35,145; ansic: 2,220; python: 983; makefile: 25; sh: 17
file content (97 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.h"

#if TOML_ENABLE_WINDOWS_COMPAT

TOML_DISABLE_WARNINGS;
#include <windows.h>
TOML_ENABLE_WARNINGS;

TEST_CASE("windows compat")
{
	static constexpr auto toml_text = R"(
		[library]
		name = "toml++"
		authors = ["Mark Gillard <mark.gillard@outlook.com.au>"]
		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<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
	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<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);
}

#endif // TOML_ENABLE_WINDOWS_COMPAT