Lumiera  0.pre.03
»edit your freedom«
builder-qualifier-support-test.cpp
Go to the documentation of this file.
1 /*
2  BuilderQualifierSupport(Test) - demonstrate accepting arbitrary qualifier terms on a builder function
3 
4  Copyright (C) Lumiera.org
5  2022, 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 
30 #include "lib/test/run.hpp"
32 #include "lib/test/test-helper.hpp"
33 
34 #include <string>
35 
36 
37 namespace lib {
38 namespace test{
39 
40  using std::string;
41 
42 
43  namespace { // example strategy to use the builder-qualifier-support...
44 
45 
49  : BuilderQualifierSupport<ExampleStrategy>
50  {
51 
52  friend Qualifier one();
53  friend Qualifier two(string);
54 
55  public:
56  ExampleStrategy() = default;
57 
58  template<class... QS>
59  ExampleStrategy(Qualifier qual, QS... qs)
60  : ExampleStrategy{}
61  {
62  qualify(*this, qual, qs...);
63  }
64 
65  operator string () const
66  {
67  return "Strategy{"+prop_+"}";
68  }
69 
70  private:
73  string prop_{"∅"};
74  };
75 
76 
78  ExampleStrategy::Qualifier
79  one()
80  {
81  return ExampleStrategy::Qualifier{[](ExampleStrategy& strategy)
82  {
83  strategy.prop_ = "!one!";
84  }};
85  }
86 
88  ExampleStrategy::Qualifier
89  two(string additionalArg)
90  {
91  return ExampleStrategy::Qualifier{[=](ExampleStrategy& strategy)
92  {
93  strategy.prop_ += ".two("+additionalArg+")";
94  }};
95  }
96 
97  }//(End)Test example
98 
99 
100 
101  /***********************************************************************************/
114  class BuilderQualifierSupport_test : public Test
115  {
116 
117  void
118  run (Arg)
119  {
120  ExampleStrategy f0;
121  CHECK (f0 == "Strategy{∅}"_expect);
122 
123  ExampleStrategy f1(one());
124  CHECK (f1 == "Strategy{!one!}"_expect);
125 
126  ExampleStrategy f2(two("Ψ"));
127  CHECK (f2 == "Strategy{∅.two(Ψ)}"_expect);
128 
129  ExampleStrategy f3(one(), two("↯"));
130  CHECK (f3 == "Strategy{!one!.two(↯)}"_expect);
131 
132  ExampleStrategy f4(two("☭"), one());
133  CHECK (f4 == "Strategy{!one!}"_expect); // Note: evaluated from left to right, one() overwrites prop_
134  }
135  };
136 
137 
139  LAUNCHER (BuilderQualifierSupport_test, "unit common");
140 
141 
142 }} // namespace lib::test
Definition: run.hpp:49
Mix-in to accept and apply an arbitrary sequence of qualifier functors.
Implementation namespace for support and library code.
Simple test class runner.
A collection of frequently used helper functions to support unit testing.
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
Mix-in to support builder functions to accept optional qualifier terms.
ExampleStrategy::Qualifier one()
definition of a qualifier one()
Example "strategy" class, which can be configured with additional qualifiers at construction.