[go: up one dir, main page]

File: test_parse_table.cpp

package info (click to toggle)
toml11 3.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,120 kB
  • sloc: cpp: 17,500; sh: 6; makefile: 4
file content (50 lines) | stat: -rw-r--r-- 1,407 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
#define BOOST_TEST_MODULE "parse_table_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp>
#include <toml/get.hpp>
#include "test_parse_aux.hpp"

using namespace toml;
using namespace detail;

BOOST_AUTO_TEST_CASE(test_normal_table)
{
    std::string table(
        "key1 = \"value\"\n"
        "key2 = 42\n"
        "key3 = 3.14\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();

    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);
}