2015-10-23 19:24:34 +02:00
|
|
|
|
/*
|
|
|
|
|
|
GenericRecordUpdate(Test) - manipulate and reshape the generic record contents
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2015-10-23 20:11:43 +02:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2015-10-23 19:24:34 +02:00
|
|
|
|
#include "lib/diff/record-content-mutator.hpp"
|
2015-10-24 01:49:07 +02:00
|
|
|
|
#include "lib/format-util.hpp"
|
2015-10-23 20:11:43 +02:00
|
|
|
|
#include "lib/diff/record.hpp"
|
|
|
|
|
|
#include "lib/itertools.hpp"
|
2015-10-23 19:24:34 +02:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
2015-10-23 20:11:43 +02:00
|
|
|
|
#include <algorithm>
|
2015-10-23 19:24:34 +02:00
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
2015-10-23 20:11:43 +02:00
|
|
|
|
using lib::append_all;
|
2015-10-23 19:24:34 +02:00
|
|
|
|
using util::isnil;
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
2015-10-23 20:11:43 +02:00
|
|
|
|
using lumiera::error::LUMIERA_ERROR_ITER_EXHAUST;
|
|
|
|
|
|
|
2015-10-23 19:24:34 +02:00
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace diff{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
namespace {//Test fixture....
|
|
|
|
|
|
|
2015-10-23 20:11:43 +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());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-23 19:24:34 +02:00
|
|
|
|
}//(End)Test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************//**
|
|
|
|
|
|
* @test cover technical details of rearranging the contents of lib::diff::Record.
|
|
|
|
|
|
* The implementation of our generic record (abstract object representation)
|
|
|
|
|
|
* uses two lists to hold the data of the attribute and content scopes.
|
|
|
|
|
|
* When receiving a diff message, we have to rearrange and alter the contents,
|
|
|
|
|
|
* which are by default immutable. Thus, for this specific task, embedded
|
|
|
|
|
|
* data is moved into this adapter, which exposes the mutating operation
|
|
|
|
|
|
* required to apply such a diff message.
|
2015-10-24 01:49:07 +02:00
|
|
|
|
*
|
2015-10-23 19:24:34 +02:00
|
|
|
|
* @see generic-record-representation-test.cpp
|
|
|
|
|
|
* @see tree-diff-application-test.cpp
|
|
|
|
|
|
*/
|
|
|
|
|
|
class GenericRecordUpdate_test
|
|
|
|
|
|
: public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2015-10-23 20:11:43 +02:00
|
|
|
|
RecS subject({"b = β", "a = α", "γ", "ε"});
|
|
|
|
|
|
RecS::Mutator mut(subject);
|
|
|
|
|
|
mut.appendChild("δ");
|
|
|
|
|
|
mut.setType("🌰");
|
|
|
|
|
|
|
2015-10-24 01:49:07 +02:00
|
|
|
|
RecS::ContentMutator content; // empty
|
2015-10-23 20:11:43 +02:00
|
|
|
|
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK (!isnil (mut));
|
|
|
|
|
|
CHECK ( isnil (content));
|
2015-10-24 01:49:07 +02:00
|
|
|
|
mut.swapContent(content); // contents of mutator now moved over
|
2015-10-23 20:11:43 +02:00
|
|
|
|
CHECK (!isnil (content));
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK ( isnil (mut));
|
|
|
|
|
|
|
2015-10-23 20:11:43 +02:00
|
|
|
|
CHECK (content.pos == content.attribs.begin());
|
|
|
|
|
|
CHECK (content.currIsAttrib());
|
|
|
|
|
|
CHECK (!content.currIsChild());
|
|
|
|
|
|
CHECK ("b = β" == *content.pos);
|
|
|
|
|
|
|
2015-10-23 20:55:02 +02:00
|
|
|
|
void* rawElm = &content.attribs[0];
|
2015-10-23 20:11:43 +02:00
|
|
|
|
swap (content.attribs[0], content.attribs[1]);
|
|
|
|
|
|
CHECK ("a = α" == *content.pos);
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK (rawElm == & *content.pos);
|
2015-10-23 20:11:43 +02:00
|
|
|
|
|
|
|
|
|
|
++content;
|
|
|
|
|
|
CHECK ("b = β" == *content.pos);
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK (rawElm != &*content.pos);
|
2015-10-23 20:11:43 +02:00
|
|
|
|
CHECK (content.currIsAttrib());
|
|
|
|
|
|
CHECK (!content.currIsChild());
|
|
|
|
|
|
|
|
|
|
|
|
std::sort (content.children.begin(), content.children.end());
|
|
|
|
|
|
|
2015-10-24 01:49:07 +02:00
|
|
|
|
++content; // now leaving attributes and entering child scope...
|
2015-10-23 20:11:43 +02:00
|
|
|
|
CHECK (!content.currIsAttrib());
|
|
|
|
|
|
CHECK (content.currIsChild());
|
|
|
|
|
|
CHECK ("γ" == *content.pos);
|
|
|
|
|
|
|
|
|
|
|
|
++content;
|
|
|
|
|
|
CHECK ("δ" == *content.pos);
|
|
|
|
|
|
++content;
|
|
|
|
|
|
CHECK ("ε" == *content.pos);
|
|
|
|
|
|
|
|
|
|
|
|
++content;
|
|
|
|
|
|
CHECK (content.pos == content.end());
|
|
|
|
|
|
CHECK (!content.currIsAttrib());
|
|
|
|
|
|
CHECK (!content.currIsChild());
|
|
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR (ITER_EXHAUST, ++content);
|
|
|
|
|
|
|
|
|
|
|
|
content.resetPos();
|
2015-10-24 01:49:07 +02:00
|
|
|
|
CHECK (content.currIsAttrib());
|
|
|
|
|
|
CHECK (!content.currIsChild());
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK (rawElm == & *content.pos);
|
2015-10-23 20:11:43 +02:00
|
|
|
|
++content;
|
|
|
|
|
|
CHECK ("b = β" == *content.pos);
|
2015-10-24 03:15:35 +02:00
|
|
|
|
content.jumpToChildScope();
|
|
|
|
|
|
CHECK ("γ" == *content.pos);
|
|
|
|
|
|
CHECK (!content.currIsAttrib());
|
|
|
|
|
|
CHECK (content.currIsChild());
|
2015-10-23 20:11:43 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK ( isnil (mut));
|
|
|
|
|
|
CHECK (!isnil (content));
|
2015-10-23 20:55:02 +02:00
|
|
|
|
mut.swapContent(content);
|
2015-10-23 20:11:43 +02:00
|
|
|
|
CHECK ( isnil (content));
|
|
|
|
|
|
CHECK (!isnil (mut));
|
|
|
|
|
|
|
2016-03-03 22:58:33 +01:00
|
|
|
|
mut.swap (subject);
|
2015-10-23 20:55:02 +02:00
|
|
|
|
CHECK (Seq({"a = α", "b = β", "γ", "δ", "ε"}) == contents(subject));
|
2015-10-24 01:49:07 +02:00
|
|
|
|
CHECK ("Rec(🌰| a = α, b = β |{γ, δ, ε})" == string(subject));
|
2015-10-23 19:24:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (GenericRecordUpdate_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::diff::test
|