Lumiera  0.pre.03
»edit your freedom«
diff-list-application-test.cpp
Go to the documentation of this file.
1 /*
2  DiffListApplication(Test) - demonstrate linearised representation of list diffs
3 
4  Copyright (C) Lumiera.org
5  2014, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
30 #include "lib/iter-adapter-stl.hpp"
31 #include "lib/util.hpp"
32 
33 #include <string>
34 #include <vector>
35 
37 using util::isnil;
38 using std::string;
39 using std::vector;
40 
41 
42 namespace lib {
43 namespace diff{
44 namespace test{
45 
46  namespace {//Test fixture....
47 
48  using DataSeq = vector<string>;
49 
50  #define TOK(id) id(STRINGIFY(id))
51 
52  string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5);
53  string TOK(b1), TOK(b2), TOK(b3), TOK(b4);
54 
56  using DiffStep = ListDiffLanguage<string>::DiffStep;
58 
59  DiffStep_CTOR(ins);
60  DiffStep_CTOR(del);
61  DiffStep_CTOR(pick);
62  DiffStep_CTOR(find);
63  DiffStep_CTOR(skip);
64 
65 
66  inline DiffSeq
67  generateTestDiff()
68  {
69  return snapshot({del(a1)
70  , del(a2)
71  , ins(b1)
72  , pick(a3)
73  , find(a5)
74  , ins(b2)
75  , ins(b3)
76  , pick(a4)
77  , skip(a5)
78  , ins(b4)
79  });
80  }
81  }//(End)Test fixture
82 
83 
84 
85 
86 
87 
88 
89 
90 
91  /***********************************************************************/
102  class DiffListApplication_test : public Test
103  {
104 
105  virtual void
106  run (Arg)
107  {
108  DataSeq src({a1,a2,a3,a4,a5});
109  DiffSeq diff = generateTestDiff();
110  CHECK (!isnil (diff));
111 
112  DataSeq target = src;
113  DiffApplicator<DataSeq> application(target);
114  application.consume(diff);
115 
116  CHECK (isnil (diff));
117  CHECK (!isnil (target));
118  CHECK (src != target);
119  CHECK (target == DataSeq({b1,a3,a5,b2,b3,a4,b4}));
120  }
121  };
122 
123 
125  LAUNCHER (DiffListApplication_test, "unit common");
126 
127 
128 
129 }}} // namespace lib::diff::test
Apply a "list diff" to a concrete sequence of elements in a container.
Interpreter interface to define the operations ("verbs"), which describe differences or changes in a ...
Definition: list-diff.hpp:72
Definition: run.hpp:49
iter_stl::IterSnapshot< VAL > snapshot(std::initializer_list< VAL > const &&ili)
Take a snapshot of the given std::initializer_list.
Implementation namespace for support and library code.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
materialised iterator contents.
Preconfigured adapters for some STL container standard usage situations.
#define DiffStep_CTOR(_ID_)
shortcut to define tokens of the diff language.
generic builder to apply a diff description to a given target data structure.