diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-04-15 17:30:25 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-04-15 17:30:25 +0100 |
commit | ce699c4ff01349da00e5fa6a13dfdc2b38144b7e (patch) | |
tree | 9ddead625f6f8fe0f84b5a816baa5887794cbd3f | |
parent | Fix shadowing in icemetadata (diff) | |
download | slicer-ce699c4ff01349da00e5fa6a13dfdc2b38144b7e.tar.bz2 slicer-ce699c4ff01349da00e5fa6a13dfdc2b38144b7e.tar.xz slicer-ce699c4ff01349da00e5fa6a13dfdc2b38144b7e.zip |
constexpr preprocessor component counts
-rw-r--r-- | slicer/test/preprocessor.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index 7f9fefd..e85a42a 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -8,25 +8,22 @@ #include <filesystem> #include <map> #include <numeric> +#include <span> #include <string> #include <utility> #include <vector> -using ComponentsCount = std::map<std::string, unsigned int>; -ComponentsCount COMPONENTS_IN_TEST_ICE = {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 5}, - {"enums.ice", 2}, {"inheritance.ice", 12}, {"interfaces.ice", 0}, {"json.ice", 2}, {"locals.ice", 7}, - {"optionals.ice", 2}, {"structs.ice", 5}, {"types.ice", 4}, {"xml.ice", 5}}; - -unsigned int -total() -{ - const auto t = std::accumulate( - COMPONENTS_IN_TEST_ICE.begin(), COMPONENTS_IN_TEST_ICE.end(), 0U, [](const auto & t, const auto & c) { - return t + c.second; - }); - BOOST_CHECK_EQUAL(49, t); - return t; -} +constexpr std::array<std::pair<std::string_view, size_t>, 12> COMPONENTS_IN_TEST_ICE_ARRAY { + {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 5}, {"enums.ice", 2}, {"inheritance.ice", 12}, + {"interfaces.ice", 0}, {"json.ice", 2}, {"locals.ice", 7}, {"optionals.ice", 2}, {"structs.ice", 5}, + {"types.ice", 4}, {"xml.ice", 5}}}; +using ComponentsCount = decltype(COMPONENTS_IN_TEST_ICE_ARRAY); +constexpr std::span<const ComponentsCount::value_type> COMPONENTS_IN_TEST_ICE {COMPONENTS_IN_TEST_ICE_ARRAY}; +constexpr auto COMPONENTS_IN_TEST_ICE_COUNT = std::accumulate( + COMPONENTS_IN_TEST_ICE.begin(), COMPONENTS_IN_TEST_ICE.end(), 0U, [](const auto & t, const auto & c) { + return t + c.second; + }); +static_assert(COMPONENTS_IN_TEST_ICE_COUNT == 49); void process(Slicer::Slicer & s, const ComponentsCount::value_type & c) @@ -48,7 +45,7 @@ processAll(Slicer::Slicer & s) process(s, c); } } - BOOST_REQUIRE_EQUAL(total(), s.Components()); + BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE_COUNT, s.Components()); } BOOST_AUTO_TEST_CASE(slicer_metadata_split_empty, *boost::unit_test::timeout(5)) |