add parser impl for integer, float, boolean

This commit is contained in:
ToruNiina
2017-05-11 00:14:22 +09:00
parent 88e2c3fe48
commit f5d301016f
2 changed files with 220 additions and 52 deletions

View File

@@ -31,6 +31,12 @@ BOOST_AUTO_TEST_CASE(test_parse_basic_inline_string)
BOOST_CHECK_EQUAL(result.first.get(), expected);
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
}
{
const std::string source("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_parse_basic_multiline_string)
@@ -62,6 +68,12 @@ BOOST_AUTO_TEST_CASE(test_parse_basic_multiline_string)
BOOST_CHECK_EQUAL(result.first.get(), expected);
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
}
{
const std::string source("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_parse_literal_inline_string)
@@ -100,6 +112,12 @@ BOOST_AUTO_TEST_CASE(test_parse_literal_inline_string)
BOOST_CHECK_EQUAL(result.first.get(), expected);
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
}
{
const std::string source("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_parse_literal_multiline_string)
@@ -122,6 +140,12 @@ BOOST_AUTO_TEST_CASE(test_parse_literal_multiline_string)
BOOST_CHECK_EQUAL(result.first.get(), expected);
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
}
{
const std::string source("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_parse_string)
@@ -160,8 +184,148 @@ BOOST_AUTO_TEST_CASE(test_parse_string)
BOOST_CHECK_EQUAL(result.first.get(), expected);
BOOST_CHECK(result.second == acceptor::invoke(source.begin()));
}
{
const std::string source("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_integer)
{
typedef toml::parse_integer parser;
typedef toml::is_integer<toml::charactor> acceptor;
{
const std::string source("42");
const toml::Integer expected(42);
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("+42");
const toml::Integer expected(42);
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("-42");
const toml::Integer expected(-42);
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("-4_2");
const toml::Integer expected(-42);
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("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_float)
{
typedef toml::parse_float parser;
typedef toml::is_float<toml::charactor> acceptor;
{
const std::string source("42.0");
const toml::Float expected(42.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("+42.0");
const toml::Float expected(42.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("-42.0");
const toml::Float expected(-42.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("-4_2.0");
const toml::Float expected(-42.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("-42e0");
const toml::Float expected(-42.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("-42.0e0");
const toml::Float expected(-42.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("dummy");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
BOOST_AUTO_TEST_CASE(test_parse_boolean)
{
typedef toml::parse_boolean parser;
typedef toml::is_boolean<toml::charactor> acceptor;
{
const std::string source("true");
const toml::Boolean expected(true);
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("false");
const toml::Boolean expected(false);
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("T");
const auto result = parser::invoke(source.cbegin());
BOOST_CHECK(!result.first.ok());
BOOST_CHECK(result.second == source.begin());
}
}
// BOOST_AUTO_TEST_CASE(test_parse_local_time)
// {
// typedef toml::parse_local_time<char> parser;