Lumiera  0.pre.03
»edit your freedom«
diff-tree-application-simple-test.cpp
Go to the documentation of this file.
1 /*
2  DiffTreeApplicationSimple(Test) - demonstrate the basics of tree diff representation
3 
4  Copyright (C) Lumiera.org
5  2019, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
30 #include "lib/test/run.hpp"
33 #include "lib/format-util.hpp"
34 #include "lib/util.hpp"
35 
36 #include <string>
37 #include <vector>
38 
39 using std::string;
40 using std::vector;
41 
42 
43 namespace lib {
44 namespace diff{
45 namespace test{
46 
47  namespace {//Test fixture....
48 
49  // some symbolic values to be used within the diff
50  const GenNode VAL_A("a"),
51  VAL_B("b"),
52  VAL_C("c"),
53  VAL_D("d");
54 
56  string
57  contents (Rec const& object)
58  {
59  return util::join (transformIterator (object.scope()
60  ,[](GenNode const& n) { return n.data.get<string>(); }
61  ));
62  }
63 
64  string
65  contents (vector<string> const& strings)
66  {
67  return util::join (strings);
68  }
69  }//(End)Test fixture
70 
71 
72 
73 
74 
75 
76 
77 
78 
79  /****************************************************************************/
102  : public Test
104  {
105 
106  virtual void
107  run (Arg)
108  {
109  demo_one();
110  demo_two();
111  }
112 
124  {
125  return { pick(VAL_A)
126  , ins (VAL_D)
127  , del (VAL_B)
128  , pick(VAL_C)
129  };
130  }
131 
132 
134  void
136  {
137  Rec::Mutator subject;
138  subject.scope (VAL_A, VAL_B, VAL_C);
139 
140  CHECK ("a, b, c" == contents(subject));
141 
142  DiffApplicator<Rec::Mutator>{subject}.consume (someDiff());
143 
144  CHECK ("a, d, c" == contents(subject));
145  }
146 
147 
149  void
151  {
152  struct Opaque
153  : DiffMutable
154  , std::vector<string>
155  {
156  using std::vector<string>::vector;
157 
158  void
159  buildMutator (TreeMutator::Handle buff) override
160  {
161  buff.emplace(
163  .attach (collection (*this)
164  ));
165  }
166 
167  };
168 
169 
170  Opaque subject{"a","b","c"};
171  CHECK ("a, b, c" == contents(subject));
172 
173  DiffApplicator<Opaque>{subject}.consume (someDiff());
174 
175  CHECK ("a, d, c" == contents(subject));
176  }
177  };
178 
179 
181  LAUNCHER (DiffTreeApplicationSimple_test, "unit common");
182 
183 
184 
185 }}} // namespace lib::diff::test
Concrete implementation to apply structural changes to hierarchical data structures.
Generic Message with an embedded diff, to describe changes to model elements.
Definition: run.hpp:49
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
Implementation namespace for support and library code.
static Builder< TreeMutator > build()
DSL: start building a custom adapted tree mutator, where the operations are tied by closures or wrapp...
SUB & emplace(SUB &&implementation)
move-construct an instance of a subclass into the opaque buffer
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Collection of small helpers and convenience shortcuts for diagnostics & formatting.
auto collection(COLL &coll)
Entry point to a nested DSL for setup and configuration of a collection binding.
auto transformIterator(IT const &src, FUN processingFunc)
Build a TransformIter: convenience free function shortcut, picking up the involved types automaticall...
Definition: itertools.hpp:797
object-like record of data.
Definition: record.hpp:150
MutationMessage someDiff()
a change represented symbolically as »diff sequence«.
string contents(Rec const &object)
render the child elements as string data for test/verification
generic data element node within a tree
Definition: gen-node.hpp:231
Marker or capability interface: an otherwise not further disclosed data structure, which can be transformed through "tree diff messages".
generic builder to apply a diff description to a given target data structure.