From 4d64c0d8af1f5a4d76a462b3c384843524a5fd09 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 11 Dec 2018 23:38:57 +0900 Subject: [PATCH] add tests for inline table --- tests/CMakeLists.txt | 1 + tests/test_parse_inline_table.cpp | 48 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/test_parse_inline_table.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 28bb812..d9bee1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,6 +15,7 @@ set(TEST_NAMES test_parse_floating test_parse_string test_parse_array + test_parse_inline_table test_parse_key # test_to_toml diff --git a/tests/test_parse_inline_table.cpp b/tests/test_parse_inline_table.cpp new file mode 100644 index 0000000..57045bd --- /dev/null +++ b/tests/test_parse_inline_table.cpp @@ -0,0 +1,48 @@ +#define BOOST_TEST_MODULE "parse_inline_table_test" +#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST +#include +#else +#define BOOST_TEST_NO_LIB +#include +#endif +#include +#include "test_parse_aux.hpp" + +using namespace toml; +using namespace detail; + +BOOST_AUTO_TEST_CASE(test_inline_table) +{ + TOML11_TEST_PARSE_EQUAL(parse_inline_table, "{}", table()); + { + table t; + t["foo"] = toml::value(42); + t["bar"] = toml::value("baz"); + TOML11_TEST_PARSE_EQUAL(parse_inline_table, "{foo = 42, bar = \"baz\"}", t); + } + { + table t; + table t_sub; + t_sub["name"] = toml::value("pug"); + t["type"] = toml::value(t_sub); + TOML11_TEST_PARSE_EQUAL(parse_inline_table, "{type.name = \"pug\"}", t); + } +} + +BOOST_AUTO_TEST_CASE(test_inline_table_value) +{ + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "{}", value(table())); + { + table t; + t["foo"] = toml::value(42); + t["bar"] = toml::value("baz"); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "{foo = 42, bar = \"baz\"}", value(t)); + } + { + table t; + table t_sub; + t_sub["name"] = toml::value("pug"); + t["type"] = toml::value(t_sub); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "{type.name = \"pug\"}", value(t)); + } +}