-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathvalue_choices_run_test.cpp
More file actions
99 lines (95 loc) · 2.5 KB
/
value_choices_run_test.cpp
File metadata and controls
99 lines (95 loc) · 2.5 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
/*
Copyright René Ferdinand Rivera Morell
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include <lyra/lyra.hpp>
#include "mini_test.hpp"
int main()
{
using namespace lyra;
bfg::mini_test::scope test;
{
std::string choice;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices("one", "two", "other");
auto result = p.parse( { "TestApp", "-c", "two" } );
test
(REQUIRE(result))
(REQUIRE(choice == "two"));
}
{
std::string choice;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices("one", "two", "other");
auto result = p.parse( { "TestApp", "-c", "foo" } );
test
(REQUIRE(!result));
}
{
int choice = 0;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices(1, 2, 3);
auto result = p.parse( { "TestApp", "-c", "2" } );
test
(REQUIRE(result))
(REQUIRE(choice == 2));
}
{
int choice = 0;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices(1, 2, 3);
auto result = p.parse( { "TestApp", "-c", "5" } );
test
(REQUIRE(!result))
(REQUIRE(choice == 0));
}
{
int choice = 0;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices(1);
auto result = p.parse( { "TestApp", "-c", "1" } );
test
(REQUIRE(result))
(REQUIRE(choice == 1));
}
{
int choice = 20;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices([](int value) -> bool { return 10 <= value && value <= 20; });
auto result = p.parse( { "TestApp", "-c", "15" } );
test
(REQUIRE(result))
(REQUIRE(choice == 15));
}
{
int choice = 20;
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices([](int value) -> bool { return 10 <= value && value <= 20; });
auto result = p.parse( { "TestApp", "-c", "40" } );
test
(REQUIRE(!result))
(REQUIRE(choice == 20));
}
{
std::string choice;
auto p = cli() | arg(choice, "choice")("the choice")
.choices("walk", "run", "jump");
auto result = p.parse( { "TestApp", "run" } );
test
(REQUIRE(result))
(REQUIRE(choice == "run"));
}
{
std::string choice;
const std::string choices[] = { "one", "two", "other" };
auto p = cli() | opt(choice, "choice")["-c"]["--choice"]("the choice")
.choices(choices);
auto result = p.parse( { "TestApp", "-c", "two" } );
test
(REQUIRE(result))
(REQUIRE(choice == "two"));
}
return test;
}