-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathblocking_test10.cpp
More file actions
87 lines (69 loc) · 2.71 KB
/
blocking_test10.cpp
File metadata and controls
87 lines (69 loc) · 2.71 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
/*****************************************************************************
*
* 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 n_, std::initializer_list<int> nums_,
bool s_, const std::string& str_)
:
str{str_}, nums{nums_}, n{n_}, s{s_}
{}
std::string str;
std::vector<int> nums;
bool n = false, s = false;
friend bool operator == (const active& x, const active& y) noexcept {
return x.n == y.n && x.s == y.s && x.str == y.str &&
(
(x.nums.size() == 0 && y.nums.size() == 0) ||
(x.nums.size() > 0 && y.nums.size() > 0 && x.nums.size() == y.nums.size() &&
std::equal(x.nums.begin(), x.nums.end(), y.nums.begin()))
);
}
};
//-------------------------------------------------------------------
void test(int lineNo,
const std::initializer_list<const char*> args,
const active& matches)
{
using namespace clipp;
active m;
auto cli = (
option("-n", "--num").set(m.n) & integers("nums", m.nums),
option("-s", "--str").set(m.s) & value("str", m.str)
);
run_wrapped_variants({ __FILE__, lineNo }, args, cli,
[&]{ m = active{}; },
[&]{ return m == matches; });
}
//-------------------------------------------------------------------
int main()
{
try {
test(__LINE__, {""}, active{});
test(__LINE__, {"-n"}, active{true, {}, false, ""});
test(__LINE__, {"-n", "1"}, active{true, {1}, false, ""});
test(__LINE__, {"-n", "1", "5"}, active{true, {1,5}, false, ""});
test(__LINE__, {"-n", "1", "-3", "4"}, active{true, {1,-3,4}, false, ""});
test(__LINE__, {"-s"}, active{false, {}, true, ""});
test(__LINE__, {"-s", "xyz"}, active{false, {}, true, "xyz"});
test(__LINE__, {"-n", "1", "ab"}, active{true, {1}, false, ""});
test(__LINE__, {"-n", "1", "2", "ab"}, active{true, {1,2}, false, ""});
test(__LINE__, {"-n", "1", "-3", "ab"}, active{true, {1,-3}, false, ""});
test(__LINE__, {"-n", "1", "-s", "ab"}, active{true, {1}, true, "ab"});
test(__LINE__, {"-n", "1", "2", "-s", "ab"}, active{true, {1,2}, true, "ab"});
test(__LINE__, {"-n", "1", "-3", "-s", "ab"}, active{true, {1,-3}, true, "ab"});
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
}