From df8ca071a878ff61a84c0545704f90c577285a16 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 19 Mar 2016 16:47:40 +0100 Subject: [PATCH] first outline of test and aggregate initialisation problem - the test will use some really private data types, valid only within the scope of the test function. - invoking the builder for real got me into problems with the aggregate initialisation I'd used. Maybe it's the function pointers? Anyway, working around that by definint a telescope ctor --- .../diff/tree-mutator-collection-binding.hpp | 40 ++++++++++++------- src/lib/diff/tree-mutator.hpp | 2 +- .../diff/tree-manipulation-binding-test.cpp | 25 +++++++++++- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/lib/diff/tree-mutator-collection-binding.hpp b/src/lib/diff/tree-mutator-collection-binding.hpp index 5c6863210..19c8d474a 100644 --- a/src/lib/diff/tree-mutator-collection-binding.hpp +++ b/src/lib/diff/tree-mutator-collection-binding.hpp @@ -86,12 +86,21 @@ Coll& collection; - SEL isApplicable; MAT matches; CTR construct; + SEL isApplicable; ASS assign; MUT openSub; + CollectionBinding(Coll& coll, MAT m, CTR c, SEL s, ASS a, MUT u) + : collection(coll) + , matches(m) + , construct(c) + , isApplicable(s) + , assign(a) + , openSub(u) + { } + /* === content manipulation API === */ @@ -305,6 +314,7 @@ struct CollectionBindingBuilder : CollectionBinding { + using CollectionBinding::CollectionBinding; template CollectionBindingBuilder @@ -393,13 +403,13 @@ static bool default_contentMatch (GenNode const& spec, Elm const& elm) { - return spec.matches(elm); + //return spec.matches(elm); } static Elm default_construct_from_payload (GenNode const& spec) { - return spec.data.get(); + //return spec.data.get(); } static bool @@ -423,23 +433,23 @@ using FallbackBindingConfiguration = CollectionBindingBuilder; static FallbackBindingConfiguration attachTo (Coll& coll) { - return { coll - , disable_selector - , default_contentMatch - , default_construct_from_payload - , disable_assignment - , disable_childMutation - }; + return FallbackBindingConfiguration{ coll + , default_contentMatch + , default_construct_from_payload + , disable_selector + , disable_assignment + , disable_childMutation + }; } }; diff --git a/src/lib/diff/tree-mutator.hpp b/src/lib/diff/tree-mutator.hpp index 239f2bc4f..d0c97d225 100644 --- a/src/lib/diff/tree-mutator.hpp +++ b/src/lib/diff/tree-mutator.hpp @@ -351,7 +351,7 @@ namespace diff{ Builder> attach (BIN&& collectionBindingSetup) { - return Collection (std::forward(collectionBindingSetup)); + return Collection (std::forward(collectionBindingSetup), *this); } /** set up a diagnostic layer, binding to TestMutationTarget. diff --git a/tests/library/diff/tree-manipulation-binding-test.cpp b/tests/library/diff/tree-manipulation-binding-test.cpp index 6b11099e6..e38f604ab 100644 --- a/tests/library/diff/tree-manipulation-binding-test.cpp +++ b/tests/library/diff/tree-manipulation-binding-test.cpp @@ -273,10 +273,33 @@ namespace test{ } + /** @test map mutation primitives onto a STL collection managed locally. */ void mutateCollection() { - TODO ("define how to map the mutation primitives onto a generic collection"); + MARK_TEST_FUN; + + // some private data structures + struct Data + { + string key; + string val; + + operator string() const { return _Fmt{"≺%s∫%s≻"} % key % val; } + bool operator== (Data const& o) const { return key==o.key and val==o.val; } + bool operator!= (Data const& o) const { return not (*this == o); } + }; + + using VecD = std::vector; + using MapD = std::map; + + VecD target; + + // now set up a binding to these opaque private structures... + auto mutator = + TreeMutator::build() + .attach (collection(target)); + }