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)
5  2014, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
21 #include "lib/iter-adapter-stl.hpp"
22 #include "lib/util.hpp"
23 
24 #include <string>
25 #include <vector>
26 
28 using util::isnil;
29 using std::string;
30 using std::vector;
31 
32 
33 namespace lib {
34 namespace diff{
35 namespace test{
36 
37  namespace {//Test fixture....
38 
39  using DataSeq = vector<string>;
40 
41  #define TOK(id) id(STRINGIFY(id))
42 
43  string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5);
44  string TOK(b1), TOK(b2), TOK(b3), TOK(b4);
45 
47  using DiffStep = ListDiffLanguage<string>::DiffStep;
49 
50  DiffStep_CTOR(ins);
51  DiffStep_CTOR(del);
52  DiffStep_CTOR(pick);
53  DiffStep_CTOR(find);
54  DiffStep_CTOR(skip);
55 
56 
57  inline DiffSeq
58  generateTestDiff()
59  {
60  return snapshot({del(a1)
61  , del(a2)
62  , ins(b1)
63  , pick(a3)
64  , find(a5)
65  , ins(b2)
66  , ins(b3)
67  , pick(a4)
68  , skip(a5)
69  , ins(b4)
70  });
71  }
72  }//(End)Test fixture
73 
74 
75 
76 
77 
78 
79 
80 
81 
82  /***********************************************************************/
93  class DiffListApplication_test : public Test
94  {
95 
96  virtual void
97  run (Arg)
98  {
99  DataSeq src({a1,a2,a3,a4,a5});
100  DiffSeq diff = generateTestDiff();
101  CHECK (!isnil (diff));
102 
103  DataSeq target = src;
104  DiffApplicator<DataSeq> application(target);
105  application.consume(diff);
106 
107  CHECK (isnil (diff));
108  CHECK (!isnil (target));
109  CHECK (src != target);
110  CHECK (target == DataSeq({b1,a3,a5,b2,b3,a4,b4}));
111  }
112  };
113 
114 
116  LAUNCHER (DiffListApplication_test, "unit common");
117 
118 
119 
120 }}} // 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:63
Definition: run.hpp:40
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.
Simplistic 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.