diff --git a/src/lib/diff/diff-language.hpp b/src/lib/diff/diff-language.hpp index d28993c97..471ab6234 100644 --- a/src/lib/diff/diff-language.hpp +++ b/src/lib/diff/diff-language.hpp @@ -137,8 +137,8 @@ namespace diff{ * of constant size. The actual verbs of the diff language in use are defined * through the operations of the \em Interpreter; each #VerbToken corresponds * to a handler function on the Interpreter interface. In addition to the verb, - * each DiffStep also carries a content data element, like e.g. "insert elm - * at next position". + * each DiffStep also carries a content data element as argument, + * like e.g. "insert elm at next position". * @param I Interpreter interface of the actual language to use * @param E type of the elementary data elements. * @remarks recommendation is to set up a builder function for each distinct diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index b05f7e947..578df677e 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -25,7 +25,7 @@ ** Concrete implementation(s) to apply structural changes to hierarchical ** data structures. Together with the generic #DiffApplicator, this allows ** to receive linearised structural diff descriptions and apply them to - ** a given target data structure, to effect the correspoinding changes. + ** a given target data structure, to effect the corresponding changes. ** ** @see diff-list-application-test.cpp ** @see VerbToken @@ -38,13 +38,21 @@ #include "lib/diff/tree-diff.hpp" +#include "lib/diff/gen-node.hpp" namespace lib { namespace diff{ - template - class DiffApplicationStrategy> - : public ListDiffInterpreter + /** + * concrete strategy to apply a structural diff to a target data structure + * made from #Record elements. + * @throws lumiera::error::State when diff application fails due to the + * target sequence being different than assumed by the given diff. + * @see #TreeDiffInterpreter explanation of the verbs + */ + template<> + class DiffApplicationStrategy + : public TreeDiffInterpreter { }; diff --git a/src/lib/diff/tree-diff.hpp b/src/lib/diff/tree-diff.hpp index dbc86bf11..3482c4da5 100644 --- a/src/lib/diff/tree-diff.hpp +++ b/src/lib/diff/tree-diff.hpp @@ -1,8 +1,8 @@ /* - TREE-DIFF.hpp - language to describe differences in linearised form + TREE-DIFF.hpp - language to describe differences in hierarchical data structures Copyright (C) Lumiera.org - 2014, Hermann Vosseler + 2015, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,7 +21,7 @@ */ -/** @file list-diff.hpp +/** @file tree-diff.hpp ** A token language to represent structural changes in a tree like ** hierarchical data structure. In combination with the #DiffLanguage framework, ** this building block defines the set of operations to express both content @@ -30,9 +30,9 @@ ** @todo UNIMPLEMENTED as of 12/14 ** ** @see diff-language.cpp - ** @see diff-list-application-test.cpp - ** @see list-diff.cpp - ** @see VerbToken + ** @see diff-tree-application-test.cpp + ** @see tree-diff.cpp + ** @see GenNode ** */ diff --git a/tests/library/diff/diff-list-application-test.cpp b/tests/library/diff/diff-list-application-test.cpp index 9f8207a77..f8bf3639c 100644 --- a/tests/library/diff/diff-list-application-test.cpp +++ b/tests/library/diff/diff-list-application-test.cpp @@ -91,7 +91,9 @@ namespace test{ * to a given source list, transforming this list to hold the intended * target list contents. * - * @see session-structure-mapping-test.cpp + * @see DiffListGeneration_test + * @see DiffTreeApplication_test + * @see VerbFunctionDispatch_test */ class DiffListApplication_test : public Test { diff --git a/tests/library/diff/diff-tree-application-test.cpp b/tests/library/diff/diff-tree-application-test.cpp new file mode 100644 index 000000000..36a704371 --- /dev/null +++ b/tests/library/diff/diff-tree-application-test.cpp @@ -0,0 +1,122 @@ +/* + DiffTreeApplication(Test) - demonstrate the basics of tree diff representation + + Copyright (C) Lumiera.org + 2015, Hermann Vosseler + + 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/diff/tree-diff-application.hpp" +#include "lib/iter-adapter-stl.hpp" +#include "lib/util.hpp" + +#include +#include + +using lib::iter_stl::snapshot; +using util::isnil; +using std::string; +using std::vector; + + +namespace lib { +namespace diff{ +namespace test{ + + namespace {//Test fixture.... + + + #define TOK(id) id(STRINGIFY(id)) + + string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5); + string TOK(b1), TOK(b2), TOK(b3), TOK(b4); + + using Interpreter = TreeDiffInterpreter; + using DiffStep = TreeDiffLanguage::DiffStep; + using DiffSeq = iter_stl::IterSnapshot; + + DiffStep_CTOR(ins); + DiffStep_CTOR(del); + DiffStep_CTOR(pick); + DiffStep_CTOR(find); + DiffStep_CTOR(skip); + + + inline DiffSeq + generateTestDiff() + { + return snapshot({del(a1) + , del(a2) + , ins(b1) + , pick(a3) + , find(a5) + , ins(b2) + , ins(b3) + , pick(a4) + , skip(a5) + , ins(b4) + }); + } + }//(End)Test fixture + + + + + + + + + + /***********************************************************************//** + * @test Demonstration/Concept: a description language for list differences. + * The representation is given as a linearised sequence of verb tokens. + * This test demonstrates the application of such a diff representation + * to a given source list, transforming this list to hold the intended + * target list contents. + * + * @see session-structure-mapping-test.cpp + */ + class DiffTreeApplication_test : public Test + { + + virtual void + run (Arg) + { + DataSeq src({a1,a2,a3,a4,a5}); + DiffSeq diff = generateTestDiff(); + CHECK (!isnil (diff)); + + DataSeq target = src; + DiffApplicator application(target); + application.consume(diff); + + CHECK (isnil (diff)); + CHECK (!isnil (target)); + CHECK (src != target); + CHECK (target == DataSeq({b1,a3,a5,b2,b3,a4,b4})); + } + }; + + + /** Register this test class... */ + LAUNCHER (DiffTreeApplication_test, "unit common"); + + + +}}} // namespace lib::diff::test