2016-02-19 20:25:30 +01:00
|
|
|
|
/*
|
|
|
|
|
|
DiffVirtualisedApplication(Test) - apply structural changes to unspecific private data structures
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2016, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/format-util.hpp"
|
2016-07-28 01:17:50 +02:00
|
|
|
|
#include "lib/diff/tree-diff-application.hpp"
|
2016-07-30 23:22:46 +02:00
|
|
|
|
#include "lib/diff/test-mutation-target.hpp"
|
2016-02-19 20:25:30 +01:00
|
|
|
|
#include "lib/iter-adapter-stl.hpp"
|
|
|
|
|
|
#include "lib/time/timevalue.hpp"
|
2016-06-10 04:30:02 +02:00
|
|
|
|
#include "lib/format-string.hpp"
|
2016-08-29 19:39:19 +02:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2016-02-19 20:25:30 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
2016-06-10 04:30:02 +02:00
|
|
|
|
#include <memory>
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
using util::join;
|
2016-06-10 04:30:02 +02:00
|
|
|
|
using util::_Fmt;
|
2016-08-29 19:39:19 +02:00
|
|
|
|
using util::BOTTOM_INDICATOR;
|
|
|
|
|
|
using lib::iter_stl::snapshot;
|
|
|
|
|
|
using lib::time::Time;
|
2016-06-10 04:30:02 +02:00
|
|
|
|
using std::unique_ptr;
|
2016-02-19 20:25:30 +01:00
|
|
|
|
using std::string;
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace diff{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
namespace {//Test fixture....
|
|
|
|
|
|
|
|
|
|
|
|
// define some GenNode elements
|
|
|
|
|
|
// to act as templates within the concrete diff
|
|
|
|
|
|
// NOTE: everything in this diff language is by-value
|
2016-06-09 02:15:50 +02:00
|
|
|
|
const GenNode ATTRIB1("α", 1), // attribute α = 1
|
2016-02-19 20:25:30 +01:00
|
|
|
|
ATTRIB2("β", int64_t(2)), // attribute α = 2L (int64_t)
|
|
|
|
|
|
ATTRIB3("γ", 3.45), // attribute γ = 3.45 (double)
|
2016-06-09 02:15:50 +02:00
|
|
|
|
TYPE_X("type", "ξ"), // a "magic" type attribute "Xi"
|
|
|
|
|
|
TYPE_Z("type", "ζ"), //
|
2016-02-19 20:25:30 +01:00
|
|
|
|
CHILD_A("a"), // unnamed string child node
|
|
|
|
|
|
CHILD_B('b'), // unnamed char child node
|
|
|
|
|
|
CHILD_T(Time(12,34,56,78)), // unnamed time value child
|
|
|
|
|
|
SUB_NODE = MakeRec().genNode(), // empty anonymous node used to open a sub scope
|
|
|
|
|
|
ATTRIB_NODE = MakeRec().genNode("δ"), // empty named node to be attached as attribute δ
|
2016-06-10 04:30:02 +02:00
|
|
|
|
GAMMA_PI("γ", 3.14159265); // happens to have the same identity (ID) as ATTRIB3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* opaque private data structure to apply the diff.
|
|
|
|
|
|
* This class offers to build a binding for diff messages,
|
|
|
|
|
|
* which basically maps its internal structures onto the
|
|
|
|
|
|
* generic "object" scheme underlying the diff language.
|
|
|
|
|
|
*/
|
|
|
|
|
|
class Opaque
|
|
|
|
|
|
{
|
2016-08-26 02:42:19 +02:00
|
|
|
|
idi::BareEntryID key_;
|
2016-07-30 23:22:46 +02:00
|
|
|
|
string type_ = Rec::TYPE_NIL;
|
|
|
|
|
|
|
2016-06-10 04:30:02 +02:00
|
|
|
|
int alpha_ = -1;
|
2016-08-25 17:48:40 +02:00
|
|
|
|
int64_t beta_ = -1;
|
2016-06-10 04:30:02 +02:00
|
|
|
|
double gamma_ = -1;
|
|
|
|
|
|
|
|
|
|
|
|
unique_ptr<Opaque> delta_;
|
|
|
|
|
|
|
|
|
|
|
|
vector<Opaque> nestedObj_;
|
|
|
|
|
|
vector<string> nestedData_;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2016-08-26 02:42:19 +02:00
|
|
|
|
Opaque()
|
|
|
|
|
|
: key_(idi::EntryID<Opaque>())
|
|
|
|
|
|
{ }
|
2016-06-10 04:30:02 +02:00
|
|
|
|
|
2016-07-30 23:22:46 +02:00
|
|
|
|
explicit
|
|
|
|
|
|
Opaque (string keyID)
|
2016-08-26 02:42:19 +02:00
|
|
|
|
: key_(idi::EntryID<Opaque>(keyID))
|
2016-07-30 23:22:46 +02:00
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
explicit
|
|
|
|
|
|
Opaque (idi::BareEntryID id)
|
|
|
|
|
|
: key_(id)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
Opaque (Opaque const& o)
|
|
|
|
|
|
: key_(o.key_)
|
|
|
|
|
|
, type_(o.type_)
|
|
|
|
|
|
, alpha_(o.alpha_)
|
|
|
|
|
|
, beta_(o.beta_)
|
|
|
|
|
|
, gamma_(o.gamma_)
|
|
|
|
|
|
, delta_()
|
|
|
|
|
|
, nestedObj_(o.nestedObj_)
|
|
|
|
|
|
, nestedData_(o.nestedData_)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (o.delta_)
|
|
|
|
|
|
delta_.reset(new Opaque(*o.delta_));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Opaque&
|
|
|
|
|
|
operator= (Opaque const& o)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (&o != this)
|
|
|
|
|
|
{
|
|
|
|
|
|
Opaque tmp(o);
|
|
|
|
|
|
swap (*this, tmp);
|
|
|
|
|
|
}
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 19:39:19 +02:00
|
|
|
|
bool verifyType(string x) const { return x == type_; }
|
|
|
|
|
|
bool verifyAlpha(int x) const { return x == alpha_;}
|
|
|
|
|
|
bool verifyBeta(int64_t x) const { return x == beta_; }
|
|
|
|
|
|
bool verifyGamma(double x) const { return x == gamma_;}
|
|
|
|
|
|
bool verifyData(string desc) const { return desc == join(nestedData_); }
|
|
|
|
|
|
const Opaque* nestedDelta() const { return not delta_? NULL : delta_.get(); }
|
|
|
|
|
|
const Opaque* nestedObj_1() const { return isnil(nestedObj_)? NULL : &nestedObj_[0]; }
|
|
|
|
|
|
|
2016-07-30 23:22:46 +02:00
|
|
|
|
|
2016-06-10 04:30:02 +02:00
|
|
|
|
operator string() const
|
|
|
|
|
|
{
|
2016-08-26 02:42:19 +02:00
|
|
|
|
return _Fmt{"%s__(α:%d β:%s γ:%7.5f δ:%s\n......|nested:%s\n......|data:%s\n )__END_%s"}
|
2016-07-30 23:22:46 +02:00
|
|
|
|
% identity()
|
2016-06-10 04:30:02 +02:00
|
|
|
|
% alpha_
|
|
|
|
|
|
% beta_
|
|
|
|
|
|
% gamma_
|
|
|
|
|
|
% delta_
|
2016-08-26 02:42:19 +02:00
|
|
|
|
% join (nestedObj_, "\n......|")
|
2016-06-10 04:30:02 +02:00
|
|
|
|
% join (nestedData_)
|
2016-08-26 02:42:19 +02:00
|
|
|
|
% identity()
|
2016-06-10 04:30:02 +02:00
|
|
|
|
;
|
|
|
|
|
|
}
|
2016-06-11 19:40:53 +02:00
|
|
|
|
|
2016-07-30 23:22:46 +02:00
|
|
|
|
string
|
|
|
|
|
|
identity() const
|
|
|
|
|
|
{
|
|
|
|
|
|
string symbol = key_.getSym() + (isTyped()? "≺"+type_+"≻" : "");
|
|
|
|
|
|
return lib::idi::format::instance_hex_format(symbol, key_.getHash());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
isTyped() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Rec::TYPE_NIL != type_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-29 19:39:19 +02:00
|
|
|
|
/** the _only way_ this opaque object exposes itself for mutation through diff messages.
|
|
|
|
|
|
* This function builds a TreeMutator implementation into the given buffer space
|
|
|
|
|
|
* @note some crucial details for this binding to work properly...
|
|
|
|
|
|
* - we define several "onion layers" of binding to deal with various scopes.
|
|
|
|
|
|
* - the priority of these bindings is ordered from lowest to highest
|
|
|
|
|
|
* - actually this is a quite complicated setup, including object fields
|
|
|
|
|
|
* to represent attributes, where one special attribute which actually holds
|
|
|
|
|
|
* a nested object, then both a collection of child objects and a collection
|
|
|
|
|
|
* of data values
|
|
|
|
|
|
* - the selector predicate (`isApplicableIf`) actually decides if a binding layer
|
|
|
|
|
|
* becomes responsible for a given diff verb. Here, this decision is based on
|
|
|
|
|
|
* the classification of the verb or spec to be handled, either being an
|
|
|
|
|
|
* attribute (named, key-value pair), a nested sub-scope ("object") and
|
|
|
|
|
|
* finally just any unnamed (non attribute) value
|
|
|
|
|
|
* - the recursive mutation of nested scopes is simply initiated by invoking
|
|
|
|
|
|
* the same Opaque::buildMutator on the respective children recursively.
|
|
|
|
|
|
* - such an unusually complicated TreeMutator binding leads to increased
|
|
|
|
|
|
* buffer space requirements for the actual TreeMutator to be generated;
|
|
|
|
|
|
* Thus we need to implement the _extension point_ treeMutatorSize()
|
|
|
|
|
|
* to supply a sufficient buffer size value. This function is
|
|
|
|
|
|
* picked up through ADL, based on the target type `Opaque`
|
|
|
|
|
|
*/
|
2016-06-14 02:33:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
buildMutator (TreeMutator::Handle buff)
|
2016-06-11 19:40:53 +02:00
|
|
|
|
{
|
2016-06-14 02:33:28 +02:00
|
|
|
|
buff.create (
|
|
|
|
|
|
TreeMutator::build()
|
|
|
|
|
|
.attach (collection(nestedData_)
|
2016-07-30 23:22:46 +02:00
|
|
|
|
.isApplicableIf ([&](GenNode const& spec) -> bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return not spec.isNamed(); // »Selector« : accept anything unnamed value-like
|
|
|
|
|
|
})
|
2016-08-25 17:48:40 +02:00
|
|
|
|
.matchElement ([&](GenNode const& spec, string const& elm) -> bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return elm == render(spec.data);
|
|
|
|
|
|
})
|
2016-08-08 14:20:54 +02:00
|
|
|
|
.constructFrom ([&](GenNode const& spec) -> string
|
|
|
|
|
|
{
|
2016-08-25 17:48:40 +02:00
|
|
|
|
return render (spec.data);
|
2016-08-08 14:20:54 +02:00
|
|
|
|
})
|
2016-07-30 23:22:46 +02:00
|
|
|
|
.assignElement ([&](string& target, GenNode const& spec) -> bool
|
|
|
|
|
|
{
|
2016-08-25 17:48:40 +02:00
|
|
|
|
target = render (spec.data);
|
2016-07-30 23:22:46 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
}))
|
|
|
|
|
|
.attach (collection(nestedObj_)
|
|
|
|
|
|
.isApplicableIf ([&](GenNode const& spec) -> bool
|
|
|
|
|
|
{
|
2016-09-01 22:58:08 +02:00
|
|
|
|
return spec.data.isNested(); // »Selector« : require object-like sub scope
|
2016-07-30 23:22:46 +02:00
|
|
|
|
})
|
|
|
|
|
|
.matchElement ([&](GenNode const& spec, Opaque const& elm) -> bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return spec.idi == elm.key_;
|
|
|
|
|
|
})
|
2016-08-25 17:48:40 +02:00
|
|
|
|
.constructFrom ([&](GenNode const& spec) -> Opaque
|
|
|
|
|
|
{
|
|
|
|
|
|
return Opaque{spec.idi};
|
|
|
|
|
|
})
|
2016-07-30 23:22:46 +02:00
|
|
|
|
.buildChildMutator ([&](Opaque& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool
|
|
|
|
|
|
{
|
2016-07-31 00:32:03 +02:00
|
|
|
|
if (target.key_ != subID) return false; // require match on already existing child object
|
2016-07-30 23:22:46 +02:00
|
|
|
|
target.buildMutator (buff); // delegate to child to build nested TreeMutator
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}))
|
|
|
|
|
|
.change("type", [&](string typeID)
|
|
|
|
|
|
{
|
|
|
|
|
|
type_ = typeID;
|
|
|
|
|
|
})
|
|
|
|
|
|
.change("α", [&](int val)
|
|
|
|
|
|
{
|
|
|
|
|
|
alpha_ = val;
|
|
|
|
|
|
})
|
2016-08-25 17:48:40 +02:00
|
|
|
|
.change("β", [&](int64_t val)
|
2016-07-30 23:22:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
beta_ = val;
|
|
|
|
|
|
})
|
|
|
|
|
|
.change("γ", [&](double val)
|
|
|
|
|
|
{
|
|
|
|
|
|
gamma_ = val;
|
|
|
|
|
|
})
|
|
|
|
|
|
.mutateAttrib("δ", [&](TreeMutator::Handle buff)
|
|
|
|
|
|
{
|
2016-08-26 02:56:48 +02:00
|
|
|
|
if (not delta_) // note: object managed automatically,
|
|
|
|
|
|
delta_.reset (new Opaque("δ")); // no INS-implementation necessary
|
2016-07-30 23:22:46 +02:00
|
|
|
|
REQUIRE (delta_);
|
|
|
|
|
|
|
|
|
|
|
|
delta_->buildMutator(buff);
|
|
|
|
|
|
}));
|
2016-06-11 19:40:53 +02:00
|
|
|
|
}
|
2016-07-30 23:22:46 +02:00
|
|
|
|
|
2016-07-31 00:32:03 +02:00
|
|
|
|
/** override default size traits
|
|
|
|
|
|
* to allow for sufficient buffer,
|
|
|
|
|
|
* able to hold the mutator defined above.
|
|
|
|
|
|
*/
|
2016-07-30 23:22:46 +02:00
|
|
|
|
friend constexpr size_t
|
|
|
|
|
|
treeMutatorSize (const Opaque*)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 350;
|
|
|
|
|
|
}
|
2016-06-10 04:30:02 +02:00
|
|
|
|
};
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
}//(End)Test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************//**
|
2016-03-19 01:42:27 +01:00
|
|
|
|
* @test Demonstration: apply a structural change to unspecified private
|
2016-02-19 21:33:22 +01:00
|
|
|
|
* data structures, with the help of an [dynamic adapter](\ref TreeMutator)
|
|
|
|
|
|
* - we use private data classes, defined here in the test fixture
|
|
|
|
|
|
* to represent "just some" pre-existing data structure.
|
|
|
|
|
|
* - we re-assign some attribute values
|
|
|
|
|
|
* - we add, re-order and delete child "elements", without knowing
|
|
|
|
|
|
* what these elements actually are and how they are to be handled.
|
|
|
|
|
|
* - we recurse into mutating such an _"unspecified"_ child element.
|
2016-04-30 00:26:19 +02:00
|
|
|
|
*
|
2016-06-10 03:19:33 +02:00
|
|
|
|
* @note this test uses the same verb sequence as is assumed for the
|
|
|
|
|
|
* coverage of diff building blocks in TreeMutatorBinding_test
|
2016-04-30 00:26:19 +02:00
|
|
|
|
*
|
2016-02-19 21:33:22 +01:00
|
|
|
|
* @see DiffTreeApplication_test generic variant of tree diff application
|
2016-06-10 03:19:33 +02:00
|
|
|
|
* @see TreeMutatorBinding_test coverage of the "building blocks"
|
2016-02-26 22:57:49 +01:00
|
|
|
|
* @see TreeMutator_test base operations of the adapter
|
2016-02-19 20:25:30 +01:00
|
|
|
|
* @see diff-tree-application.hpp
|
|
|
|
|
|
* @see tree-diff.hpp
|
|
|
|
|
|
*/
|
2016-08-29 17:52:35 +02:00
|
|
|
|
class DiffComplexApplication_test
|
2016-02-19 20:25:30 +01:00
|
|
|
|
: public Test
|
|
|
|
|
|
, TreeDiffLanguage
|
|
|
|
|
|
{
|
|
|
|
|
|
using DiffSeq = iter_stl::IterSnapshot<DiffStep>;
|
|
|
|
|
|
|
|
|
|
|
|
DiffSeq
|
2016-06-09 02:15:50 +02:00
|
|
|
|
populationDiff()
|
2016-02-19 20:25:30 +01:00
|
|
|
|
{
|
2016-06-09 02:15:50 +02:00
|
|
|
|
return snapshot({ins(ATTRIB1)
|
2016-02-19 20:25:30 +01:00
|
|
|
|
, ins(ATTRIB3)
|
2016-06-09 02:15:50 +02:00
|
|
|
|
, ins(ATTRIB3)
|
|
|
|
|
|
, ins(CHILD_B)
|
|
|
|
|
|
, ins(CHILD_B)
|
|
|
|
|
|
, ins(CHILD_T)
|
2016-02-19 21:33:22 +01:00
|
|
|
|
});
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
} // ==> ATTRIB1, ATTRIB3, (ATTRIB3), CHILD_B, CHILD_B, CHILD_T
|
2016-02-19 21:33:22 +01:00
|
|
|
|
|
|
|
|
|
|
DiffSeq
|
2016-06-09 02:15:50 +02:00
|
|
|
|
reorderingDiff()
|
2016-02-19 21:33:22 +01:00
|
|
|
|
{
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
return snapshot({after(Ref::ATTRIBS)
|
2016-06-09 02:15:50 +02:00
|
|
|
|
, ins(ATTRIB2)
|
|
|
|
|
|
, del(CHILD_B)
|
|
|
|
|
|
, ins(SUB_NODE)
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
, find(CHILD_T)
|
2016-06-09 02:15:50 +02:00
|
|
|
|
, pick(CHILD_B)
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
, skip(CHILD_T)
|
2016-02-19 20:25:30 +01:00
|
|
|
|
});
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
} // ==> ATTRIB1, ATTRIB3, (ATTRIB3), ATTRIB2, SUB_NODE, CHILD_T, CHILD_B
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
DiffSeq
|
|
|
|
|
|
mutationDiff()
|
|
|
|
|
|
{
|
2016-06-10 03:19:33 +02:00
|
|
|
|
return snapshot({after(CHILD_B)
|
|
|
|
|
|
, after(Ref::END)
|
2016-06-09 02:15:50 +02:00
|
|
|
|
, set(GAMMA_PI)
|
|
|
|
|
|
, mut(SUB_NODE)
|
|
|
|
|
|
, ins(TYPE_X)
|
|
|
|
|
|
, ins(ATTRIB2)
|
|
|
|
|
|
, ins(CHILD_B)
|
|
|
|
|
|
, ins(CHILD_A)
|
|
|
|
|
|
, emu(SUB_NODE)
|
|
|
|
|
|
, ins(ATTRIB_NODE)
|
|
|
|
|
|
, mut(ATTRIB_NODE)
|
|
|
|
|
|
, ins(TYPE_Z)
|
|
|
|
|
|
, ins(CHILD_A)
|
|
|
|
|
|
, ins(CHILD_A)
|
|
|
|
|
|
, ins(CHILD_A)
|
|
|
|
|
|
, emu(ATTRIB_NODE)
|
2016-02-19 20:25:30 +01:00
|
|
|
|
});
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
} // ==> ATTRIB1, ATTRIB3 := π, (ATTRIB3), ATTRIB2,
|
2016-06-10 02:48:22 +02:00
|
|
|
|
// ATTRIB_NODE{ type ζ, CHILD_A, CHILD_A, CHILD_A }
|
2016-06-09 02:15:50 +02:00
|
|
|
|
// SUB_NODE{ type ξ, ATTRIB2, CHILD_B, CHILD_A },
|
reshape test diff to be more in line with the newly written implementation
...during implementation of the binding, I decided to be more strict
with the interpretation of "reshaping" of attributes: since my onion-layer
for attribute binding works without the notion of any 'position' or 'ordering',
I made up my mind that it's best outright to reject any diff verbs attempting
to re-order or delete attributes. The rationale is that otherwise the same diff
might lead to substantially different results when applied to a Rec<GenNode>
as when applied to a target data structure bound via TreeMutator.
Consequently, the previously established test diff sequence would raise an error::Logic
in the second segment, since it attempts to re-order attributes. Instead of this,
I've now introduced a after(Ref::ATTRIBS) verb and I'm re-ordering children
rather than attributes.
Unfortunately this also prompts me to re-adjust all of the TreeMutatorBinding_tests,
since these detail tests are intended to play the same sequence on low level.
This is not a fundamental problem, though, just laborious. CHECK (target.showContent() == "α = 1, γ = 3.45, γ = 3.45, β = 2, Rec(), 78:56:34.012, b");
2016-08-13 17:50:40 +02:00
|
|
|
|
// CHILD_T, CHILD_B
|
2016-06-09 02:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2016-06-11 19:40:53 +02:00
|
|
|
|
Opaque subject;
|
2016-07-28 22:58:21 +02:00
|
|
|
|
DiffApplicator<Opaque> application(subject);
|
2016-06-09 02:15:50 +02:00
|
|
|
|
//
|
|
|
|
|
|
cout << "before..."<<endl << subject<<endl;
|
2016-08-29 19:39:19 +02:00
|
|
|
|
CHECK (subject.verifyAlpha(-1));
|
|
|
|
|
|
CHECK (subject.verifyBeta(-1));
|
|
|
|
|
|
CHECK (subject.verifyGamma(-1));
|
|
|
|
|
|
CHECK (not subject.nestedDelta());
|
|
|
|
|
|
CHECK (not subject.nestedObj_1());
|
|
|
|
|
|
CHECK (subject.verifyData(""));
|
|
|
|
|
|
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
2016-02-19 21:33:22 +01:00
|
|
|
|
// Part I : apply attribute changes
|
2016-02-19 20:25:30 +01:00
|
|
|
|
application.consume(populationDiff());
|
2016-06-09 02:15:50 +02:00
|
|
|
|
//
|
|
|
|
|
|
cout << "after...I"<<endl << subject<<endl;
|
2016-08-29 19:39:19 +02:00
|
|
|
|
// ==> ATTRIB1, ATTRIB3, (ATTRIB3), CHILD_B, CHILD_B, CHILD_T
|
|
|
|
|
|
CHECK (subject.verifyAlpha(1));
|
|
|
|
|
|
CHECK (subject.verifyGamma(ATTRIB3.data.get<double>()));
|
|
|
|
|
|
CHECK (subject.verifyData("b, b, 78:56:34.012"));
|
|
|
|
|
|
// unchanged...
|
|
|
|
|
|
CHECK (subject.verifyBeta(-1));
|
|
|
|
|
|
CHECK (not subject.nestedDelta());
|
|
|
|
|
|
CHECK (not subject.nestedObj_1());
|
|
|
|
|
|
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
2016-02-19 21:33:22 +01:00
|
|
|
|
// Part II : apply child population
|
2016-06-09 02:15:50 +02:00
|
|
|
|
application.consume(reorderingDiff());
|
|
|
|
|
|
//
|
|
|
|
|
|
cout << "after...II"<<endl << subject<<endl;
|
2016-08-29 19:39:19 +02:00
|
|
|
|
// ==> ATTRIB1, ATTRIB3, (ATTRIB3), ATTRIB2, SUB_NODE, CHILD_T, CHILD_B
|
|
|
|
|
|
CHECK (subject.verifyAlpha(1));
|
|
|
|
|
|
CHECK (subject.verifyBeta (2)); // attribute β has been set
|
|
|
|
|
|
CHECK (subject.verifyGamma(3.45));
|
|
|
|
|
|
CHECK (subject.verifyData("78:56:34.012, b")); // one child deleted, the other ones re-ordered
|
|
|
|
|
|
CHECK (subject.nestedObj_1()); // plus inserted a nested child object
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyType(Rec::TYPE_NIL));
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyBeta(-1)); // ...which is empty (default constructed)
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyData(""));
|
|
|
|
|
|
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
2016-08-26 02:42:19 +02:00
|
|
|
|
// Part III : apply child mutations
|
2016-02-19 20:25:30 +01:00
|
|
|
|
application.consume(mutationDiff());
|
2016-06-09 02:15:50 +02:00
|
|
|
|
//
|
|
|
|
|
|
cout << "after...III"<<endl << subject<<endl;
|
2016-08-29 19:39:19 +02:00
|
|
|
|
// ==> ATTRIB1, ATTRIB3 := π, (ATTRIB3), ATTRIB2,
|
|
|
|
|
|
// ATTRIB_NODE{ type ζ, CHILD_A, CHILD_A, CHILD_A }
|
|
|
|
|
|
// SUB_NODE{ type ξ, ATTRIB2, CHILD_B, CHILD_A },
|
|
|
|
|
|
// CHILD_T, CHILD_B
|
|
|
|
|
|
CHECK (subject.verifyAlpha(1));
|
|
|
|
|
|
CHECK (subject.verifyBeta (2));
|
|
|
|
|
|
CHECK (subject.verifyGamma(GAMMA_PI.data.get<double>())); // new value assigned to attribute γ
|
|
|
|
|
|
CHECK (subject.nestedDelta()); // attribute δ (object valued) is now present
|
|
|
|
|
|
CHECK (subject.nestedDelta()->verifyType("ζ")); // ...and has an explicitly defined type field
|
|
|
|
|
|
CHECK (subject.nestedDelta()->verifyData("a, a, a"));//...plus three similar child values
|
|
|
|
|
|
CHECK (subject.verifyData("78:56:34.012, b")); // the child values weren't altered
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyType("ξ")); // but the nested child object's type has been set
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyBeta(2)); // ...and the attribute β has been set on the nested object
|
|
|
|
|
|
CHECK (subject.nestedObj_1()->verifyData("b, a")); // ...plus some child values where added here
|
2016-02-19 20:25:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2016-08-29 17:52:35 +02:00
|
|
|
|
LAUNCHER (DiffComplexApplication_test, "unit common");
|
2016-02-19 20:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::diff::test
|