Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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)
5 2022, 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
21#include "lib/test/run.hpp"
24
25#include <string>
26
27
28namespace lib {
29namespace test{
30
31 using std::string;
32
33
34 namespace { // example strategy to use the builder-qualifier-support...
35
36
40 : BuilderQualifierSupport<ExampleStrategy>
41 {
42
43 friend Qualifier one();
44 friend Qualifier two(string);
45
46 public:
47 ExampleStrategy() = default;
48
49 template<class... QS>
50 ExampleStrategy(Qualifier qual, QS... qs)
52 {
53 qualify(*this, qual, qs...);
54 }
55
56 operator string () const
57 {
58 return "Strategy{"+prop_+"}";
59 }
60
61 private:
64 string prop_{"∅"};
65 };
66
67
69 ExampleStrategy::Qualifier
71 {
72 return ExampleStrategy::Qualifier{[](ExampleStrategy& strategy)
73 {
74 strategy.prop_ = "!one!";
75 }};
76 }
77
79 ExampleStrategy::Qualifier
80 two(string additionalArg)
81 {
82 return ExampleStrategy::Qualifier{[=](ExampleStrategy& strategy)
83 {
84 strategy.prop_ += ".two("+additionalArg+")";
85 }};
86 }
87
88 }//(End)Test example
89
90
91
92 /***********************************************************************************/
106 {
107
108 void
109 run (Arg)
110 {
111 ExampleStrategy f0;
112 CHECK (f0 == "Strategy{∅}"_expect);
113
114 ExampleStrategy f1(one());
115 CHECK (f1 == "Strategy{!one!}"_expect);
116
117 ExampleStrategy f2(two("Ψ"));
118 CHECK (f2 == "Strategy{∅.two(Ψ)}"_expect);
119
120 ExampleStrategy f3(one(), two("↯"));
121 CHECK (f3 == "Strategy{!one!.two(↯)}"_expect);
122
123 ExampleStrategy f4(two("☭"), one());
124 CHECK (f4 == "Strategy{!one!}"_expect); // Note: evaluated from left to right, one() overwrites prop_
125 }
126 };
127
128
131
132
133}} // namespace lib::test
Mix-in to support builder functions to accept optional qualifier terms.
Mix-in to accept and apply an arbitrary sequence of qualifier functors.
Example "strategy" class, which can be configured with additional qualifiers at construction.
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
ExampleStrategy::Qualifier one()
definition of a qualifier one()
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.