-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathtest_choices.cpp
More file actions
91 lines (74 loc) · 3 KB
/
test_choices.cpp
File metadata and controls
91 lines (74 loc) · 3 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
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include "doctest.hpp"
using doctest::test_suite;
TEST_CASE("Parse argument that is provided zero choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
REQUIRE_THROWS_WITH_AS(program.add_argument("color").choices(),
"Zero choices provided", std::runtime_error);
}
TEST_CASE("Parse argument that is in the fixed number of allowed choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("color").choices("red", "green", "blue");
program.parse_args({"test", "red"});
}
TEST_CASE("Parse argument that is in the fixed number of allowed choices, with "
"invalid default" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("color").default_value("yellow").choices("red", "green",
"blue");
REQUIRE_THROWS_WITH_AS(
program.parse_args({"test"}),
"Invalid default value \"yellow\" - allowed options: {red, green, blue}",
std::runtime_error);
}
TEST_CASE("Parse invalid argument that is not in the fixed number of allowed "
"choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("color").choices("red", "green", "blue");
REQUIRE_THROWS_WITH_AS(
program.parse_args({"test", "red2"}),
"Invalid argument \"red2\" - allowed options: {red, green, blue}",
std::runtime_error);
}
TEST_CASE(
"Parse multiple arguments that are in the fixed number of allowed choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("color").nargs(2).choices("red", "green", "blue");
program.parse_args({"test", "red", "green"});
}
TEST_CASE("Parse multiple arguments one of which is not in the fixed number of "
"allowed choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("color").nargs(2).choices("red", "green", "blue");
REQUIRE_THROWS_WITH_AS(
program.parse_args({"test", "red", "green2"}),
"Invalid argument \"green2\" - allowed options: {red, green, blue}",
std::runtime_error);
}
TEST_CASE("Parse multiple arguments that are in the fixed number of allowed "
"INTEGER choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("indices").nargs(2).choices(1, 2, 3, 4, 5);
program.parse_args({"test", "1", "2"});
}
TEST_CASE("Parse multiple arguments that are not in fixed number of allowed "
"INTEGER choices" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("indices").nargs(2).choices(1, 2, 3, 4, 5);
REQUIRE_THROWS_WITH_AS(
program.parse_args({"test", "6", "7"}),
"Invalid argument \"6\" - allowed options: {1, 2, 3, 4, 5}",
std::runtime_error);
}