mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-19 03:18:09 +08:00
change impl of parser of values
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#define BOOST_TEST_MODULE "test_barekey"
|
||||
#define BOOST_TEST_MODULE "test_parser"
|
||||
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#else
|
||||
@@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE(test_parse_boolean)
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("T");
|
||||
const std::string source("dummy");
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(!result.first.ok());
|
||||
BOOST_CHECK(result.second == source.begin());
|
||||
@@ -326,257 +326,307 @@ BOOST_AUTO_TEST_CASE(test_parse_boolean)
|
||||
|
||||
|
||||
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_local_time)
|
||||
// {
|
||||
// typedef toml::parse_local_time<char> parser;
|
||||
// typedef toml::is_local_time<char> acceptor;
|
||||
// {
|
||||
// const std::string source("12:34:56");
|
||||
// const toml::Datetime expected(12, 34, 56, 0, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("12:34:56.7");
|
||||
// const toml::Datetime expected(12, 34, 56, 700, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("12:34:56.7891");
|
||||
// const toml::Datetime expected(12, 34, 56, 789, 100);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_local_date)
|
||||
// {
|
||||
// typedef toml::parse_local_date<char> parser;
|
||||
// typedef toml::is_local_date<char> acceptor;
|
||||
// {
|
||||
// const std::string source("1979-09-27");
|
||||
// const toml::Datetime expected(1979, 9, 27);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_local_date_time)
|
||||
// {
|
||||
// typedef toml::parse_local_date_time<char> parser;
|
||||
// typedef toml::is_local_date_time<char> acceptor;
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56.789000");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
||||
// {
|
||||
// typedef toml::parse_offset_date_time<char> parser;
|
||||
// typedef toml::is_offset_date_time<char> acceptor;
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56Z");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 0, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56.789000Z");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, 0, 0);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56+07:30");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 7, 30);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56.789000+07:30");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, 7, 30);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56-07:30");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, -7, -30);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("1979-09-27T12:34:56.789000-07:30");
|
||||
// const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, -7, -30);
|
||||
// const toml::Datetime result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// BOOST_CHECK_EQUAL(result, expected);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_array)
|
||||
// {
|
||||
// typedef toml::parse_array<char> parser;
|
||||
// typedef toml::is_array<char> acceptor;
|
||||
// {
|
||||
// const std::string source("[1,2,3]");
|
||||
// const toml::Array expected{1, 2, 3};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[1, 2, 3]");
|
||||
// const toml::Array expected{1, 2, 3};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[ 1,2,3 ]");
|
||||
// const toml::Array expected{1, 2, 3};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[ 1 , 2 , 3 ]");
|
||||
// const toml::Array expected{1, 2, 3};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[ 1 \n,#comment\n 2 ,\n 3\n ]");
|
||||
// const toml::Array expected{1, 2, 3};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[ # empty array\n ]");
|
||||
// const toml::Array expected{};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("[ \"] \", ' # ', \n']', # ] \n]");
|
||||
// const toml::Array expected{"] ", " # ", "]"};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("[ \"Test #11 ]proved that\", 'Experiment #9 was a success' ]");
|
||||
// const toml::Array expected{"Test #11 ]proved that", "Experiment #9 was a success"};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("[ \"Test #11 ]proved that\", 'Experiment #9 was a success' ]");
|
||||
// const toml::Array expected{"Test #11 ]proved that", "Experiment #9 was a success"};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("[ [1,2,3] , ['a', 'b', 'c'] ]");
|
||||
// const toml::Array expected{{1,2,3}, {"a", "b", "c"}};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("[ {foo=1}, {foo=1, bar=2.0}, {foo=1, bar=2.0, baz='str'} ]");
|
||||
// const toml::Array expected{{{"foo", 1}}, {{"foo", 1}, {"bar", 2.0}}, {{"foo", 1}, {"bar", 2.0}, {"baz", "str"}}};
|
||||
// const toml::Array result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
//
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// BOOST_AUTO_TEST_CASE(test_parse_inline_table)
|
||||
// {
|
||||
// typedef toml::parse_inline_table<char> parser;
|
||||
// typedef toml::is_inline_table<char> acceptor;
|
||||
// {
|
||||
// const std::string source("{foo=1,bar=2.0,baz='str'}");
|
||||
// const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
// const toml::Table result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("{ foo=1, bar=2.0, baz='str' }");
|
||||
// const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
// const toml::Table result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// {
|
||||
// const std::string source("{ foo = 1, bar = 2.0, baz = 'str' }");
|
||||
// const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
// const toml::Table result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// const std::string source("{b=true, i=1, f=2.0, d=1907-03-02T07:32:00, s='str', a=[1,2,3], t={foo=1}}");
|
||||
// const toml::Table expected{{"b", true}, {"i", 1}, {"f", 2.0},
|
||||
// {"d", toml::Datetime(1907,3,2,7,32,0,0,0)},
|
||||
// {"s", "str"}, {"a", {1, 2, 3}},
|
||||
// {"t", {{"foo", 1}}}};
|
||||
// const toml::Table result = parser::invoke(
|
||||
// source.cbegin(), acceptor::invoke(source.cbegin()));
|
||||
// const bool check = result == expected;
|
||||
// BOOST_CHECK(check);
|
||||
// }
|
||||
// }
|
||||
BOOST_AUTO_TEST_CASE(test_parse_local_time)
|
||||
{
|
||||
typedef toml::parse_local_time parser;
|
||||
typedef toml::is_local_time<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("12:34:56");
|
||||
const toml::Datetime expected(12, 34, 56, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("12:34:56.7");
|
||||
const toml::Datetime expected(12, 34, 56, 700, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("12:34:56.7891");
|
||||
const toml::Datetime expected(12, 34, 56, 789, 100);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_local_date)
|
||||
{
|
||||
typedef toml::parse_local_date parser;
|
||||
typedef toml::is_local_date<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("1979-09-27");
|
||||
const toml::Datetime expected(1979, 9, 27);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_local_date_time)
|
||||
{
|
||||
typedef toml::parse_local_date_time parser;
|
||||
typedef toml::is_local_date_time<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56.789000");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
||||
{
|
||||
typedef toml::parse_offset_date_time parser;
|
||||
typedef toml::is_offset_date_time<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56Z");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56.789000Z");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56+07:30");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 7, 30);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56.789000+07:30");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, 7, 30);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56-07:30");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, -7, -30);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56.789000-07:30");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 789, 0, -7, -30);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_datetime)
|
||||
{
|
||||
typedef toml::parse_datetime parser;
|
||||
typedef toml::is_datetime<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56Z");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27T12:34:56");
|
||||
const toml::Datetime expected(1979, 9, 27, 12, 34, 56, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("1979-09-27");
|
||||
const toml::Datetime expected(1979, 9, 27);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("12:34:56");
|
||||
const toml::Datetime expected(12, 34, 56, 0, 0);
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK_EQUAL(result.first.get(), expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_array)
|
||||
{
|
||||
typedef toml::parse_array<toml::charactor> parser;
|
||||
typedef toml::is_array<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("[1,2,3]");
|
||||
const toml::Array expected{1, 2, 3};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[1, 2, 3]");
|
||||
const toml::Array expected{1, 2, 3};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[ 1,2,3 ]");
|
||||
const toml::Array expected{1, 2, 3};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[ 1 , 2 , 3 ]");
|
||||
const toml::Array expected{1, 2, 3};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[ 1 \n,#comment\n 2 ,\n 3\n ]");
|
||||
const toml::Array expected{1, 2, 3};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[ # empty array\n ]");
|
||||
const toml::Array expected{};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("[ \"] \", ' # ', \n']', # ] \n]");
|
||||
const toml::Array expected{"] ", " # ", "]"};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("[ \"Test #11 ]proved that\", 'Experiment #9 was a success' ]");
|
||||
const toml::Array expected{"Test #11 ]proved that", "Experiment #9 was a success"};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("[ \"Test #11 ]proved that\", 'Experiment #9 was a success' ]");
|
||||
const toml::Array expected{"Test #11 ]proved that", "Experiment #9 was a success"};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("[ [1,2,3] , ['a', 'b', 'c'] ]");
|
||||
const toml::Array expected{{1,2,3}, {"a", "b", "c"}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("[ {foo=1}, {foo=1, bar=2.0}, {foo=1, bar=2.0, baz='str'} ]");
|
||||
const toml::Array expected{{{"foo", 1}}, {{"foo", 1}, {"bar", 2.0}}, {{"foo", 1}, {"bar", 2.0}, {"baz", "str"}}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_inline_table)
|
||||
{
|
||||
typedef toml::parse_inline_table<toml::charactor> parser;
|
||||
typedef toml::is_inline_table<toml::charactor> acceptor;
|
||||
{
|
||||
const std::string source("{foo=1,bar=2.0,baz='str'}");
|
||||
const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("{ foo=1, bar=2.0, baz='str' }");
|
||||
const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
{
|
||||
const std::string source("{ foo = 1, bar = 2.0, baz = 'str' }");
|
||||
const toml::Table expected{{"foo", 1}, {"bar", 2.0}, {"baz", "str"}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string source("{b=true, i=1, f=2.0, d=1907-03-02T07:32:00, s='str', a=[1,2,3], t={foo=1}}");
|
||||
const toml::Table expected{{"b", true}, {"i", 1}, {"f", 2.0},
|
||||
{"d", toml::Datetime(1907,3,2,7,32,0,0,0)},
|
||||
{"s", "str"}, {"a", {1, 2, 3}},
|
||||
{"t", {{"foo", 1}}}};
|
||||
const auto result = parser::invoke(source.cbegin());
|
||||
BOOST_CHECK(result.first.ok());
|
||||
BOOST_CHECK(result.first.get() == expected);
|
||||
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
|
||||
}
|
||||
}
|
||||
//
|
||||
// // BOOST_AUTO_TEST_CASE(test_parse_barekey)
|
||||
// // {
|
||||
|
Reference in New Issue
Block a user