Commit af9bd7c9 authored by Joseph Noir's avatar Joseph Noir

Add test case for find by long opt

parent e70a83bd
......@@ -199,3 +199,31 @@ CAF_TEST(flat CLI parsing with nested categories) {
CAF_CHECK_EQUAL(x.full_name(), "foo.goo.bar");
CAF_CHECK_EQUAL(x.has_flat_cli_name(), true);
}
CAF_TEST(find by long opt) {
auto needle = make_config_option<std::string>("?foo", "bar,b", "test option");
auto check = [&](std::vector<string> args, bool found_opt, bool has_opt) {
auto res = find_by_long_name(needle, std::begin(args), std::end(args));
CAF_CHECK_EQUAL(res.first != std::end(args), found_opt);
if (has_opt)
CAF_CHECK_EQUAL(res.second, "val2");
else
CAF_CHECK(res.second.empty());
};
// Well formed, find val2.
check({"--foo=val1", "--bar=val2", "--baz=val3"}, true, true);
// Dashes missing, no match.
check({"--foo=val1", "bar=val2", "--baz=val3"}, false, false);
// Equal missing.
check({"--fooval1", "--barval2", "--bazval3"}, false, false);
// Option value missing.
check({"--foo=val1", "--bar=", "--baz=val3"}, true, false);
// With prefix 'caf#'.
check({"--caf#foo=val1", "--caf#bar=val2", "--caf#baz=val3"}, true, true);
// Option not included.
check({"--foo=val1", "--b4r=val2", "--baz=val3"}, false, false);
// Option not included, with prefix.
check({"--caf#foo=val1", "--caf#b4r=val2", "--caf#baz=val3"}, false, false);
// No options to look through.
check({}, false, false);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment