implement RecordContentMutator - unit test pass

This commit is contained in:
Fischlurch 2015-10-24 01:49:07 +02:00
parent aa46940daa
commit 2b619d6622
4 changed files with 31 additions and 20 deletions

View file

@ -51,6 +51,7 @@
namespace lib {
namespace diff{
namespace error = lumiera::error;
using std::move;
using std::swap;
@ -77,19 +78,21 @@ namespace diff{
empty() const
{
return attribs.empty()
&& children.empty();
and children.empty();
}
bool
currIsAttrib() const
{
UNIMPLEMENTED ("determine current scope");
return & *pos >= & *attribs.begin()
and & *pos < & *attribs.end();
}
bool
currIsChild() const
{
UNIMPLEMENTED ("determine current scope");
return & *pos >= & *children.begin()
and & *pos < & *children.end();
}
Iter end() { return children.end(); }
@ -98,7 +101,16 @@ namespace diff{
RecordContentMutator&
operator++()
{
UNIMPLEMENTED ("iteration");
if (pos == children.end())
throw error::State ("attempt to iterate beyond end of scope"
,error::LUMIERA_ERROR_ITER_EXHAUST);
if (pos == attribs.end())
pos = children.begin();
else
++pos;
if (pos == attribs.end())
pos = children.begin();
return *this;
}
void

View file

@ -463,6 +463,7 @@ namespace diff{
record_.children_.size());
std::swap (record_.attribs_, alteredContent.attribs);
std::swap (record_.children_, alteredContent.children);
alteredContent.resetPos();
}
/* === extension point for building specific value types === */

View file

@ -243,7 +243,12 @@ return: 0
END
TEST "GenNodeBasic_test" GenNodeBasic_test <<END
TEST "Generic Record - Mutations" GenericRecordUpdate_test <<END
return: 0
END
TEST "Generic Record data node" GenNodeBasic_test <<END
out-lit: GenNode-ID("_CHILD_Record.001")-DataCap|«lib::diff::Record<lib::diff::GenNode>»|Rec(spam| ham = DataCap|«std::string»|eggs |{})
out-lit: --spam--
out-lit: GenNode-ID("baked beans")-DataCap|«lib::diff::Record<lib::diff::GenNode>»|Rec(hasSpam = DataCap|«bool»|1 |{GenNode-ID("_CHILD_char.002")-DataCap|«char»|*, GenNode-ID("_CHILD_string.006")-DataCap|«std::string»|★, GenNode-ID("_CHILD_double.001")-DataCap|«double»|3.1415926535897931, GenNode-ID("spam")-DataCap|«lib::diff::Record<lib::diff::GenNode>»|Rec(ham| |{GenNode-ID("_CHILD_string.003")-DataCap|«std::string»|eggs, GenNode-ID("_CHILD_string.004")-DataCap|«std::string»|spam, GenNode-ID("_CHILD_string.005")-DataCap|«std::string»|spam}), GenNode-ID("_CHILD_TimeSpan.002")-DataCap|«lib::time::TimeSpan»|0:00:00.000[920ms], GenNode-ID("_CHILD_long.001")-DataCap|«long»|42})

View file

@ -24,9 +24,7 @@
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/diff/record-content-mutator.hpp"
//#include "lib/iter-adapter-stl.hpp"
//#include "lib/time/timevalue.hpp"
//#include "lib/format-util.hpp"
#include "lib/format-util.hpp"
#include "lib/diff/record.hpp"
#include "lib/itertools.hpp"
#include "lib/util.hpp"
@ -34,15 +32,10 @@
#include <algorithm>
#include <string>
#include <vector>
#include <iostream> ///TODO
//using lib::iter_stl::snapshot;
using lib::append_all;
using util::isnil;
//using util::join;
//using std::string;
using std::vector;
//using lib::time::Time;
using lumiera::error::LUMIERA_ERROR_ITER_EXHAUST;
@ -71,7 +64,6 @@ namespace test{
return contents (rec_of_strings.begin());
}
}//(End)Test fixture
@ -90,7 +82,7 @@ namespace test{
* 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.
*
*
* @see generic-record-representation-test.cpp
* @see tree-diff-application-test.cpp
*/
@ -105,13 +97,12 @@ namespace test{
RecS::Mutator mut(subject);
mut.appendChild("δ");
mut.setType("🌰");
std::cout << string(subject) << std::endl;
RecS::ContentMutator content;
RecS::ContentMutator content; // empty
CHECK (!isnil (mut));
CHECK ( isnil (content));
mut.swapContent(content);
mut.swapContent(content); // contents of mutator now moved over
CHECK (!isnil (content));
CHECK ( isnil (mut));
@ -133,7 +124,7 @@ namespace test{
std::sort (content.children.begin(), content.children.end());
++content;
++content; // now leaving attributes and entering child scope...
CHECK (!content.currIsAttrib());
CHECK (content.currIsChild());
CHECK ("γ" == *content.pos);
@ -151,6 +142,8 @@ namespace test{
VERIFY_ERROR (ITER_EXHAUST, ++content);
content.resetPos();
CHECK (content.currIsAttrib());
CHECK (!content.currIsChild());
CHECK (rawElm == & *content.pos);
++content;
CHECK ("b = β" == *content.pos);
@ -163,7 +156,7 @@ namespace test{
mut.replace(subject);
CHECK (Seq({"a = α", "b = β", "γ", "δ", "ε"}) == contents(subject));
std::cout << string(subject) << std::endl;
CHECK ("Rec(🌰| a = α, b = β |{γ, δ, ε})" == string(subject));
}
};