mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
Merge branch 'master' into find-idx
This commit is contained in:
@@ -80,10 +80,14 @@ BOOST_AUTO_TEST_CASE(test_detect_conflicting_value)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_detect_inhomogeneous_array)
|
||||
{
|
||||
#ifdef TOML11_USE_UNRELEASED_TOML_FEATURES
|
||||
BOOST_TEST_MESSAGE("heterogeneous array will be allowed in the next release");
|
||||
#else
|
||||
std::istringstream stream(std::string(
|
||||
"a = [1, 1.0]\n"
|
||||
));
|
||||
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_detect_appending_array_of_table)
|
||||
|
||||
@@ -128,3 +128,47 @@ BOOST_AUTO_TEST_CASE(test_multiline_array_value)
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", toml::value(a));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_heterogeneous_array)
|
||||
{
|
||||
#ifndef TOML11_USE_UNRELEASED_TOML_FEATURES
|
||||
BOOST_TEST_MESSAGE("In strict TOML v0.5.0, heterogeneous arrays are not allowed.");
|
||||
#else
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value("foo");
|
||||
a[1] = toml::value(3.14);
|
||||
a[2] = toml::value(42);
|
||||
a[3] = toml::value{toml::value("array"), toml::value("of"), toml::value("hetero-array"), toml::value(1)};
|
||||
a[4] = toml::value{{"key", "value"}};
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\", 3.14, 42, [\"array\", \"of\", \"hetero-array\", 1], {key = \"value\"}]", toml::value(a));
|
||||
}
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value("foo");
|
||||
a[1] = toml::value(3.14);
|
||||
a[2] = toml::value(42);
|
||||
a[3] = toml::value{toml::value("array"), toml::value("of"), toml::value("hetero-array"), toml::value(1)};
|
||||
a[4] = toml::value{{"key", "value"}};
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",\n 3.14,\n 42,\n [\"array\", \"of\", \"hetero-array\", 1],\n {key = \"value\"},\n]", toml::value(a));
|
||||
}
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value("foo");
|
||||
a[1] = toml::value(3.14);
|
||||
a[2] = toml::value(42);
|
||||
a[3] = toml::value{toml::value("array"), toml::value("of"), toml::value("hetero-array"), toml::value(1)};
|
||||
a[4] = toml::value{{"key", "value"}};
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",#comment\n 3.14,#comment\n 42,#comment\n [\"array\", \"of\", \"hetero-array\", 1],#comment\n {key = \"value\"},#comment\n]#comment", toml::value(a));
|
||||
}
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value("foo");
|
||||
a[1] = toml::value(3.14);
|
||||
a[2] = toml::value(42);
|
||||
a[3] = toml::value{toml::value("array"), toml::value("of"), toml::value("hetero-array"), toml::value(1)};
|
||||
a[4] = toml::value{{"key", "value"}};
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",\n 3.14,\n 42,\n [\"array\",\n \"of\",\n \"hetero-array\",\n 1],\n {key = \"value\"},\n]", toml::value(a));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -111,3 +111,44 @@ BOOST_AUTO_TEST_CASE(test_literal_ml_string)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_string_add_assign)
|
||||
{
|
||||
// string literal
|
||||
{
|
||||
toml::string str("foo");
|
||||
str += "bar";
|
||||
BOOST_TEST(str.str == "foobar");
|
||||
}
|
||||
// std::string
|
||||
{
|
||||
toml::string str("foo");
|
||||
std::string str2("bar");
|
||||
str += str2;
|
||||
BOOST_TEST(str.str == "foobar");
|
||||
}
|
||||
// toml::string
|
||||
{
|
||||
toml::string str("foo");
|
||||
toml::string str2("bar");
|
||||
str += str2;
|
||||
BOOST_TEST(str.str == "foobar");
|
||||
}
|
||||
#if __cplusplus >= 201703L
|
||||
// std::string_view
|
||||
{
|
||||
toml::string str("foo");
|
||||
str += std::string_view("bar");
|
||||
BOOST_TEST(str == "foobar");
|
||||
}
|
||||
#endif
|
||||
// std::string += toml::string
|
||||
{
|
||||
std::string str("foo");
|
||||
toml::string str2("bar");
|
||||
str += str2;
|
||||
BOOST_TEST(str == "foobar");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -934,3 +934,35 @@ BOOST_AUTO_TEST_CASE(test_value_at)
|
||||
BOOST_CHECK_THROW(v1.at(5), std::out_of_range);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_value_bracket)
|
||||
{
|
||||
{
|
||||
toml::value v1{{"foo", 42}, {"bar", 3.14}, {"baz", "qux"}};
|
||||
|
||||
BOOST_TEST(v1["foo"].as_integer() == 42);
|
||||
BOOST_TEST(v1["bar"].as_floating() == 3.14);
|
||||
BOOST_TEST(v1["baz"].as_string() == "qux");
|
||||
|
||||
v1["qux"] = 54;
|
||||
BOOST_TEST(v1["qux"].as_integer() == 54);
|
||||
}
|
||||
{
|
||||
toml::value v1;
|
||||
v1["foo"] = 42;
|
||||
|
||||
BOOST_TEST(v1.is_table());
|
||||
BOOST_TEST(v1["foo"].as_integer() == 42);
|
||||
}
|
||||
{
|
||||
toml::value v1{1,2,3,4,5};
|
||||
|
||||
BOOST_TEST(v1[0].as_integer() == 1);
|
||||
BOOST_TEST(v1[1].as_integer() == 2);
|
||||
BOOST_TEST(v1[2].as_integer() == 3);
|
||||
BOOST_TEST(v1[3].as_integer() == 4);
|
||||
BOOST_TEST(v1[4].as_integer() == 5);
|
||||
|
||||
BOOST_CHECK_THROW(v1["foo"], toml::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user