From ad4ecaa7ec06a983a63ec8beba830070a09717bd Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 9 May 2017 22:07:13 +0900 Subject: [PATCH] add test for key-value pair --- tests/test_parser.cpp | 81 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/tests/test_parser.cpp b/tests/test_parser.cpp index 0e5d1e5..c8d2a56 100644 --- a/tests/test_parser.cpp +++ b/tests/test_parser.cpp @@ -339,6 +339,81 @@ BOOST_AUTO_TEST_CASE(test_parse_inline_table) } } - - - +BOOST_AUTO_TEST_CASE(test_key_value_pair) +{ + typedef toml::parse_key_value_pair parser; + typedef toml::is_key_value_pair acceptor; + { + const std::string source("key=1"); + const std::pair expected{"key", 1}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key =\t1"); + const std::pair expected{"key", 1}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = true"); + const std::pair expected{"key", true}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = -42"); + const std::pair expected{"key", -42}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = -42.0"); + const std::pair expected{"key", -42.}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = \"string\""); + const std::pair expected{"key", "string"}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = 1901-01-01T00:00:00"); + const std::pair expected{"key", toml::Datetime(1901, 1,1,0,0,0,0,0)}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = [1,2,3]"); + const std::pair expected{"key", {1,2,3}}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } + { + const std::string source("key = {foo=1,bar=2.0,baz='3'}"); + const std::pair expected{"key", + {{"foo", 1}, {"bar", 2.0}, {"baz", "3"}}}; + const auto result = parser::invoke( + source.cbegin(), acceptor::invoke(source.cbegin())); + const bool check = result == expected; + BOOST_CHECK(check); + } +}