#include #include "unit_test.hpp" #include "test_parse_aux.hpp" using namespace toml; using namespace detail; BOOST_AUTO_TEST_CASE(test_oneline_array) { TOML11_TEST_PARSE_EQUAL_VAT(parse_array, "[]", array()); { array a(5); a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4); a[3] = toml::value(1); a[4] = toml::value(5); TOML11_TEST_PARSE_EQUAL_VAT(parse_array, "[3,1,4,1,5]", a); } { array a(3); a[0] = toml::value("foo"); a[1] = toml::value("bar"); a[2] = toml::value("baz"); TOML11_TEST_PARSE_EQUAL_VAT(parse_array, "[\"foo\", \"bar\", \"baz\"]", a); } { array a(5); a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4); a[3] = toml::value(1); a[4] = toml::value(5); TOML11_TEST_PARSE_EQUAL_VAT(parse_array, "[3,1,4,1,5,]", a); } { array a(3); a[0] = toml::value("foo"); a[1] = toml::value("bar"); a[2] = toml::value("baz"); TOML11_TEST_PARSE_EQUAL_VAT(parse_array, "[\"foo\", \"bar\", \"baz\",]", a); } } BOOST_AUTO_TEST_CASE(test_oneline_array_value) { TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "[]", toml::value(array())); { array a(5); a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4); a[3] = toml::value(1); a[4] = toml::value(5); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "[3,1,4,1,5]", toml::value(a)); } { array a(3); a[0] = toml::value("foo"); a[1] = toml::value("bar"); a[2] = toml::value("baz"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "[\"foo\", \"bar\", \"baz\"]", toml::value(a)); } { array a(5); a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4); a[3] = toml::value(1); a[4] = toml::value(5); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "[3,1,4,1,5,]", toml::value(a)); } { array a(3); a[0] = toml::value("foo"); a[1] = toml::value("bar"); a[2] = toml::value("baz"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "[\"foo\", \"bar\", \"baz\",]", toml::value(a)); } } BOOST_AUTO_TEST_CASE(test_multiline_array) { TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\n#comment\n]", typename basic_value< discard_comments>::array_type()); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\n#comment\n]", typename basic_value::array_type()); { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[3,\n1,\n4,\n1,\n5]", a); } { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[3,\n1,\n4,\n1,\n5]", a); } { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", a); } { typename basic_value::array_type a(5); a[0] = basic_value(3, {"comment"}); a[1] = basic_value(1, {"comment"}); a[2] = basic_value(4, {"comment"}); a[3] = basic_value(1, {"comment"}); a[4] = basic_value(5, {"comment"}); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", a); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("bar"); a[2] = basic_value("baz"); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\"foo\",\n\"bar\",\n\"baz\"]", a); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("bar"); a[2] = basic_value("baz"); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\"foo\",\n\"bar\",\n\"baz\"]", a); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("b#r"); a[2] = basic_value("b#z"); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", a); } { typename basic_value::array_type a(3); a[0] = basic_value("foo", {"comment"}); a[1] = basic_value("b#r", {"comment"}); a[2] = basic_value("b#z", {"comment"}); TOML11_TEST_PARSE_EQUAL_VAT(parse_array>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", a); } } BOOST_AUTO_TEST_CASE(test_multiline_array_value) { TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\n#comment\n]", basic_value< discard_comments>(typename basic_value< discard_comments>::array_type())); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\n#comment\n]", basic_value(typename basic_value::array_type())); { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[3,\n1,\n4,\n1,\n5]", basic_value(a)); } { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[3,\n1,\n4,\n1,\n5]", basic_value(a)); } { typename basic_value::array_type a(5); a[0] = basic_value(3); a[1] = basic_value(1); a[2] = basic_value(4); a[3] = basic_value(1); a[4] = basic_value(5); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", basic_value(a)); } { typename basic_value::array_type a(5); a[0] = basic_value(3, {"comment"}); a[1] = basic_value(1, {"comment"}); a[2] = basic_value(4, {"comment"}); a[3] = basic_value(1, {"comment"}); a[4] = basic_value(5, {"comment"}); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", basic_value(a)); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("bar"); a[2] = basic_value("baz"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\"foo\",\n\"bar\",\n\"baz\"]", basic_value(a)); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("bar"); a[2] = basic_value("baz"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\"foo\",\n\"bar\",\n\"baz\"]", basic_value(a)); } { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("b#r"); a[2] = basic_value("b#z"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", basic_value(a)); } { typename basic_value::array_type a(3); a[0] = basic_value("foo", {"comment"}); a[1] = basic_value("b#r", {"comment"}); a[2] = basic_value("b#z", {"comment"}); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", basic_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, "[\"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, "[\"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, "[\"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, "[\"foo\",\n 3.14,\n 42,\n [\"array\",\n \"of\",\n \"hetero-array\",\n 1],\n {key = \"value\"},\n]", toml::value(a)); } #endif } BOOST_AUTO_TEST_CASE(test_comments_after_comma) { { typename basic_value::array_type a(3); a[0] = basic_value("foo"); a[1] = basic_value("bar"); a[2] = basic_value("baz"); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[ \"foo\" # comment\n" ", \"bar\" # comment\n" ", \"baz\" # comment\n" "]", basic_value(a)); } { typename basic_value::array_type a(3); a[0] = basic_value("foo", {" comment"}); a[1] = basic_value("bar", {" comment"}); a[2] = basic_value("baz", {" comment"}); TOML11_TEST_PARSE_EQUAL_VALUE(parse_value>, "[ \"foo\" # comment\n" ", \"bar\" # comment\n" ", \"baz\" # comment\n" "]", basic_value(a)); } }