From f2cea8d5934591cb2f3b22f6bb3f586666fd394e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Sep 2023 14:34:48 +0100 Subject: Add new test type --- slicer/test/collections.ice | 2 ++ slicer/test/preprocessor.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/slicer/test/collections.ice b/slicer/test/collections.ice index 60798cd..62d3d3e 100644 --- a/slicer/test/collections.ice +++ b/slicer/test/collections.ice @@ -10,6 +10,8 @@ module TestModule { local sequence Structs; dictionary ClassMap; local dictionary StructMap; + ["slicer:key:id","slicer:value:res","slicer:item:thing"] + local dictionary StructMapNamed; }; #endif diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index fea951b..ee94fea 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -12,7 +12,7 @@ #include constexpr std::array, 12> COMPONENTS_IN_TEST_ICE_ARRAY { - {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 5}, {"enums.ice", 2}, {"inheritance.ice", 12}, + {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 6}, {"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); @@ -21,7 +21,7 @@ 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); +static_assert(COMPONENTS_IN_TEST_ICE_COUNT == 50); void process(Slicer::Slicer & s, const ComponentsCount::value_type & c) -- cgit v1.2.3 From d7cca3056ac2ad1734989600b6652efefa185dbc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Sep 2023 15:19:43 +0100 Subject: Partially revert changes to IceMetaData constructor Fixes issue where some metadata names/keys were corrupted. Includes new tests which highlighted problem, only to certain values, yay undefined behaviour. --- slicer/slicer/metadata-test.cpp | 7 ++++++- slicer/test/collections.ice | 2 +- slicer/test/initial/dictNamed.xml | 17 +++++++++++++++++ slicer/test/serializers.cpp | 7 +++++++ slicer/tool/icemetadata.cpp | 5 ++--- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 slicer/test/initial/dictNamed.xml diff --git a/slicer/slicer/metadata-test.cpp b/slicer/slicer/metadata-test.cpp index a72b844..cc981e3 100644 --- a/slicer/slicer/metadata-test.cpp +++ b/slicer/slicer/metadata-test.cpp @@ -21,11 +21,12 @@ namespace test { static_assert(!Slicer::MetaData<>::in_scope("scope:sub2:subsub", "scope:sub")); static_assert(!Slicer::MetaData<>::in_scope("scope:sub:subsub", "scope:sub2")); - constexpr Slicer::MetaDataImpl<4> md {{{ + constexpr Slicer::MetaDataImpl<5> md {{{ "slicer:yes", "slicer:no", "slicer:sub:scope", "notslicer:dontcare", + "slicer:key:id", }}}; static_assert(md.arr[0].first == "slicer:yes"); @@ -45,4 +46,8 @@ namespace test { static_assert(md.value("slicer:sub").has_value()); static_assert(md.value("slicer:sub").value() == "scope"); static_assert(!md.value("nope:").has_value()); + static_assert(md.value("slicer:key:").has_value()); + static_assert(md.value("slicer:key:").value() == "id"); + static_assert(md.value("slicer:key").has_value()); + static_assert(md.value("slicer:key").value() == "id"); } diff --git a/slicer/test/collections.ice b/slicer/test/collections.ice index 62d3d3e..f2ccc74 100644 --- a/slicer/test/collections.ice +++ b/slicer/test/collections.ice @@ -10,7 +10,7 @@ module TestModule { local sequence Structs; dictionary ClassMap; local dictionary StructMap; - ["slicer:key:id","slicer:value:res","slicer:item:thing"] + ["slicer:value:res","slicer:key:id","slicer:item:thing"] local dictionary StructMapNamed; }; diff --git a/slicer/test/initial/dictNamed.xml b/slicer/test/initial/dictNamed.xml new file mode 100644 index 0000000..2e1fe7e --- /dev/null +++ b/slicer/test/initial/dictNamed.xml @@ -0,0 +1,17 @@ + + + + 1 + + 1 + 2 + + + + 2 + + 3 + 4 + + + diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index 1780237..525d68d 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -710,3 +710,10 @@ BOOST_DATA_TEST_CASE(typeid_specifies_no_such_type, BOOST_CHECK_THROW(std::ignore = (Slicer::DeserializeAny(in)), Slicer::UnknownType); } + +BOOST_AUTO_TEST_CASE(dict_with_name_overrides) +{ + auto res = Slicer::DeserializeAny( + rootDir / "initial/dictNamed.xml"); + BOOST_REQUIRE_EQUAL(res.size(), 2); +} diff --git a/slicer/tool/icemetadata.cpp b/slicer/tool/icemetadata.cpp index 3dfbee9..3cbde8c 100644 --- a/slicer/tool/icemetadata.cpp +++ b/slicer/tool/icemetadata.cpp @@ -8,10 +8,9 @@ namespace Slicer { IceMetaData::IceMetaData(Slice::StringList as) { arr.reserve(as.size()); - std::transform(as.begin(), as.end(), std::back_inserter(arr), [](auto && a) { - decltype(arr)::value_type md {std::forward(a), std::string_view {}}; + std::for_each(as.begin(), as.end(), [this](auto a) { + auto & md = arr.emplace_back(std::move(a), std::string_view {}); md.second = std::string_view(md.first).substr(0, md.first.rfind(':')); - return md; }); _begin = arr.begin(); _end = arr.end(); -- cgit v1.2.3