mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
add some tests
This commit is contained in:
@@ -443,10 +443,14 @@ BOOST_AUTO_TEST_CASE(test_inline_table)
|
||||
BOOST_CHECK(is_valid::invoke(tab7.cbegin()) == tab7.cend());
|
||||
}
|
||||
{
|
||||
const std::string tab0("{hoge = [1,2,3], piyo = {fuga = {}}}");
|
||||
const std::string tab0("{hoge = 1, piyo = 2.0}");
|
||||
BOOST_CHECK(is_valid::invoke(tab0.cbegin()) == tab0.cend());
|
||||
const std::string tab1("{hoge = \"}\", piyo = \"#\"}");
|
||||
const std::string tab1("{hoge = [1,2,3], piyo = {fuga = {}}}");
|
||||
BOOST_CHECK(is_valid::invoke(tab1.cbegin()) == tab1.cend());
|
||||
const std::string tab2("{hoge = \"}\", piyo = \"#\"}");
|
||||
BOOST_CHECK(is_valid::invoke(tab2.cbegin()) == tab2.cend());
|
||||
const std::string tab3("{b=true, i=1, f=2.0, d=1907-03-02T07:32:00, s='str', a=[1,2,3], t={foo=1}}");
|
||||
BOOST_CHECK(is_valid::invoke(tab3.cbegin()) == tab3.cend());
|
||||
}
|
||||
{
|
||||
const std::string tab0("{hoge = \"}\",\n piyo = \"#\"}");
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#endif
|
||||
#include <toml/acceptor.hpp>
|
||||
#include <toml/parser.hpp>
|
||||
#include <toml/from_toml.hpp>
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_parse_barekey)
|
||||
@@ -196,3 +197,148 @@ BOOST_AUTO_TEST_CASE(test_parse_offset_date_time)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user