From 8a5f1bc8d73e657121ec067d2c3c7bff8c08bc47 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 Dec 2019 01:05:04 +0100 Subject: [PATCH] Diff-Listener: add a similar simplistic demo for opaque binding based on a TreeMutator binding to a STL vector ...because this is probably the most frequently used case --- doc/technical/library/DiffFramework.txt | 2 +- .../diff-tree-application-simple-test.cpp | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/doc/technical/library/DiffFramework.txt b/doc/technical/library/DiffFramework.txt index 77ef3d0a8..29618afc4 100644 --- a/doc/technical/library/DiffFramework.txt +++ b/doc/technical/library/DiffFramework.txt @@ -316,7 +316,7 @@ sometimes get into conflict with the essentially open and permissive nature of s a mapping rule, which translates into additional conventions about how to spell out matters in the diff language. We choose to leave this largely on the level of stylistic rules, thus stressing the language nature of the diff. -Even when this bears the danger to produce an exception very late, when it comes to applying the diff to a target +Even when this bears the danger to raise failures rather late, when it comes to applying the diff to a target data structure. The intention behind this whole diff approach is to transform tight coupling with strict rules into a loose collaboration based on a common understanding. So generally we'll assume the diff is just right, and if not, we'll get what we deserve.footnote:[This gives rise to a tricky discussion about loss of strictness diff --git a/tests/library/diff/diff-tree-application-simple-test.cpp b/tests/library/diff/diff-tree-application-simple-test.cpp index 792639b85..adf82b2a1 100644 --- a/tests/library/diff/diff-tree-application-simple-test.cpp +++ b/tests/library/diff/diff-tree-application-simple-test.cpp @@ -63,6 +63,12 @@ namespace test{ ,[](GenNode const& n) { return n.data.get(); } )); } + + string + contents (vector const& strings) + { + return util::join (strings); + } }//(End)Test fixture @@ -104,7 +110,7 @@ namespace test{ run (Arg) { demo_one(); -// demo_two(); + demo_two(); } /** @@ -132,7 +138,7 @@ namespace test{ demo_one() { Rec::Mutator subject; - subject.scope(VAL_A, VAL_B, VAL_C); + subject.scope (VAL_A, VAL_B, VAL_C); CHECK ("a, b, c" == contents(subject)); @@ -140,6 +146,37 @@ namespace test{ CHECK ("a, d, c" == contents(subject)); } + + + /** @test mutate a STL collection opaquely by applying the sample diff */ + void + demo_two() + { + struct Opaque + : DiffMutable + , std::vector + { + using std::vector::vector; + + void + buildMutator (TreeMutator::Handle buff) override + { + buff.create ( + TreeMutator::build() + .attach (collection (static_cast&> (*this)) + )); + } + + }; + + + Opaque subject{"a","b","c"}; + CHECK ("a, b, c" == contents(subject)); + + DiffApplicator{subject}.consume (someDiff()); + + CHECK ("a, d, c" == contents(subject)); + } };