Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
30using std::string;
31using std::vector;
32
33
34namespace lib {
35namespace diff{
36namespace 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
145 , std::vector<string>
146 {
147 using std::vector<string>::vector;
148
149 void
150 buildMutator (TreeMutator::Handle buff) override
151 {
152 buff.emplace(
153 TreeMutator::build()
154 .attach (collection (*this)
155 ));
156 }
157
158 };
159
160
161 Opaque subject{"a","b","c"};
162 CHECK ("a, b, c" == contents(subject));
163
165
166 CHECK ("a, d, c" == contents(subject));
167 }
168 };
169
170
173
174
175
176}}} // namespace lib::diff::test
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
SUB & emplace(SUB &&implementation)
move-construct an instance of a subclass into the opaque buffer
generic builder to apply a diff description to a given target data structure.
Marker or capability interface: an otherwise not further disclosed data structure,...
Mutator && scope(X const &initialiser, ARGS &&...args)
Definition record.hpp:578
object-like record of data.
Definition record.hpp:142
MutationMessage someDiff()
a change represented symbolically as »diff sequence«.
Collection of small helpers and convenience shortcuts for diagnostics & formatting.
Generic Message with an embedded diff, to describe changes to model elements.
string contents(Rec const &object)
render the child elements as string data for test/verification
Implementation namespace for support and library code.
auto transformIterator(IT const &src, FUN processingFunc)
Build a TransformIter: convenience free function shortcut, picking up the involved types automaticall...
Test runner and basic definitions for tests.
string join(COLL &&coll, string const &delim=", ")
enumerate a collection's contents, separated by delimiter.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
generic data element node within a tree
Definition gen-node.hpp:224
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
Concrete implementation to apply structural changes to hierarchical data structures.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...