-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathblocking_test01.cpp
More file actions
136 lines (105 loc) · 5.39 KB
/
blocking_test01.cpp
File metadata and controls
136 lines (105 loc) · 5.39 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
/*****************************************************************************
*
* 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 test01 {
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 test01;
//-------------------------------------------------------------------
void test(int lineNo,
const std::initializer_list<const char*> args,
const active& matches)
{
using namespace clipp;
active m;
auto cli = (
option("-a").set(m.a),
command("-b").set(m.b),
option("-c").set(m.c),
option("-i") & value("i", m.i),
option("-d").set(m.d),
command("-e").set(m.e),
option("-f").set(m.f)
);
run_test({ __FILE__, lineNo }, args, cli, [&]{ return m == matches; });
}
//-------------------------------------------------------------------
int main()
{
try {
test(__LINE__, {""}, active{});
test(__LINE__, {"-a"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-a", "-c"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-a", "-d"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-a", "-e"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-a", "-f"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-a", "-i", "123"}, active{1,0,0,0,0,0, 0});
test(__LINE__, {"-b"}, active{0,1,0,0,0,0, 0});
test(__LINE__, {"-b", "-a"}, active{0,1,0,0,0,0, 0});
test(__LINE__, {"-a", "-b"}, active{1,1,0,0,0,0, 0});
test(__LINE__, {"-b", "-c"}, active{0,1,1,0,0,0, 0});
test(__LINE__, {"-a", "-b", "-c"}, active{1,1,1,0,0,0, 0});
test(__LINE__, {"-a", "-b", "-c", "-i"}, active{1,1,1,0,0,0, 0});
test(__LINE__, {"-a", "-b", "-c", "-i", "123"}, active{1,1,1,0,0,0, 123});
test(__LINE__, {"-b", "-i", "123"}, active{0,1,0,0,0,0, 123});
test(__LINE__, {"-a", "-b", "-i", "123"}, active{1,1,0,0,0,0, 123});
test(__LINE__, {"-a", "-b", "-c", "-i", "123"}, active{1,1,1,0,0,0, 123});
test(__LINE__, {"-a", "-b", "-d", "-i", "123"}, active{1,1,0,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-i", "123", "-c"}, active{1,1,1,0,0,0, 123});
test(__LINE__, {"-a", "-b", "-i", "123", "-d"}, active{1,1,0,1,0,0, 123});
test(__LINE__, {"-b", "-i", "123", "-a"}, active{0,1,0,0,0,0, 123});
test(__LINE__, {"-b", "-i", "123", "-a"}, active{0,1,0,0,0,0, 123});
test(__LINE__, {"-b", "-i", "123", "-d", "-c"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-i", "123", "-c", "-d"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-c", "-i", "123", "-d"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-c", "-d", "-i", "123"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-d", "-c", "-i", "123"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-d", "-i", "123", "-c"}, active{0,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-i", "123", "-d", "-c"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-i", "123", "-c", "-d"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-c", "-i", "123", "-d"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-c", "-d", "-i", "123"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-d", "-c", "-i", "123"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-a", "-b", "-d", "-i", "123", "-c"}, active{1,1,1,1,0,0, 123});
test(__LINE__, {"-b", "-c", "-d"}, active{0,1,1,1,0,0, 0});
test(__LINE__, {"-b", "-c", "-d", "-e"}, active{0,1,1,1,1,0, 0});
test(__LINE__, {"-b", "-c", "-d", "-e", "-f"}, active{0,1,1,1,1,1, 0});
test(__LINE__, {"-a", "-b", "-c", "-d"}, active{1,1,1,1,0,0, 0});
test(__LINE__, {"-a", "-b", "-c", "-d", "-e"}, active{1,1,1,1,1,0, 0});
test(__LINE__, {"-a", "-b", "-c", "-d", "-e", "-f"}, active{1,1,1,1,1,1, 0});
test(__LINE__, {"-b", "-f"}, active{0,1,0,0,0,0, 0});
test(__LINE__, {"-b", "-e", "-f"}, active{0,1,0,0,1,1, 0});
test(__LINE__, {"-a", "-b", "-f"}, active{1,1,0,0,0,0, 0});
test(__LINE__, {"-a", "-b", "-e", "-f"}, active{1,1,0,0,1,1, 0});
test(__LINE__, {"-b", "-e", "-c"}, active{0,1,0,0,1,0, 0});
test(__LINE__, {"-b", "-e", "-d"}, active{0,1,0,0,1,0, 0});
test(__LINE__, {"-b", "-e", "-i", "123"}, active{0,1,0,0,1,0, 0});
test(__LINE__, {"-a", "-b", "-e", "-c"}, active{1,1,0,0,1,0, 0});
test(__LINE__, {"-a", "-b", "-e", "-d"}, active{1,1,0,0,1,0, 0});
test(__LINE__, {"-a", "-b", "-e", "-i", "123"}, active{1,1,0,0,1,0, 0});
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
}