2015-03-21 02:00:55 +01:00
|
|
|
|
/*
|
|
|
|
|
|
GenericRecordRepresentation(Test) - introspective representation of object-like data
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2015, 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.
|
|
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file generic-record-representation-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref GenericRecordRepresentation_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2015-07-05 03:17:39 +02:00
|
|
|
|
#include "lib/format-util.hpp"
|
2015-03-21 02:00:55 +01:00
|
|
|
|
#include "lib/diff/record.hpp"
|
2015-06-05 19:17:39 +02:00
|
|
|
|
#include "lib/itertools.hpp"
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
2015-06-05 19:17:39 +02:00
|
|
|
|
#include <string>
|
2015-06-04 19:26:45 +02:00
|
|
|
|
#include <vector>
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
2015-06-05 19:17:39 +02:00
|
|
|
|
using std::string;
|
2015-06-04 19:26:45 +02:00
|
|
|
|
using util::isSameObject;
|
2015-06-05 19:17:39 +02:00
|
|
|
|
using util::isnil;
|
2015-08-17 03:59:53 +02:00
|
|
|
|
using util::join;
|
2015-06-04 19:26:45 +02:00
|
|
|
|
using std::vector;
|
2015-08-17 22:13:36 +02:00
|
|
|
|
using std::swap;
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace diff{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
2018-04-02 01:48:51 +02:00
|
|
|
|
using lumiera::error::LERR_(INVALID);
|
|
|
|
|
|
using lumiera::error::LERR_(INDEX_BOUNDS);
|
|
|
|
|
|
using lumiera::error::LERR_(BOTTOM_VALUE);
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
namespace {//Test fixture....
|
|
|
|
|
|
|
2015-06-05 19:17:39 +02:00
|
|
|
|
using Seq = vector<string>;
|
|
|
|
|
|
using RecS = Record<string>;
|
|
|
|
|
|
|
|
|
|
|
|
template<class IT>
|
|
|
|
|
|
inline Seq
|
|
|
|
|
|
contents (IT const& it)
|
|
|
|
|
|
{
|
|
|
|
|
|
Seq collected;
|
|
|
|
|
|
append_all (it, collected);
|
|
|
|
|
|
return collected;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Seq
|
|
|
|
|
|
contents (RecS const& rec_of_strings)
|
|
|
|
|
|
{
|
|
|
|
|
|
return contents (rec_of_strings.begin());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class X>
|
|
|
|
|
|
inline Seq
|
|
|
|
|
|
strings (std::initializer_list<X> const& con)
|
|
|
|
|
|
{
|
|
|
|
|
|
Seq collected;
|
|
|
|
|
|
for (auto elm : con)
|
|
|
|
|
|
collected.push_back(elm);
|
|
|
|
|
|
return collected;
|
|
|
|
|
|
}
|
2015-03-21 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//(End)Test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-04 19:26:45 +02:00
|
|
|
|
/*************************************************************************************//**
|
2015-03-21 02:00:55 +01:00
|
|
|
|
* @test Verify properties of a special collection type meant for external representation
|
2015-08-17 22:13:36 +02:00
|
|
|
|
* of object-like data, especially for symbolic representation in diff messages.
|
|
|
|
|
|
* - there is a type meta attribute
|
|
|
|
|
|
* - a Record can have attributes (by key) and contents (ordered list of values)
|
|
|
|
|
|
* - various kinds of iterators are provided
|
|
|
|
|
|
* - besides the regular constructor, which explicitly takes a type, a collection
|
|
|
|
|
|
* of attributes, and a collection of contents, there is a convenience constructor
|
|
|
|
|
|
* especially for literal notation and data definition. This one figures out the
|
|
|
|
|
|
* break between attributes and contents automatically; a type meta attribute
|
|
|
|
|
|
* is recognised and the first element without a given key or ID ends the
|
|
|
|
|
|
* attributes and starts the content scope
|
|
|
|
|
|
* - Record elements are conceived as values and equality is defined in terms
|
|
|
|
|
|
* of their contents, including the order (no normalisation, no sorting)
|
|
|
|
|
|
* - they are \em immutable after construction. But we provide a Mutator
|
|
|
|
|
|
* for remoulding a given element, enabling object builder notation.
|
|
|
|
|
|
* - a reference wrapper for handling of large structures is provided.
|
|
|
|
|
|
* @remarks this test uses the specialisation \c Record<string> solely, to cover the
|
|
|
|
|
|
* basic properties and behaviour, while leaving out the complexities of specific
|
|
|
|
|
|
* payload data types. For the actual use case, the symbolic description of
|
|
|
|
|
|
* data structure differences, we use a specific "value" within Record,
|
|
|
|
|
|
* the diff::GenNode, which is a limited typesafe Variant element, and in
|
|
|
|
|
|
* turn allows Record<GenNode> as embedded payload. Effectively this creates
|
|
|
|
|
|
* a "recursive data type", which is key to typesafe functional processing of
|
|
|
|
|
|
* unlimited data structures. The design of diff::Record only makes sense with
|
|
|
|
|
|
* this use case in mind; most notably, we have the keys (attribute names)
|
|
|
|
|
|
* embedded within the value payload, which turns attributes into just another
|
|
|
|
|
|
* content scope with special access operations. This also explains, why we
|
|
|
|
|
|
* do not normalise the content in any way; content is meant to reflect
|
|
|
|
|
|
* other data structures, which are normalised and maintained by their owner.
|
2015-03-21 02:00:55 +01:00
|
|
|
|
*
|
2015-08-17 22:13:36 +02:00
|
|
|
|
* @see GenNodeBasic_test
|
|
|
|
|
|
* @see tree-diff.cpp
|
2015-03-21 02:00:55 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class GenericRecordRepresentation_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
simpleUsage();
|
2015-06-04 19:26:45 +02:00
|
|
|
|
verifyCreation();
|
|
|
|
|
|
verifyMutations();
|
2015-03-21 02:00:55 +01:00
|
|
|
|
copy_and_move();
|
2015-06-04 19:26:45 +02:00
|
|
|
|
equality();
|
2015-06-14 02:52:11 +02:00
|
|
|
|
wrapRef();
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
simpleUsage()
|
|
|
|
|
|
{
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS enterprise("starship"
|
2015-06-05 19:17:39 +02:00
|
|
|
|
, strings ({"Name = USS Enterprise"
|
|
|
|
|
|
,"Registry = NCC-1701-D"
|
|
|
|
|
|
,"Class = Galaxy"
|
|
|
|
|
|
,"Owner = United Federation of Planets"
|
2015-08-17 03:59:53 +02:00
|
|
|
|
,"Operator= Starfleet"
|
2015-06-05 19:17:39 +02:00
|
|
|
|
,"built=2363"
|
|
|
|
|
|
})
|
|
|
|
|
|
, strings ({"Picard", "Riker", "Data", "Troi", "Worf", "Crusher", "La Forge"})
|
2015-06-04 19:26:45 +02:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (enterprise.getType() == "starship");
|
|
|
|
|
|
CHECK (enterprise.get("Registry") == "NCC-1701-D");
|
2016-01-23 17:10:44 +01:00
|
|
|
|
CHECK (enterprise.child(0) == "Picard");
|
|
|
|
|
|
CHECK (enterprise.child(2) == "Data");
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (enterprise.hasAttribute("Owner"));
|
|
|
|
|
|
CHECK (!enterprise.hasAttribute("owner"));
|
2015-08-17 22:13:36 +02:00
|
|
|
|
CHECK (!enterprise.hasAttribute("Owner ")); // no normalisation
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (enterprise.contains("Data"));
|
2015-08-17 22:13:36 +02:00
|
|
|
|
CHECK (!enterprise.contains("Woof")); // it is /Worf/, madam
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (util::contains (enterprise, "Worf"));
|
|
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR (INVALID, enterprise.get("warp10"));
|
2016-01-28 15:19:09 +01:00
|
|
|
|
VERIFY_ERROR (INDEX_BOUNDS, enterprise.child(12));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
2015-08-17 06:17:00 +02:00
|
|
|
|
cout << "enterprise = "
|
2016-01-07 03:58:29 +01:00
|
|
|
|
<< enterprise <<endl;
|
2015-08-17 06:17:00 +02:00
|
|
|
|
for (string elm : enterprise)
|
2016-01-07 03:58:29 +01:00
|
|
|
|
cout << elm <<endl;
|
2015-08-17 03:59:53 +02:00
|
|
|
|
cout << "--Attributes--"<<endl;
|
2015-08-17 06:17:00 +02:00
|
|
|
|
for (string att : enterprise.attribs())
|
2016-01-07 03:58:29 +01:00
|
|
|
|
cout << att <<endl;
|
2015-08-17 03:59:53 +02:00
|
|
|
|
cout << "--Keys--->" << join (enterprise.keys(), "<->")<<endl;
|
|
|
|
|
|
cout << "--Vals--->" << join (enterprise.vals(), "<->")<<endl;
|
|
|
|
|
|
cout << "--Crew--->" << join (enterprise.scope()," | ")<<endl;
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-04 19:26:45 +02:00
|
|
|
|
verifyCreation()
|
2015-03-21 02:00:55 +01:00
|
|
|
|
{
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS nil;
|
|
|
|
|
|
CHECK (isnil(nil));
|
|
|
|
|
|
CHECK ("NIL" == nil.getType());
|
2015-08-17 06:17:00 +02:00
|
|
|
|
CHECK (RecS::TYPE_NIL == nil.getType());
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (!nil.begin());
|
|
|
|
|
|
CHECK (nil.begin() == nil.end());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RecS untyped({"x"});
|
|
|
|
|
|
CHECK (!isnil(untyped));
|
|
|
|
|
|
CHECK ("NIL" == untyped.getType());
|
|
|
|
|
|
CHECK (Seq{"x"} == contents(untyped));
|
|
|
|
|
|
CHECK (Seq{"x"} == contents(untyped.scope()));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (isnil (untyped.attribs()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
RecS untyped2({"x=y", "z"});
|
|
|
|
|
|
CHECK (!isnil(untyped2));
|
|
|
|
|
|
CHECK ("NIL" == untyped2.getType());
|
|
|
|
|
|
CHECK (Seq({"x=y", "z"}) == contents(untyped2));
|
|
|
|
|
|
CHECK (Seq{"x"} == contents (untyped2.keys()));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (Seq{"y"} == contents (untyped2.vals()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (Seq{"z"} == contents (untyped2.scope()));
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-17 06:17:00 +02:00
|
|
|
|
RecS something({"a=1", "type=thing", "b=2", "c", "d"});
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (!isnil(something));
|
|
|
|
|
|
CHECK ("thing" == something.getType());
|
2015-08-17 06:17:00 +02:00
|
|
|
|
CHECK (Seq({"a=1", "b=2", "c", "d"}) == contents(something));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (Seq({"a", "b"}) == contents (something.keys()));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (Seq({"1", "2"}) == contents (something.vals()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (Seq({"c", "d"}) == contents (something.scope()));
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-04 19:26:45 +02:00
|
|
|
|
copy_and_move()
|
2015-03-21 02:00:55 +01:00
|
|
|
|
{
|
2015-08-17 06:17:00 +02:00
|
|
|
|
RecS a({"a=1", "b=2", "c", "d"});
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS b(a);
|
|
|
|
|
|
CHECK (a.getType() == b.getType());
|
|
|
|
|
|
CHECK (contents(a) == contents(b));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (contents(a.attribs()) == contents(b.attribs()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (!isSameObject (a.get("a"), b.get("a")));
|
|
|
|
|
|
CHECK (!isSameObject (*a.scope(), *b.scope()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
2015-06-06 00:11:12 +02:00
|
|
|
|
string const& c = *b.scope();
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK ("c" == c);
|
|
|
|
|
|
|
|
|
|
|
|
RecS bb;
|
|
|
|
|
|
CHECK (isnil(bb));
|
|
|
|
|
|
bb = move(b);
|
Generic Record: finish implementation of Mutator
especially setting (changing) attributes turned out to be tricky,
since in case of a GenNode this would mean to re-bind the hash ID;
we can not possibly do that properly without knowing the type of the payload,
and by design this payload type is opaque (erased).
As resort, I changed the semantics of the assign operation:
now it rather builds a new payload element, with a given initialiser.
In case of the strings, this ends up being the same operation,
while in case of GenNode, this is now something entirely different:
we can now build a new GenNode "in place" of the old one, and both
will have the same symbolic ID (attribute key). Incidentally,
our Variant implementation will reject such a re-building operatinon
when this means to change the (opaque) payload type.
in addition, I created a new API function on the Mutator,
allowing to move-in a complete attribute object. Actually this
new function became the working implementation. This way, it is
still possible to emplace a new attribute efficiently (consider
this to be a whole object graph!). But only, if the key (ID)
embedded in the attribute object is already what is the intended
key for this attribute. This way, we elegantly circumvent the
problem of having to re-bind a hash ID without knowing the type seed
2015-08-17 20:31:07 +02:00
|
|
|
|
CHECK ("2" == bb.get("b"));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (isSameObject(c, *bb.scope()));
|
|
|
|
|
|
|
|
|
|
|
|
swap (a, bb);
|
|
|
|
|
|
CHECK (!isSameObject(c, *bb.scope()));
|
|
|
|
|
|
CHECK ( isSameObject(c, *a.scope()));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (isnil (b));
|
|
|
|
|
|
b = bb;
|
|
|
|
|
|
CHECK (!isnil (b));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (!isSameObject(b.get("a"), bb.get("a")));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (!isSameObject(*b.scope(), *bb.scope()));
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-04 19:26:45 +02:00
|
|
|
|
equality()
|
2015-03-21 02:00:55 +01:00
|
|
|
|
{
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS a({"a"});
|
|
|
|
|
|
RecS aa({"a","aa"});
|
|
|
|
|
|
RecS aaa({"a","a"});
|
|
|
|
|
|
RecS ax({"type=a","a"});
|
|
|
|
|
|
RecS ay({"a=a","a"});
|
2015-08-17 22:13:36 +02:00
|
|
|
|
RecS az({"a =a","a"});
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (a != aa); CHECK (aa != a);
|
|
|
|
|
|
CHECK (aa != aaa); CHECK (aaa != aa);
|
|
|
|
|
|
CHECK (a != aaa); CHECK (aaa != a);
|
|
|
|
|
|
CHECK (a != ax); CHECK (ax != a);
|
|
|
|
|
|
CHECK (a != ay); CHECK (ay != a);
|
|
|
|
|
|
CHECK (ax != ay); CHECK (ay != ax);
|
|
|
|
|
|
CHECK (aaa != ay); CHECK (ay != aaa);
|
2015-08-17 22:13:36 +02:00
|
|
|
|
CHECK (ay != az); CHECK (az != ay); // NOTE: attributes are *not* normalised,
|
|
|
|
|
|
// rather, they are used as-is,
|
|
|
|
|
|
// thus "a=a" != "a =a"
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS a2({"a","aa"});
|
|
|
|
|
|
CHECK (aa == a2); CHECK (a2 == aa);
|
|
|
|
|
|
|
2015-06-05 19:17:39 +02:00
|
|
|
|
RecS o1("oo", strings({"a=α", "b=β"}), strings({"γ", "δ", "ε"}));
|
Generic Record: finish implementation of Mutator
especially setting (changing) attributes turned out to be tricky,
since in case of a GenNode this would mean to re-bind the hash ID;
we can not possibly do that properly without knowing the type of the payload,
and by design this payload type is opaque (erased).
As resort, I changed the semantics of the assign operation:
now it rather builds a new payload element, with a given initialiser.
In case of the strings, this ends up being the same operation,
while in case of GenNode, this is now something entirely different:
we can now build a new GenNode "in place" of the old one, and both
will have the same symbolic ID (attribute key). Incidentally,
our Variant implementation will reject such a re-building operatinon
when this means to change the (opaque) payload type.
in addition, I created a new API function on the Mutator,
allowing to move-in a complete attribute object. Actually this
new function became the working implementation. This way, it is
still possible to emplace a new attribute efficiently (consider
this to be a whole object graph!). But only, if the key (ID)
embedded in the attribute object is already what is the intended
key for this attribute. This way, we elegantly circumvent the
problem of having to re-bind a hash ID without knowing the type seed
2015-08-17 20:31:07 +02:00
|
|
|
|
RecS o2({"type=oo", "a=α", "b=β", "γ", "δ", "ε"});
|
|
|
|
|
|
RecS o3({"type=oO", "a=α", "b=β", "γ", "δ", "ε"});
|
|
|
|
|
|
RecS o4({"type=oo", "a=α", "b=β", "c=γ", "δ", "ε"});
|
|
|
|
|
|
RecS o5({"type=oo", "a=α", "b=β", "γ", "ε", "δ"});
|
|
|
|
|
|
RecS o6({"type=oo", "a=α", "b=β", "γ", "δ"});
|
2015-06-04 19:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (o1 == o2); CHECK (o2 == o1);
|
|
|
|
|
|
CHECK (o2 != o3); CHECK (o3 != o2);
|
|
|
|
|
|
CHECK (o3 != o4); CHECK (o4 != o3);
|
|
|
|
|
|
CHECK (o4 != o5); CHECK (o5 != o4);
|
|
|
|
|
|
CHECK (o5 != o6); CHECK (o6 != o5);
|
|
|
|
|
|
CHECK (o1 != o3); CHECK (o3 != o1);
|
|
|
|
|
|
CHECK (o1 != o4); CHECK (o4 != o1);
|
|
|
|
|
|
CHECK (o1 != o5); CHECK (o5 != o1);
|
|
|
|
|
|
CHECK (o1 != o6); CHECK (o6 != o1);
|
|
|
|
|
|
CHECK (o2 != o4); CHECK (o4 != o2);
|
|
|
|
|
|
CHECK (o2 != o5); CHECK (o5 != o2);
|
|
|
|
|
|
CHECK (o2 != o6); CHECK (o6 != o2);
|
|
|
|
|
|
CHECK (o3 != o5); CHECK (o5 != o3);
|
|
|
|
|
|
CHECK (o3 != o6); CHECK (o6 != o3);
|
|
|
|
|
|
CHECK (o4 != o6); CHECK (o6 != o4);
|
|
|
|
|
|
|
|
|
|
|
|
RecS o7({"type=oo", "b = β", "a = α", "γ", "δ", "ε"});
|
|
|
|
|
|
CHECK (o2 != o7); CHECK (o7 != o2);
|
|
|
|
|
|
// ideally, they would be equal, but this would require
|
|
|
|
|
|
// a way more expensive implementation
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-04 19:26:45 +02:00
|
|
|
|
verifyMutations()
|
2015-03-21 02:00:55 +01:00
|
|
|
|
{
|
2015-06-04 19:26:45 +02:00
|
|
|
|
RecS a;
|
|
|
|
|
|
CHECK (isnil (a));
|
|
|
|
|
|
CHECK ("NIL" == a.getType());
|
|
|
|
|
|
|
|
|
|
|
|
RecS::Mutator mut(a);
|
|
|
|
|
|
mut.setType("u");
|
|
|
|
|
|
mut.appendChild("a");
|
|
|
|
|
|
mut.set("a", "1");
|
|
|
|
|
|
|
2015-06-14 22:34:22 +02:00
|
|
|
|
RecS aa(mut);
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (a != aa);
|
|
|
|
|
|
CHECK ("u" == aa.getType());
|
Generic Record: finish implementation of Mutator
especially setting (changing) attributes turned out to be tricky,
since in case of a GenNode this would mean to re-bind the hash ID;
we can not possibly do that properly without knowing the type of the payload,
and by design this payload type is opaque (erased).
As resort, I changed the semantics of the assign operation:
now it rather builds a new payload element, with a given initialiser.
In case of the strings, this ends up being the same operation,
while in case of GenNode, this is now something entirely different:
we can now build a new GenNode "in place" of the old one, and both
will have the same symbolic ID (attribute key). Incidentally,
our Variant implementation will reject such a re-building operatinon
when this means to change the (opaque) payload type.
in addition, I created a new API function on the Mutator,
allowing to move-in a complete attribute object. Actually this
new function became the working implementation. This way, it is
still possible to emplace a new attribute efficiently (consider
this to be a whole object graph!). But only, if the key (ID)
embedded in the attribute object is already what is the intended
key for this attribute. This way, we elegantly circumvent the
problem of having to re-bind a hash ID without knowing the type seed
2015-08-17 20:31:07 +02:00
|
|
|
|
CHECK (Seq({"a = 1", "a"}) == contents(aa));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (Seq({"a"}) == contents (aa.keys()));
|
2015-06-05 19:17:39 +02:00
|
|
|
|
CHECK (Seq({"1"}) == contents (aa.vals()));
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (Seq({"a"}) == contents (aa.scope()));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mut == aa);
|
|
|
|
|
|
|
|
|
|
|
|
mut.prependChild("⟂");
|
|
|
|
|
|
mut.set("b", "β");
|
|
|
|
|
|
mut.set("a", "α");
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mut != aa);
|
|
|
|
|
|
|
2016-03-03 22:58:33 +01:00
|
|
|
|
mut.swap (a);
|
2015-06-04 19:26:45 +02:00
|
|
|
|
CHECK (isnil (mut));
|
Generic Record: finish implementation of Mutator
especially setting (changing) attributes turned out to be tricky,
since in case of a GenNode this would mean to re-bind the hash ID;
we can not possibly do that properly without knowing the type of the payload,
and by design this payload type is opaque (erased).
As resort, I changed the semantics of the assign operation:
now it rather builds a new payload element, with a given initialiser.
In case of the strings, this ends up being the same operation,
while in case of GenNode, this is now something entirely different:
we can now build a new GenNode "in place" of the old one, and both
will have the same symbolic ID (attribute key). Incidentally,
our Variant implementation will reject such a re-building operatinon
when this means to change the (opaque) payload type.
in addition, I created a new API function on the Mutator,
allowing to move-in a complete attribute object. Actually this
new function became the working implementation. This way, it is
still possible to emplace a new attribute efficiently (consider
this to be a whole object graph!). But only, if the key (ID)
embedded in the attribute object is already what is the intended
key for this attribute. This way, we elegantly circumvent the
problem of having to re-bind a hash ID without knowing the type seed
2015-08-17 20:31:07 +02:00
|
|
|
|
CHECK (Seq({"a = α", "b = β", "⟂", "a"}) == contents(a));
|
|
|
|
|
|
CHECK (Seq({"a = 1", "a"}) == contents(aa));
|
2015-03-21 02:00:55 +01:00
|
|
|
|
}
|
2015-06-14 02:52:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
wrapRef()
|
|
|
|
|
|
{
|
|
|
|
|
|
RecS oo({"type = 🌰", "☿ = mercury", "♀ = venus", "♁ = earth", "♂ = mars", "♃ = jupiter", "♄ = saturn"});
|
|
|
|
|
|
|
|
|
|
|
|
RecordRef<string> empty;
|
|
|
|
|
|
CHECK (bool(empty) == false);
|
|
|
|
|
|
CHECK (nullptr == empty.get());
|
2015-07-03 15:42:25 +02:00
|
|
|
|
VERIFY_ERROR (BOTTOM_VALUE, empty.operator RecS&() );
|
2015-06-14 02:52:11 +02:00
|
|
|
|
|
|
|
|
|
|
RecordRef<string> ref(oo);
|
|
|
|
|
|
CHECK (ref);
|
|
|
|
|
|
CHECK (ref.get() == &oo);
|
|
|
|
|
|
|
|
|
|
|
|
RecS& oor = ref;
|
|
|
|
|
|
CHECK ("🌰" == oor.getType());
|
|
|
|
|
|
CHECK (oor.get("♄") == "saturn");
|
|
|
|
|
|
|
2015-08-17 20:56:40 +02:00
|
|
|
|
// are copyable but not reassignable
|
2015-06-14 02:52:11 +02:00
|
|
|
|
RecordRef<string> r2 = ref;
|
|
|
|
|
|
CHECK (r2);
|
|
|
|
|
|
CHECK (r2.get() == ref.get());
|
|
|
|
|
|
CHECK (!isSameObject (r2, ref));
|
|
|
|
|
|
|
2015-08-17 20:56:40 +02:00
|
|
|
|
// but references are move-assignable
|
2015-06-14 02:52:11 +02:00
|
|
|
|
empty = std::move(r2);
|
|
|
|
|
|
CHECK (empty);
|
|
|
|
|
|
CHECK (!r2);
|
|
|
|
|
|
CHECK (nullptr == r2.get());
|
|
|
|
|
|
}
|
2015-03-21 02:00:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (GenericRecordRepresentation_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::diff::test
|