-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalternative_options_test.cpp
More file actions
111 lines (92 loc) · 3.09 KB
/
Copy pathalternative_options_test.cpp
File metadata and controls
111 lines (92 loc) · 3.09 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
/*****************************************************************************
*
* CLIPP - command line interfaces for modern C++
*
* released under MIT license
*
* (c) 2017-2018 André Müller; foss@andremueller-online.de
*
*****************************************************************************/
#include "testing.h"
//-------------------------------------------------------------------
struct active {
active() = default;
explicit
active(bool a_, bool b_, bool c_, bool d_):
a{a_}, b{b_}, c{c_}, d{d_}
{}
bool a = false, b = false, c = false, d = false;
bool conflict = 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.conflict == y.conflict);
}
};
//-------------------------------------------------------------------
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) |
option("-b").set(m.b) |
option("-c").set(m.c) |
option("-d").set(m.d);
auto res = parse(args, cli);
m.conflict = res.any_conflict();
if(!(m == matches)) {
throw std::runtime_error{"failed " + std::string( __FILE__ ) +
" #1 in line " + std::to_string(lineNo)};
}
}
{
active m;
auto cli = (
option("?????"),
(
option("-a").set(m.a) |
option("-b").set(m.b) |
option("-c").set(m.c) |
option("-d").set(m.d)
)
);
auto res = parse(args, cli);
m.conflict = res.any_conflict();
if(!(m == matches)) {
throw std::runtime_error{"failed " + std::string( __FILE__ ) +
" #2 in line " + std::to_string(lineNo)};
}
}
}
//-------------------------------------------------------------------
int main()
{
try {
test(__LINE__, {""}, active{});
test(__LINE__, {"-a"}, active{1,0,0,0});
test(__LINE__, {"-b"}, active{0,1,0,0});
test(__LINE__, {"-c"}, active{0,0,1,0});
test(__LINE__, {"-d"}, active{0,0,0,1});
{
active e; e.conflict = true;
test(__LINE__, {"-a","-b"}, e);
test(__LINE__, {"-b","-a"}, e);
test(__LINE__, {"-c","-b"}, e);
test(__LINE__, {"-d","-c"}, e);
test(__LINE__, {"-a","-d"}, e);
test(__LINE__, {"-a","-b","-c"}, e);
test(__LINE__, {"-c","-b","-a"}, e);
test(__LINE__, {"-d","-a","-c"}, e);
test(__LINE__, {"-a","-b","-c", "-d"}, e);
test(__LINE__, {"-d","-c","-b", "-a"}, e);
test(__LINE__, {"-c","-b","-a", "-d"}, e);
test(__LINE__, {"-d","-a","-c", "-b"}, e);
}
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
}