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)
5  2019, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
21 #include "lib/test/run.hpp"
24 #include "lib/format-util.hpp"
25 #include "lib/util.hpp"
26 
27 #include <string>
28 #include <vector>
29 
30 using std::string;
31 using std::vector;
32 
33 
34 namespace lib {
35 namespace diff{
36 namespace test{
37 
38  namespace {//Test fixture....
39 
40  // some symbolic values to be used within the diff
41  const GenNode VAL_A("a"),
42  VAL_B("b"),
43  VAL_C("c"),
44  VAL_D("d");
45 
47  string
48  contents (Rec const& object)
49  {
50  return util::join (transformIterator (object.scope()
51  ,[](GenNode const& n) { return n.data.get<string>(); }
52  ));
53  }
54 
55  string
56  contents (vector<string> const& strings)
57  {
58  return util::join (strings);
59  }
60  }//(End)Test fixture
61 
62 
63 
64 
65 
66 
67 
68 
69 
70  /****************************************************************************/
93  : public Test
95  {
96 
97  virtual void
98  run (Arg)
99  {
100  demo_one();
101  demo_two();
102  }
103 
115  {
116  return { pick(VAL_A)
117  , ins (VAL_D)
118  , del (VAL_B)
119  , pick(VAL_C)
120  };
121  }
122 
123 
125  void
127  {
128  Rec::Mutator subject;
129  subject.scope (VAL_A, VAL_B, VAL_C);
130 
131  CHECK ("a, b, c" == contents(subject));
132 
133  DiffApplicator<Rec::Mutator>{subject}.consume (someDiff());
134 
135  CHECK ("a, d, c" == contents(subject));
136  }
137 
138 
140  void
142  {
143  struct Opaque
144  : DiffMutable
145  , std::vector<string>
146  {
147  using std::vector<string>::vector;
148 
149  void
150  buildMutator (TreeMutator::Handle buff) override
151  {
152  buff.emplace(
154  .attach (collection (*this)
155  ));
156  }
157 
158  };
159 
160 
161  Opaque subject{"a","b","c"};
162  CHECK ("a, b, c" == contents(subject));
163 
164  DiffApplicator<Opaque>{subject}.consume (someDiff());
165 
166  CHECK ("a, d, c" == contents(subject));
167  }
168  };
169 
170 
172  LAUNCHER (DiffTreeApplicationSimple_test, "unit common");
173 
174 
175 
176 }}} // 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:40
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:104
Simplistic 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:788
object-like record of data.
Definition: record.hpp:141
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:222
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.