Files
toml11/tests/test_parse_unicode.cpp

74 lines
4.0 KiB
C++
Raw Normal View History

2017-05-17 12:54:13 +09:00
#define BOOST_TEST_MODULE "test_parse_unicode"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp>
#include <iostream>
#include <fstream>
#ifdef _MSC_VER
BOOST_AUTO_TEST_CASE(test_hard_example_unicode)
{
const auto data = toml::parse("toml/tests/hard_example_unicode.toml");
const auto the = toml::get<toml::Table>(data.at("the"));
BOOST_CHECK_EQUAL(toml::get<std::string>(the.at("test_string")),
std::string("\xC3\x9D\xC3\xB4\xC3\xBA\x27\xE2\x84\x93\xE2\x84\x93\x20\xCE\xBB\xC3\xA1\xC6\xAD\xC3\xA8\x20\xE2\x82\xA5\xC3\xA8\x20\xC3\xA1\xC6\x92\xC6\xAD\xC3\xA8\xC5\x99\x20\xC6\xAD\xCE\xBB\xC3\xAF\xC6\xA8\x20\x2D\x20\x23"));
// const auto hard = toml::get<toml::Table>(the.at("hard"));
// const std::vector<std::string> expected_the_hard_test_array{"] ", " # "};
// BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array")) ==
// expected_the_hard_test_array);
// const std::vector<std::string> expected_the_hard_test_array2{
// std::string(u8"Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ"),
// std::string(u8"Éжƥèřï₥èñƭ #9 ωáƨ á ƨúççèƨƨ")};
// BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array2")) ==
// expected_the_hard_test_array2);
// BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("another_test_string")),
// std::string(u8"§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #"));
// BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_string")),
// std::string(u8" Âñδ ωλèñ \"'ƨ ářè ïñ ƭλè ƨƭřïñϱ, áℓôñϱ ωïƭλ # \""));
//
// const auto bit = toml::get<toml::Table>(hard.at(std::string(u8"βïƭ#")));
// BOOST_CHECK_EQUAL(toml::get<std::string>(bit.at(std::string(u8"ωλáƭ?"))),
// std::string(u8"Ýôú δôñ'ƭ ƭλïñƙ ƨô₥è úƨèř ωôñ'ƭ δô ƭλáƭ?"));
// const std::vector<std::string> expected_multi_line_array{"]"};
// BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
// expected_multi_line_array);
}
#else
2017-05-17 12:54:13 +09:00
BOOST_AUTO_TEST_CASE(test_hard_example_unicode)
{
const auto data = toml::parse("toml/tests/hard_example_unicode.toml");
const auto the = toml::get<toml::Table>(data.at("the"));
BOOST_CHECK_EQUAL(toml::get<std::string>(the.at("test_string")),
2017-05-17 14:17:03 +09:00
std::string(u8"Ýôú' λáƭè ₥è áƒƭèř ƭλïƨ - #"));
2017-05-17 12:54:13 +09:00
const auto hard = toml::get<toml::Table>(the.at("hard"));
const std::vector<std::string> expected_the_hard_test_array{"] ", " # "};
BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array")) ==
expected_the_hard_test_array);
const std::vector<std::string> expected_the_hard_test_array2{
2017-05-17 14:17:03 +09:00
std::string(u8"Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ"),
std::string(u8"Éжƥèřï₥èñƭ #9 ωáƨ á ƨúççèƨƨ")};
2017-05-17 12:54:13 +09:00
BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array2")) ==
expected_the_hard_test_array2);
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("another_test_string")),
2017-05-17 14:17:03 +09:00
std::string(u8"§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #"));
2017-05-17 12:54:13 +09:00
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_string")),
2017-05-17 14:17:03 +09:00
std::string(u8" Âñδ ωλèñ \"'ƨ ářè ïñ ƭλè ƨƭřïñϱ, áℓôñϱ ωïƭλ # \""));
2017-05-17 12:54:13 +09:00
const auto bit = toml::get<toml::Table>(hard.at(std::string(u8"βïƭ#")));
BOOST_CHECK_EQUAL(toml::get<std::string>(bit.at(std::string(u8"ωλáƭ?"))),
2017-05-17 14:17:03 +09:00
std::string(u8"Ýôú δôñ'ƭ ƭλïñƙ ƨô₥è úƨèř ωôñ'ƭ δô ƭλáƭ?"));
2017-05-17 12:54:13 +09:00
const std::vector<std::string> expected_multi_line_array{"]"};
BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
expected_multi_line_array);
}
#endif