-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathblocking_test04.cpp
More file actions
144 lines (116 loc) · 5.02 KB
/
blocking_test04.cpp
File metadata and controls
144 lines (116 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*****************************************************************************
*
* CLIPP - command line interfaces for modern C++
*
* released under MIT license
*
* (c) 2017-2018 André Müller; foss@andremueller-online.de
*
*****************************************************************************/
#include "testing.h"
//-------------------------------------------------------------------
namespace test04 {
struct active {
active() = default;
explicit
active(bool a_, bool b_, bool c_, bool d_, bool e_, bool f_) :
a{ a_ }, b{ b_ }, c{ c_ }, d{ d_ }, e{ e_ }, f{ f_ }
{}
bool a = false, b = false, c = false, d = false, e = false, f = false;
friend bool operator == (const active& x, const active& y) noexcept {
return (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d &&
x.e == y.e && x.f == y.f);
}
};
}
using namespace test04;
//-------------------------------------------------------------------
void test(int lineNo,
const std::initializer_list<const char*> args,
const active& matches)
{
using namespace clipp;
active m1;
auto cli1 = (
option("a").set(m1.a),
group(
command("b").set(m1.b),
command("c").set(m1.c),
command("d").set(m1.d),
command("e").set(m1.e)
),
option("f").set(m1.f)
);
//equivalent interface
active m2;
auto cli2 = (
option("a").set(m2.a),
(
required("b").set(m2.b) &
required("c").set(m2.c) &
required("d").set(m2.d) &
required("e").set(m2.e)
),
option("f").set(m2.f)
);
run_wrapped_variants({ __FILE__, lineNo }, args, cli1,
[&]{ m1 = active{}; },
[&]{ return m1 == matches; });
run_wrapped_variants({ __FILE__, lineNo }, args, cli2,
[&]{ m2 = active{}; },
[&]{ return m2 == matches; });
}
//-------------------------------------------------------------------
int main()
{
try {
test(__LINE__, {""}, active{});
test(__LINE__, {"a"}, active{1,0,0,0,0,0});
test(__LINE__, {"f"}, active{0,0,0,0,0,1});
test(__LINE__, {"b"}, active{0,1,0,0,0,0});
test(__LINE__, {"c"}, active{});
test(__LINE__, {"d"}, active{});
test(__LINE__, {"e"}, active{});
test(__LINE__, {"b", "c"}, active{0,1,1,0,0,0});
test(__LINE__, {"b", "c", "d"}, active{0,1,1,1,0,0});
test(__LINE__, {"b", "c", "d", "e"}, active{0,1,1,1,1,0});
test(__LINE__, {"b", "c", "d", "e", "f"}, active{0,1,1,1,1,1});
test(__LINE__, {"b", "c", "d", "e", "a"}, active{1,1,1,1,1,0});
test(__LINE__, {"a", "b"}, active{1,1,0,0,0,0});
test(__LINE__, {"a", "b", "c"}, active{1,1,1,0,0,0});
test(__LINE__, {"a", "b", "c", "d"}, active{1,1,1,1,0,0});
test(__LINE__, {"a", "b", "c", "d", "e"}, active{1,1,1,1,1,0});
test(__LINE__, {"f", "b"}, active{0,1,0,0,0,1});
test(__LINE__, {"f", "b", "c"}, active{0,1,1,0,0,1});
test(__LINE__, {"f", "b", "c", "d"}, active{0,1,1,1,0,1});
test(__LINE__, {"f", "b", "c", "d", "e"}, active{0,1,1,1,1,1});
test(__LINE__, {"a", "b", "c", "d", "e", "f"}, active{1,1,1,1,1,1});
test(__LINE__, {"f", "b", "c", "d", "e", "a"}, active{1,1,1,1,1,1});
test(__LINE__, {"a", "f", "b", "c", "d", "e"}, active{1,1,1,1,1,1});
test(__LINE__, {"f", "a", "b", "c", "d", "e"}, active{1,1,1,1,1,1});
test(__LINE__, {"b", "c", "d", "e", "a", "f"}, active{1,1,1,1,1,1});
test(__LINE__, {"b", "c", "d", "e", "f", "a"}, active{1,1,1,1,1,1});
test(__LINE__, {"b", "c", "a"}, active{1,1,1,0,0,0});
test(__LINE__, {"b", "c", "f"}, active{0,1,1,0,0,1});
test(__LINE__, {"b", "a", "c"}, active{1,1,0,0,0,0});
test(__LINE__, {"b", "f", "c"}, active{0,1,0,0,0,1});
test(__LINE__, {"b", "c", "d", "a"}, active{1,1,1,1,0,0});
test(__LINE__, {"b", "c", "d", "f"}, active{0,1,1,1,0,1});
test(__LINE__, {"b", "c", "a", "d"}, active{1,1,1,0,0,0});
test(__LINE__, {"b", "c", "f", "d"}, active{0,1,1,0,0,1});
test(__LINE__, {"b", "a", "c", "d"}, active{1,1,0,0,0,0});
test(__LINE__, {"b", "f", "c", "d"}, active{0,1,0,0,0,1});
test(__LINE__, {"b", "a", "c", "d", "e"}, active{1,1,0,0,0,0});
test(__LINE__, {"b", "f", "c", "d", "e"}, active{0,1,0,0,0,1});
test(__LINE__, {"b", "c", "d", "f", "a", "e"}, active{1,1,1,1,0,1});
test(__LINE__, {"b", "c", "f", "d", "a", "e"}, active{1,1,1,0,0,1});
test(__LINE__, {"b", "c", "a", "d", "f", "e"}, active{1,1,1,0,0,1});
test(__LINE__, {"b", "a", "c", "f", "d", "e"}, active{1,1,0,0,0,1});
test(__LINE__, {"b", "f", "c", "a", "d", "e"}, active{1,1,0,0,0,1});
test(__LINE__, {"b", "c", "d", "a", "e"}, active{1,1,1,1,0,0});
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
}