Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
tree-mutator-test.cpp
Go to the documentation of this file.
1/*
2 TreeMutator(Test) - customisable intermediary to abstract tree changing operations
3
4 Copyright (C)
5 2015, 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
19#include "lib/test/run.hpp"
20#include "lib/format-util.hpp"
23#include "lib/format-cout.hpp"
24#include "lib/format-util.hpp"
25#include "lib/util.hpp"
26
27#include <string>
28#include <vector>
29
30using util::isnil;
31using util::join;
32using util::typeStr;
33
34using std::string;
35using std::vector;
36
37
38namespace lib {
39namespace diff{
40namespace test{
41
42
43
44
45
46 /*****************************************************************************/
59 class TreeMutator_test : public Test
60 {
61
62 virtual void
68
69
70 void
72 {
74 string localData;
75 auto mutator =
77 .change("data", [&](string val)
78 {
79 cout << "\"data\" closure received something "<<val<<endl;
80 localData = val;
81 });
82
83 cout << "concrete TreeMutator size=" << sizeof(mutator)
84 << " type="<< typeStr(mutator)
85 << endl;
86
87 mutator.init();
88
89 CHECK (isnil (localData));
90 string testValue{"that would be acceptable"};
91 mutator.assignElm ({"lore", testValue});
92 CHECK ( isnil (localData)); // nothing happens, nothing changed
93 mutator.assignElm ({"data", testValue});
94 CHECK (!isnil (localData));
95 cout << "localData changed to: "<<localData<<endl;
96 CHECK (localData == "that would be acceptable");
97 }
98
99
100 void
102 {
104 vector<string> values;
105 values.push_back("a");
106 values.push_back("b");
107
108 cout << join(values) <<endl;
109 CHECK (2 == values.size());
110 CHECK ("a, b" == join(values));
111
112 auto mutator =
114 .attach (collection(values));
115
116 cout << "concrete TreeMutator size=" << sizeof(mutator)
117 << " type="<< typeStr(mutator)
118 << endl;
119
120 mutator.init();
121
122 CHECK (isnil (values));
123 CHECK (mutator.matchSrc (GenNode("a")));
124 mutator.skipSrc (GenNode("a"));
125 CHECK (mutator.matchSrc (GenNode("b")));
126 CHECK (mutator.injectNew (GenNode("c")));
127 CHECK (mutator.acceptSrc (GenNode("b")));
128
129 cout << join(values) <<endl;
130 CHECK (2 == values.size());
131 CHECK ("c, b" == join(values));
132 }
133 };
134
135
137 LAUNCHER (TreeMutator_test, "unit common");
138
139
140
141}}} // namespace lib::diff::test
static Builder< TreeMutator > build()
DSL: start building a custom adapted tree mutator, where the operations are tied by closures or wrapp...
Automatically use custom string conversion in C++ stream output.
Collection of small helpers and convenience shortcuts for diagnostics & formatting.
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
string join(COLL &&coll, string const &delim=", ")
enumerate a collection's contents, separated by delimiter.
bool isnil(lib::time::Duration const &dur)
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
A collection of frequently used helper functions to support unit testing.
#define MARK_TEST_FUN
Macro to mark the current test function in STDOUT.
Customisable intermediary to abstract generic tree mutation operations.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...