mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
split parsing unicode file
This commit is contained in:
@@ -10,6 +10,7 @@ set(TEST_NAMES
|
|||||||
test_acceptor
|
test_acceptor
|
||||||
test_parser
|
test_parser
|
||||||
test_parse_file
|
test_parse_file
|
||||||
|
test_parse_unicode
|
||||||
)
|
)
|
||||||
|
|
||||||
CHECK_CXX_COMPILER_FLAG("-Wall" COMPILER_SUPPORTS_WALL)
|
CHECK_CXX_COMPILER_FLAG("-Wall" COMPILER_SUPPORTS_WALL)
|
||||||
|
@@ -123,33 +123,3 @@ BOOST_AUTO_TEST_CASE(test_hard_example)
|
|||||||
BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
|
BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
|
||||||
expected_multi_line_array);
|
expected_multi_line_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
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")),
|
|
||||||
u8"Ýôú'ℓℓ λáƭè ₥è áƒƭèř ƭλïƨ - #");
|
|
||||||
|
|
||||||
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{
|
|
||||||
u8"Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ", 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")),
|
|
||||||
u8"§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #");
|
|
||||||
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_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"ωλáƭ?"))),
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
40
tests/test_parse_unicode.cpp
Normal file
40
tests/test_parse_unicode.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#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>
|
||||||
|
|
||||||
|
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")),
|
||||||
|
u8"Ýôú'ℓℓ λáƭè ₥è áƒƭèř ƭλïƨ - #");
|
||||||
|
|
||||||
|
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{
|
||||||
|
u8"Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ", 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")),
|
||||||
|
u8"§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #");
|
||||||
|
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_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"ωλáƭ?"))),
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
@@ -6,6 +6,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <codecvt>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
namespace toml
|
namespace toml
|
||||||
@@ -1071,7 +1072,7 @@ toml::Table parse(std::basic_istream<toml::character, traits>& is)
|
|||||||
|
|
||||||
toml::Table parse(const std::string& filename)
|
toml::Table parse(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream ifs(filename, std::ios::binary);
|
std::ifstream ifs(filename);
|
||||||
if(!ifs.good()) throw std::runtime_error("file open error: " + filename);
|
if(!ifs.good()) throw std::runtime_error("file open error: " + filename);
|
||||||
return parse(ifs);
|
return parse(ifs);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user