Skip to content

Commit ed72cc2

Browse files
committed
Add tests for the current implicit_value behaviour.
1 parent c83abc2 commit ed72cc2

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

test/cmdline_test.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ void apply_syntax(options_description& desc,
7777
v = value<string>();
7878
s.resize(s.size()-1);
7979
} else if (*(s.end()-1) == '?') {
80-
//v = value<string>()->implicit();
81-
v = value<string>();
80+
v = value<string>()->implicit_value("default");
8281
s.resize(s.size()-1);
8382
} else if (*(s.end()-1) == '*') {
8483
v = value<vector<string> >()->multitoken();
@@ -607,6 +606,34 @@ void test_unregistered()
607606
// It's not clear yet, so I'm leaving the decision till later.
608607
}
609608

609+
void test_implicit_value()
610+
{
611+
using namespace command_line_style;
612+
cmdline::style_t style;
613+
614+
style = cmdline::style_t(
615+
allow_long | long_allow_adjacent
616+
);
617+
618+
test_case test_cases1[] = {
619+
// 'bar' does not even look like option, so is consumed
620+
{"--foo bar", s_success, "foo:bar"},
621+
// '--bar' looks like option, and such option exists, so we don't consume this token
622+
{"--foo --bar", s_success, "foo: bar:"},
623+
// '--biz' looks like option, but does not match any existing one.
624+
// Presently this results in parse error, since
625+
// (1) in cmdline.cpp:finish_option, we only consume following tokens if they are
626+
// requires
627+
// (2) in cmdline.cpp:run, we let options consume following positional options
628+
// For --biz, an exception is thrown between 1 and 2.
629+
// We might want to fix that in future.
630+
{"--foo --biz", s_unknown_option, ""},
631+
{0, 0, 0}
632+
};
633+
634+
test_cmdline("foo? bar?", style, test_cases1);
635+
}
636+
610637
int main(int /*ac*/, char** /*av*/)
611638
{
612639
test_long_options();
@@ -619,6 +646,7 @@ int main(int /*ac*/, char** /*av*/)
619646
test_additional_parser();
620647
test_style_parser();
621648
test_unregistered();
649+
test_implicit_value();
622650

623651
return 0;
624652
}

0 commit comments

Comments
 (0)