-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathblocking_test02.cpp
More file actions
157 lines (121 loc) · 5.65 KB
/
blocking_test02.cpp
File metadata and controls
157 lines (121 loc) · 5.65 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
145
146
147
148
149
150
151
152
153
154
155
156
157
/*****************************************************************************
*
* 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 test02 {
struct active {
active() = default;
explicit
active(bool a_, bool b_, bool c_, bool d_, bool e_, bool f_, int i_ = 0) :
a{ a_ }, b{ b_ }, c{ c_ }, d{ d_ }, e{ e_ }, f{ f_ }, i{ i_ }
{}
bool a = false, b = false, c = false, d = false, e = false, f = false;
int i = 0;
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 && x.i == y.i);
}
};
}
using namespace test02;
//-------------------------------------------------------------------
void test(int lineNo,
const std::initializer_list<const char*> args,
const active& matches)
{
using namespace clipp;
active m;
auto cli = (
( command("a"),
option("-x").set(m.a)
).doc("group (~a,-x)")
|
( command("b"),
option("-x").set(m.b),
( command("u").set(m.i,1) |
command("v").set(m.i,2) |
command("w").set(m.i,3)
).doc("group (u|v|w)"),
option("-e").set(m.e)
).doc("group (~b,-x,(~u|~v|~w),-e)")
|
( command("c"),
option("-x").set(m.c),
command("d").set(m.d),
required("-i").set(m.e) & value("i", m.i),
option("-f").set(m.f)
).doc("group (~c,-x,d,(~-i,~i),-f)")
);
run_wrapped_variants({ __FILE__, lineNo }, args, cli,
[&]{ m = active{}; },
[&]{ return m == matches; });
}
//-------------------------------------------------------------------
int main()
{
try {
test(__LINE__, {""}, active{});
test(__LINE__, {"a"}, active{});
test(__LINE__, {"b"}, active{});
test(__LINE__, {"c"}, active{});
test(__LINE__, {"-x"}, active{});
test(__LINE__, {"a", "-x"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"b", "-x"}, active{0,1,0,0,0,0, 0});
test(__LINE__, {"c", "-x"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"b", "u"}, active{0,0,0,0,0,0, 1});
test(__LINE__, {"b", "v"}, active{0,0,0,0,0,0, 2});
test(__LINE__, {"b", "w"}, active{0,0,0,0,0,0, 3});
test(__LINE__, {"b", "-x", "u"}, active{0,1,0,0,0,0, 1});
test(__LINE__, {"b", "-x", "v"}, active{0,1,0,0,0,0, 2});
test(__LINE__, {"b", "-x", "w"}, active{0,1,0,0,0,0, 3});
test(__LINE__, {"b", "u", "-x"}, active{0,0,0,0,0,0, 1});
test(__LINE__, {"b", "v", "-x"}, active{0,0,0,0,0,0, 2});
test(__LINE__, {"b", "w", "-x"}, active{0,0,0,0,0,0, 3});
test(__LINE__, {"b", "-x", "u", "-e"}, active{0,1,0,0,1,0, 1});
test(__LINE__, {"b", "-x", "v", "-e"}, active{0,1,0,0,1,0, 2});
test(__LINE__, {"b", "-x", "w", "-e"}, active{0,1,0,0,1,0, 3});
test(__LINE__, {"b", "u", "-x", "-e"}, active{0,0,0,0,1,0, 1});
test(__LINE__, {"b", "v", "-x", "-e"}, active{0,0,0,0,1,0, 2});
test(__LINE__, {"b", "w", "-x", "-e"}, active{0,0,0,0,1,0, 3});
test(__LINE__, {"b", "-x", "u", "-e"}, active{0,1,0,0,1,0, 1});
test(__LINE__, {"b", "-x", "v", "-e"}, active{0,1,0,0,1,0, 2});
test(__LINE__, {"b", "-x", "w", "-e"}, active{0,1,0,0,1,0, 3});
test(__LINE__, {"b", "-x", "-e", "u"}, active{0,1,0,0,0,0, 1});
test(__LINE__, {"b", "-x", "-e", "v"}, active{0,1,0,0,0,0, 2});
test(__LINE__, {"b", "-x", "-e", "w"}, active{0,1,0,0,0,0, 3});
test(__LINE__, {"c", "-x", "-i"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "-f"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "123"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "-i", "123"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "-i", "-f"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "123", "-i"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "123", "-f"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "-i", "123", "-f"}, active{0,0,1,0,0,0, 0});
test(__LINE__, {"c", "-x", "d"}, active{0,0,1,1,0,0, 0});
test(__LINE__, {"c", "-x", "d", "-i"}, active{0,0,1,1,1,0, 0});
test(__LINE__, {"c", "-x", "d", "-f"}, active{0,0,1,1,0,1, 0});
test(__LINE__, {"c", "-x", "d", "123"}, active{0,0,1,1,0,0, 0});
test(__LINE__, {"c", "-x", "d", "-i", "123"}, active{0,0,1,1,1,0, 123});
test(__LINE__, {"c", "-x", "d", "-i", "-f"}, active{0,0,1,1,1,1, 0});
test(__LINE__, {"c", "-x", "d", "123", "-i"}, active{0,0,1,1,1,0, 0});
test(__LINE__, {"c", "-x", "d", "123", "-f"}, active{0,0,1,1,0,1, 0});
test(__LINE__, {"c", "-x", "d", "-i", "123", "-f"}, active{0,0,1,1,1,1, 123});
test(__LINE__, {"c", "-x", "d", "-f", "-i"}, active{0,0,1,1,1,1, 0});
test(__LINE__, {"c", "-x", "d", "-f", "-i", "123"}, active{0,0,1,1,1,1, 123});
test(__LINE__, {"c", "d", "-f", "-i", "123"}, active{0,0,0,1,1,1, 123});
test(__LINE__, {"c", "d", "-i", "123", "-f"}, active{0,0,0,1,1,1, 123});
test(__LINE__, {"c", "d", "-x", "-i", "123", "-f"}, active{0,0,0,1,1,1, 123});
test(__LINE__, {"c", "d", "-f", "-i", "123", "-x"}, active{0,0,0,1,1,1, 123});
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
}