From b01c5534edafa9848c4491af74af0bcb5367f28b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 3 Oct 2019 13:52:12 +0900 Subject: [PATCH] test: add test cases for const-ref version --- tests/test_find.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_find.cpp b/tests/test_find.cpp index 1c188aa..63c1d78 100644 --- a/tests/test_find.cpp +++ b/tests/test_find.cpp @@ -27,6 +27,32 @@ using test_value_types = std::tuple< BOOST_AUTO_TEST_CASE(test_find_throws) { + // ----------------------------------------------------------------------- + // const-reference version + { + // value is not a table + const 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 + const toml::value v{{"key", 42}}; + BOOST_CHECK_THROW(toml::find(v, "key"), toml::type_error); + } + { + // the value corresponding to the key is not found + const toml::value v{{"key", 42}}; + BOOST_CHECK_THROW(toml::find(v, "different_key"), + std::out_of_range); + } + { + // the positive control. + const toml::value v{{"key", 42}}; + BOOST_TEST(42 == toml::find(v, "key")); + } + + // ----------------------------------------------------------------------- + // reference version { // value is not a table toml::value v(true); @@ -49,6 +75,9 @@ BOOST_AUTO_TEST_CASE(test_find_throws) BOOST_TEST(42 == toml::find(v, "key")); } + // ----------------------------------------------------------------------- + // move version + { // value is not a table toml::value v(true); @@ -70,7 +99,6 @@ BOOST_AUTO_TEST_CASE(test_find_throws) toml::value v{{"key", 42}}; BOOST_TEST(42 == toml::find(std::move(v), "key")); } - } BOOST_AUTO_TEST_CASE(test_find_recursive)