mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
fix: open file as binary-mode #16
to avoid inconsistency between file size (obtained by tellg) and the size of the actual contents that would be read later
This commit is contained in:
@@ -213,6 +213,20 @@ BOOST_AUTO_TEST_CASE(test_file_with_BOM)
|
||||
BOOST_CHECK_EQUAL(toml::get <std::string>(data.at("key")), "value");
|
||||
BOOST_CHECK_EQUAL(toml::find<std::string>(data.at("table"), "key"), "value");
|
||||
}
|
||||
{
|
||||
const std::string table(
|
||||
"\xEF\xBB\xBF" // BOM
|
||||
"key = \"value\"\n"
|
||||
"[table]\n"
|
||||
"key = \"value\"\n"
|
||||
);
|
||||
std::ofstream ofs("tmp.toml");
|
||||
ofs << table;
|
||||
const auto data = toml::parse("tmp.toml");
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::get <std::string>(data.at("key")), "value");
|
||||
BOOST_CHECK_EQUAL(toml::find<std::string>(data.at("table"), "key"), "value");
|
||||
}
|
||||
{
|
||||
const std::string table(
|
||||
"\xEF\xBB\xBF" // BOM
|
||||
@@ -223,6 +237,20 @@ BOOST_AUTO_TEST_CASE(test_file_with_BOM)
|
||||
std::istringstream iss(table);
|
||||
const auto data = toml::parse(iss, "test_file_with_BOM_CRLF.toml");
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::get <std::string>(data.at("key")), "value");
|
||||
BOOST_CHECK_EQUAL(toml::find<std::string>(data.at("table"), "key"), "value");
|
||||
}
|
||||
{
|
||||
const std::string table(
|
||||
"\xEF\xBB\xBF" // BOM
|
||||
"key = \"value\"\r\n"
|
||||
"[table]\r\n"
|
||||
"key = \"value\"\r\n"
|
||||
);
|
||||
std::ofstream ofs("tmp.toml");
|
||||
ofs << table;
|
||||
const auto data = toml::parse("tmp.toml");
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::get <std::string>(data.at("key")), "value");
|
||||
BOOST_CHECK_EQUAL(toml::find<std::string>(data.at("table"), "key"), "value");
|
||||
}
|
||||
|
Reference in New Issue
Block a user