* Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
141 lines
4 KiB
C++
141 lines
4 KiB
C++
/*
|
||
TreeMutator(Test) - customisable intermediary to abstract tree changing operations
|
||
|
||
Copyright (C)
|
||
2015, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
**Lumiera** is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU General Public License as published by the
|
||
Free Software Foundation; either version 2 of the License, or (at your
|
||
option) any later version. See the file COPYING for further details.
|
||
|
||
* *****************************************************************/
|
||
|
||
/** @file tree-mutator-test.cpp
|
||
** unit test \ref TreeMutator_test
|
||
*/
|
||
|
||
|
||
#include "lib/test/run.hpp"
|
||
#include "lib/format-util.hpp"
|
||
#include "lib/test/test-helper.hpp"
|
||
#include "lib/diff/tree-mutator.hpp"
|
||
#include "lib/format-cout.hpp"
|
||
#include "lib/format-util.hpp"
|
||
#include "lib/util.hpp"
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
using util::isnil;
|
||
using util::join;
|
||
using util::typeStr;
|
||
|
||
using std::string;
|
||
using std::vector;
|
||
|
||
|
||
namespace lib {
|
||
namespace diff{
|
||
namespace test{
|
||
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************//**
|
||
* @test Demonstrate a customisable component for flexible bindings
|
||
* to enable generic tree changing and mutating operations to
|
||
* arbitrary hierarchical data structures.
|
||
* - we use lambdas to link into our private implementation
|
||
* - this test demonstrates the behaviour of an attribute setter
|
||
* - plus some of the _primitive operations_ available on collections
|
||
*
|
||
* @see TreeMutator
|
||
* @see DiffComplexApplication_test a way more complex usage scenario
|
||
* @see GenNode_test
|
||
* @see GenericRecord_test
|
||
*/
|
||
class TreeMutator_test : public Test
|
||
{
|
||
|
||
virtual void
|
||
run (Arg)
|
||
{
|
||
simpleAttributeBinding();
|
||
simpleCollectionBinding();
|
||
}
|
||
|
||
|
||
void
|
||
simpleAttributeBinding()
|
||
{
|
||
MARK_TEST_FUN;
|
||
string localData;
|
||
auto mutator =
|
||
TreeMutator::build()
|
||
.change("data", [&](string val)
|
||
{
|
||
cout << "\"data\" closure received something "<<val<<endl;
|
||
localData = val;
|
||
});
|
||
|
||
cout << "concrete TreeMutator size=" << sizeof(mutator)
|
||
<< " type="<< typeStr(mutator)
|
||
<< endl;
|
||
|
||
mutator.init();
|
||
|
||
CHECK (isnil (localData));
|
||
string testValue{"that would be acceptable"};
|
||
mutator.assignElm ({"lore", testValue});
|
||
CHECK ( isnil (localData)); // nothing happens, nothing changed
|
||
mutator.assignElm ({"data", testValue});
|
||
CHECK (!isnil (localData));
|
||
cout << "localData changed to: "<<localData<<endl;
|
||
CHECK (localData == "that would be acceptable");
|
||
}
|
||
|
||
|
||
void
|
||
simpleCollectionBinding()
|
||
{
|
||
MARK_TEST_FUN;
|
||
vector<string> values;
|
||
values.push_back("a");
|
||
values.push_back("b");
|
||
|
||
cout << join(values) <<endl;
|
||
CHECK (2 == values.size());
|
||
CHECK ("a, b" == join(values));
|
||
|
||
auto mutator =
|
||
TreeMutator::build()
|
||
.attach (collection(values));
|
||
|
||
cout << "concrete TreeMutator size=" << sizeof(mutator)
|
||
<< " type="<< typeStr(mutator)
|
||
<< endl;
|
||
|
||
mutator.init();
|
||
|
||
CHECK (isnil (values));
|
||
CHECK (mutator.matchSrc (GenNode("a")));
|
||
mutator.skipSrc (GenNode("a"));
|
||
CHECK (mutator.matchSrc (GenNode("b")));
|
||
CHECK (mutator.injectNew (GenNode("c")));
|
||
CHECK (mutator.acceptSrc (GenNode("b")));
|
||
|
||
cout << join(values) <<endl;
|
||
CHECK (2 == values.size());
|
||
CHECK ("c, b" == join(values));
|
||
}
|
||
};
|
||
|
||
|
||
/** Register this test class... */
|
||
LAUNCHER (TreeMutator_test, "unit common");
|
||
|
||
|
||
|
||
}}} // namespace lib::diff::test
|