options: use range based for in some tests

This commit is contained in:
Danny Robson 2014-10-21 21:48:13 +11:00
parent 31326ef576
commit cf6fc87c9f

View File

@ -70,31 +70,33 @@ test_bool_opt (void) {
p->add_option (make_unique<valueoption<bool>> ('b', "bool", "testing boolean actions", &value)); p->add_option (make_unique<valueoption<bool>> ('b', "bool", "testing boolean actions", &value));
// List all legal forms of positive or negative boolean values // List all legal forms of positive or negative boolean values
static const char *argv[] = { "./foo", "-b", NULL }; std::array<const char*, 3> argv { "./foo", "-b", NULL };
static const char *positive[] = { "1", "true", "yes" }; static const char *positive[] = { "1", "true", "yes" };
static const char *negative[] = { "0", "false", "no" }; static const char *negative[] = { "0", "false", "no" };
// For each boolean value, ensure that it returns as expected // For each boolean value, ensure that it returns as expected
for (size_t i = 0; i < elems (positive); ++i) { for (auto i: positive) {
argv[2] = positive[i]; static size_t count;
p->parse_args (elems (argv), argv); std::cerr << "iter " << count++ << '\n';
argv[2] = i;
p->parse_args (argv.size (), argv.data ());
CHECK (value == true); CHECK (value == true);
} }
for (size_t i = 0; i < elems (negative); ++i) { for (auto i: negative) {
argv[2] = negative[i]; argv[2] = i;
p->parse_args (elems (argv), argv); p->parse_args (argv.size (), argv.data ());
CHECK (value == false); CHECK (value == false);
} }
// Check that invalid forms of boolean all throw exceptions // Check that invalid forms of boolean all throw exceptions
const char* invalid[] = { "foo", "y", "null" }; const char* invalid[] = { "foo", "y", "null" };
for (size_t i = 0; i < elems (invalid); ++i) { for (auto i: invalid) {
argv[2] = invalid[i]; argv[2] = i;
CHECK_THROWS ( CHECK_THROWS (
std::domain_error, std::domain_error,
p->parse_args (elems (argv), argv) p->parse_args (argv.size (), argv.data ())
); );
} }
} }