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-01-04 14:21:38 +00:00
|
|
|
#include "tests.h"
|
|
|
|
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_PUSH_WARNINGS;
|
|
|
|
TOML_DISABLE_INIT_WARNINGS;
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
TEST_CASE("parsing - TOML spec example")
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-06-28 22:57:59 +00:00
|
|
|
static constexpr auto toml_text = R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
# This is a TOML document.
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
title = "TOML Example"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
[owner]
|
|
|
|
name = "Tom Preston-Werner"
|
|
|
|
dob = 1979-05-27T07:32:00-08:00 # First class dates
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
[database]
|
|
|
|
server = "192.168.1.1"
|
|
|
|
ports = [ 8001, 8001, 8002 ]
|
|
|
|
connection_max = 5000
|
|
|
|
enabled = true
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
[servers]
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
# Indentation (tabs and/or spaces) is allowed but not required
|
|
|
|
[servers.alpha]
|
|
|
|
ip = "10.0.0.1"
|
|
|
|
dc = "eqdc10"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
[servers.beta]
|
|
|
|
ip = "10.0.0.2"
|
|
|
|
dc = "eqdc10"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
[clients]
|
|
|
|
data = [ ["gamma", "delta"], [1, 2] ]
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
# Line breaks are OK when inside arrays
|
|
|
|
hosts = [
|
|
|
|
"alpha",
|
|
|
|
"omega"
|
|
|
|
]
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv;
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
|
|
|
toml_text,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-04-06 12:57:49 +00:00
|
|
|
{
|
|
|
|
CHECK(tbl.size() == 5);
|
|
|
|
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["title"] == "TOML Example"sv);
|
2020-04-06 12:57:49 +00:00
|
|
|
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["owner"]);
|
|
|
|
CHECK(tbl["owner"].as<table>());
|
|
|
|
CHECK(tbl["owner"]["name"] == "Tom Preston-Werner"sv);
|
2020-04-06 12:57:49 +00:00
|
|
|
const auto dob = date_time{ { 1979, 5, 27 }, { 7, 32 }, { -8, 0 } };
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["owner"]["dob"] == dob);
|
2020-04-06 12:57:49 +00:00
|
|
|
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["database"].as<table>());
|
|
|
|
CHECK(tbl["database"]["server"] == "192.168.1.1"sv);
|
2020-04-06 12:57:49 +00:00
|
|
|
const auto ports = { 8001, 8001, 8002 };
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["database"]["ports"] == ports);
|
|
|
|
CHECK(tbl["database"]["connection_max"] == 5000);
|
|
|
|
CHECK(tbl["database"]["enabled"] == true);
|
|
|
|
|
|
|
|
CHECK(tbl["servers"].as<table>());
|
|
|
|
CHECK(tbl["servers"]["alpha"].as<table>());
|
|
|
|
CHECK(tbl["servers"]["alpha"]["ip"] == "10.0.0.1"sv);
|
|
|
|
CHECK(tbl["servers"]["alpha"]["dc"] == "eqdc10"sv);
|
|
|
|
CHECK(tbl["servers"]["beta"].as<table>());
|
|
|
|
CHECK(tbl["servers"]["beta"]["ip"] == "10.0.0.2"sv);
|
|
|
|
CHECK(tbl["servers"]["beta"]["dc"] == "eqdc10"sv);
|
|
|
|
|
|
|
|
CHECK(tbl["clients"].as<table>());
|
|
|
|
REQUIRE(tbl["clients"]["data"].as<array>());
|
|
|
|
CHECK(tbl["clients"]["data"].as<array>()->size() == 2);
|
|
|
|
REQUIRE(tbl["clients"]["data"][0].as<array>());
|
|
|
|
CHECK(tbl["clients"]["data"][0].as<array>()->size() == 2);
|
|
|
|
CHECK(tbl["clients"]["data"][0][0] == "gamma"sv);
|
|
|
|
CHECK(tbl["clients"]["data"][0][1] == "delta"sv);
|
|
|
|
REQUIRE(tbl["clients"]["data"][1].as<array>());
|
|
|
|
CHECK(tbl["clients"]["data"][1].as<array>()->size() == 2);
|
|
|
|
CHECK(tbl["clients"]["data"][1][0] == 1);
|
|
|
|
CHECK(tbl["clients"]["data"][1][1] == 2);
|
|
|
|
REQUIRE(tbl["clients"]["hosts"].as<array>());
|
|
|
|
CHECK(tbl["clients"]["hosts"].as<array>()->size() == 2);
|
|
|
|
CHECK(tbl["clients"]["hosts"][0] == "alpha"sv);
|
|
|
|
CHECK(tbl["clients"]["hosts"][1] == "omega"sv);
|
2020-04-06 12:57:49 +00:00
|
|
|
}
|
|
|
|
);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 12:04:46 +00:00
|
|
|
TOML_POP_WARNINGS;
|