From c3922c0d51ec56d279297ed69cca5828dd421beb Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 20 Jun 2019 14:43:31 +0900 Subject: [PATCH] test: move some test_cases across test files --- tests/test_find.cpp | 52 ++++++++++++++++++++++++++++++++ tests/test_get_related_func.cpp | 53 --------------------------------- 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/tests/test_find.cpp b/tests/test_find.cpp index 2029533..2ed4167 100644 --- a/tests/test_find.cpp +++ b/tests/test_find.cpp @@ -25,6 +25,58 @@ using test_value_types = std::tuple< toml::basic_value >; +BOOST_AUTO_TEST_CASE(test_find_throws) +{ + { + // value is not a table + toml::value v(true); + BOOST_CHECK_THROW(toml::find(v, "key"), toml::type_error); + } + { + // the value corresponding to the key is not the expected type + toml::value v{{"key", 42}}; + BOOST_CHECK_THROW(toml::find(v, "key"), toml::type_error); + } + { + // the value corresponding to the key is not found + toml::value v{{"key", 42}}; + BOOST_CHECK_THROW(toml::find(v, "different_key"), + std::out_of_range); + } + { + // the positive control. + toml::value v{{"key", 42}}; + BOOST_CHECK_EQUAL(42, toml::find(v, "key")); + } +} + +BOOST_AUTO_TEST_CASE(test_find_recursive) +{ + // recursively search tables + { + toml::value v{ + {"a", { + {"b", { + {"c", { + {"d", 42} + }} + }} + }} + }; + BOOST_CHECK_EQUAL(42, toml::find(v, "a", "b", "c", "d")); + + // reference that can be used to modify the content + auto& num = toml::find(v, "a", "b", "c", "d"); + num = 54; + BOOST_CHECK_EQUAL(54, toml::find(v, "a", "b", "c", "d")); + + const std::string a("a"), b("b"), c("c"), d("d"); + auto& num2 = toml::find(v, a, b, c, d); + num2 = 42; + BOOST_CHECK_EQUAL(42, toml::find(v, a, b, c, d)); + } +} + BOOST_AUTO_TEST_CASE_TEMPLATE(test_find_exact, value_type, test_value_types) { { diff --git a/tests/test_get_related_func.cpp b/tests/test_get_related_func.cpp index c0fcff6..496b1b7 100644 --- a/tests/test_get_related_func.cpp +++ b/tests/test_get_related_func.cpp @@ -12,60 +12,7 @@ #include #include -BOOST_AUTO_TEST_CASE(test_find) -{ - { - toml::value v(true); - bool thrown = false; - try - { - toml::find(v, "key"); - } - catch(toml::type_error const& te) - { - thrown = true; - } - BOOST_CHECK(thrown); - } - // the value corresponding to the key is not the expected type - { - toml::value v{{"key", 42}}; - bool thrown = false; - try - { - toml::find(v, "key"); - } - catch(toml::type_error const& te) - { - thrown = true; - } - BOOST_CHECK(thrown); - } - // recursively search tables - { - toml::value v = toml::table{ - {"a", toml::table{ - {"b", toml::table{ - {"c", toml::table{ - {"d", 42} - }} - }} - }} - }; - BOOST_CHECK_EQUAL(42, toml::find(v, "a", "b", "c", "d")); - - // reference that can be used to modify the content - auto& num = toml::find(v, "a", "b", "c", "d"); - num = 54; - BOOST_CHECK_EQUAL(54, toml::find(v, "a", "b", "c", "d")); - - const std::string a("a"), b("b"), c("c"), d("d"); - auto& num2 = toml::find(v, a, b, c, d); - num2 = 42; - BOOST_CHECK_EQUAL(42, toml::find(v, a, b, c, d)); - } -} BOOST_AUTO_TEST_CASE(test_get_or) {