From 0a66be3257fde6d41d22e6f5fbcaa80ab225e519 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 8 Nov 2019 15:52:31 +0900 Subject: [PATCH] test: add test for parsing heterogeneous array this test case is activated only if TOML11_USE_UNRELEASED_TOML_FEATURES is defined. --- tests/test_parse_array.cpp | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_parse_array.cpp b/tests/test_parse_array.cpp index 9cfbc4d..2dafdb9 100644 --- a/tests/test_parse_array.cpp +++ b/tests/test_parse_array.cpp @@ -128,3 +128,47 @@ BOOST_AUTO_TEST_CASE(test_multiline_array_value) TOML11_TEST_PARSE_EQUAL_VALUE(parse_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, "[\"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 +}