test: update test codes to v4

This commit is contained in:
ToruNiina
2024-06-15 19:14:06 +09:00
parent 7c123ab378
commit c47ff10a64
69 changed files with 6792 additions and 8535 deletions

View File

@@ -1,45 +1,165 @@
#include <toml/get.hpp>
#include <toml/parser.hpp>
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "unit_test.hpp"
#include "test_parse_aux.hpp"
#include <iostream>
#include "utility.hpp"
#include <toml11/parser.hpp>
#include <toml11/types.hpp>
using namespace toml;
using namespace detail;
#include "doctest.h"
BOOST_AUTO_TEST_CASE(test_normal_table)
TEST_CASE("testing a table")
{
std::string table(
"key1 = \"value\"\n"
"key2 = 42\n"
"key3 = 3.14\n"
);
location loc("test", table);
auto spec = toml::spec::v(1,0,0);
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location(R"(a = "foo")");
const auto result = toml::detail::parse_ml_table<toml::value>(loc);
BOOST_TEST(result.is_ok());
const auto data = result.unwrap();
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
BOOST_TEST(toml::get<std::string >(data.at("key1")) == "value");
BOOST_TEST(toml::get<std::int64_t>(data.at("key2")) == 42);
BOOST_TEST(toml::get<double >(data.at("key3")) == 3.14);
}
BOOST_AUTO_TEST_CASE(test_nested_table)
{
std::string table(
"a.b = \"value\"\n"
"a.c.d = 42\n"
);
location loc("test", table);
const auto result = toml::detail::parse_ml_table<toml::value>(loc);
BOOST_TEST(result.is_ok());
const auto data = result.unwrap();
const auto a = toml::get<toml::table>(data.at("a"));
const auto c = toml::get<toml::table>(a.at("c"));
BOOST_TEST(toml::get<std::string >(a.at("b")) == "value");
BOOST_TEST(toml::get<std::int64_t>(c.at("d")) == 42);
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.as_table().at("a").is_string());
CHECK_EQ (table.as_table().at("a").as_string(), "foo");
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::none);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 0);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location(" a = \"foo\"");
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.as_table().at("a").is_string());
CHECK_EQ (table.as_table().at("a").as_string(), "foo");
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::space);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 2);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location("\ta = \"foo\"");
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.as_table().at("a").is_string());
CHECK_EQ (table.as_table().at("a").as_string(), "foo");
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::tab);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 1);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location(R"(a = "foo"
b = "bar"
c.c1 = "baz"
c.c2 = "qux"
)");
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_UNARY(table.at("b").is_string());
CHECK_EQ (table.at("b").as_string(), "bar");
CHECK_UNARY(table.at("c").at("c1").is_string());
CHECK_EQ (table.at("c").at("c1").as_string(), "baz");
CHECK_UNARY(table.at("c").at("c2").is_string());
CHECK_EQ (table.at("c").at("c2").as_string(), "qux");
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::none);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 0);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location(R"(a = "foo"
b = "bar"
c.c1 = "baz"
[next.table]
c.c2 = "qux"
)");
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_UNARY(table.at("b").is_string());
CHECK_EQ (table.at("b").as_string(), "bar");
CHECK_UNARY(table.at("c").at("c1").is_string());
CHECK_EQ (table.at("c").at("c1").as_string(), "baz");
CHECK_UNARY( ! table.at("c").contains("c2"));
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::none);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 0);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
{
toml::detail::context<toml::type_config> ctx(spec);
auto loc = toml::detail::make_temporary_location(R"(
a = "foo"
b = "bar"
c.c1 = "baz"
[next.table]
c.c2 = "qux"
)");
toml::value table{toml::table()};
const auto res = toml::detail::parse_table<toml::type_config>(loc, ctx, table);
REQUIRE_UNARY(res.is_ok());
REQUIRE_UNARY(table.is_table());
CHECK_UNARY(table.at("a").is_string());
CHECK_EQ (table.at("a").as_string(), "foo");
CHECK_UNARY(table.at("b").is_string());
CHECK_EQ (table.at("b").as_string(), "bar");
CHECK_UNARY(table.at("c").at("c1").is_string());
CHECK_EQ (table.at("c").at("c1").as_string(), "baz");
CHECK_UNARY( ! table.at("c").contains("c2"));
CHECK_EQ(table.as_table_fmt().indent_type, toml::indent_char::space);
CHECK_EQ(table.as_table_fmt().name_indent, 0);
CHECK_EQ(table.as_table_fmt().body_indent, 4);
CHECK_EQ(table.as_table_fmt().closing_indent, 0);
}
}