#define BOOST_TEST_MODULE "test_barekey" #ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST #include #else #define BOOST_TEST_NO_LIB #include #endif #include #include #include BOOST_AUTO_TEST_CASE(test_parse_barekey) { { const std::string source("hoge"); const std::string result = toml::parse_barekey::invoke( source.cbegin(), toml::is_barekey::invoke(source.cbegin())); BOOST_CHECK_EQUAL(source, result); } { const std::string source("bare-key"); const std::string result = toml::parse_barekey::invoke( source.cbegin(), toml::is_barekey::invoke(source.cbegin())); BOOST_CHECK_EQUAL(source, result); } { const std::string source("bare_key"); const std::string result = toml::parse_barekey::invoke( source.cbegin(), toml::is_barekey::invoke(source.cbegin())); BOOST_CHECK_EQUAL(source, result); } { const std::string source("42"); const std::string result = toml::parse_barekey::invoke( source.cbegin(), toml::is_barekey::invoke(source.cbegin())); BOOST_CHECK_EQUAL(source, result); } } BOOST_AUTO_TEST_CASE(test_parse_basic_inline_string) { typedef toml::parse_basic_inline_string parser; typedef toml::is_basic_inline_string acceptor; { const std::string source("\"simple\""); const std::string expected("simple"); const std::string result = parser::invoke( source.cbegin(), acceptor::invoke(source.cbegin())); BOOST_CHECK_EQUAL(result, expected); } { const std::string source("\"I'm a string. \\\"You can quote me\\\". Name\\tJos\\u00E9\\nLocation\\tSF.\""); const std::string expected("I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."); const std::string result = parser::invoke( source.cbegin(), acceptor::invoke(source.cbegin())); BOOST_CHECK_EQUAL(result, expected); } } BOOST_AUTO_TEST_CASE(test_parse_basic_multiline_string) { typedef toml::parse_basic_multiline_string parser; typedef toml::is_basic_multiline_string acceptor; { const std::string source("\"\"\"\nRoses are red\nViolets are blue\"\"\""); //XXX ifdef windows platform const std::string expected("Roses are red\nViolets are blue"); const std::string result = parser::invoke( source.cbegin(), acceptor::invoke(source.cbegin())); BOOST_CHECK_EQUAL(result, expected); } { const std::string source("\"\"\"\nThe quick brown \\\n\n fox jumps over \\\n the lazy dog.\"\"\""); const std::string expected("The quick brown fox jumps over the lazy dog."); const std::string result = parser::invoke( source.cbegin(), acceptor::invoke(source.cbegin())); BOOST_CHECK_EQUAL(result, expected); } { const std::string source("\"\"\"\nThe quick brown \\\n fox jumps over \\\n the lazy dog.\\\n \"\"\""); const std::string expected("The quick brown fox jumps over the lazy dog."); const std::string result = parser::invoke( source.cbegin(), acceptor::invoke(source.cbegin())); BOOST_CHECK_EQUAL(result, expected); } } BOOST_AUTO_TEST_CASE(test_parse_local_time) { typedef toml::parse_local_time parser; typedef toml::is_local_time 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 parser; typedef toml::is_local_date 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 parser; typedef toml::is_local_date_time 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 parser; typedef toml::is_offset_date_time 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); } }