@@ -63,7 +63,8 @@ struct test_case {
63
63
The "boost::program_options" in parameter type is needed because CW9
64
64
has std::detail and it causes an ambiguity.
65
65
*/
66
- void apply_syntax (options_description& desc,
66
+ void apply_syntax (options_description& desc,
67
+ positional_options_description & m_positional,
67
68
const char * syntax)
68
69
{
69
70
@@ -77,8 +78,8 @@ void apply_syntax(options_description& desc,
77
78
v = value<string>();
78
79
s.resize (s.size ()-1 );
79
80
} else if (*(s.end ()-1 ) == ' ?' ) {
80
- // v = value<string>()->implicit( );
81
- v = value<string>( );
81
+ v = value<string>()->implicit_value ( " bar " );
82
+ m_positional. add ( " positional " , - 1 );
82
83
s.resize (s.size ()-1 );
83
84
} else if (*(s.end ()-1 ) == ' *' ) {
84
85
v = value<vector<string> >()->multitoken ();
@@ -113,12 +114,14 @@ void test_cmdline(const char* syntax,
113
114
}
114
115
}
115
116
options_description desc;
116
- apply_syntax (desc, syntax);
117
+ positional_options_description m_positional;
118
+ apply_syntax (desc, m_positional, syntax);
117
119
118
120
cmdline cmd (xinput);
119
121
cmd.style (style);
120
122
cmd.set_options_description (desc);
121
-
123
+ if (m_positional.max_total_count ())
124
+ cmd.set_positional_options (m_positional);
122
125
123
126
string result;
124
127
int status = 0 ;
@@ -130,7 +133,9 @@ void test_cmdline(const char* syntax,
130
133
{
131
134
option opt = options[j];
132
135
133
- if (opt.position_key != -1 ) {
136
+ if (opt.position_key != -1
137
+ && (m_positional.max_total_count () == 0 || (size_t )opt.position_key >= m_positional.max_total_count ()
138
+ || m_positional.name_for_position (opt.position_key ) != " positional" )) {
134
139
if (!result.empty ())
135
140
result += " " ;
136
141
result += opt.value [0 ];
@@ -228,7 +233,7 @@ void test_long_options()
228
233
{" --giz" , s_success, " Giz:" },
229
234
{0 , 0 , 0 }
230
235
};
231
- test_cmdline (" foo bar= baz? Giz" , style, test_cases4);
236
+ test_cmdline (" foo bar= Giz" , style, test_cases4);
232
237
}
233
238
234
239
void test_short_options ()
@@ -348,15 +353,15 @@ void test_disguised_long()
348
353
{" -bee=x -by" , s_success, " bee:x bee:y" },
349
354
{0 , 0 , 0 }
350
355
};
351
- test_cmdline (" foo,f goo,g= bee,b? " , style, test_cases1);
356
+ test_cmdline (" foo,f goo,g= bee,b= " , style, test_cases1);
352
357
353
358
style = cmdline::style_t (style | allow_slash_for_short);
354
359
test_case test_cases2[] = {
355
360
{" /foo -f" , s_success, " foo: foo:" },
356
361
{" /goo=x" , s_success, " goo:x" },
357
362
{0 , 0 , 0 }
358
363
};
359
- test_cmdline (" foo,f goo,g= bee,b? " , style, test_cases2);
364
+ test_cmdline (" foo,f goo,g=" , style, test_cases2);
360
365
}
361
366
362
367
void test_guessing ()
@@ -607,6 +612,35 @@ void test_unregistered()
607
612
// It's not clear yet, so I'm leaving the decision till later.
608
613
}
609
614
615
+ void test_implicit_value ()
616
+ {
617
+ using namespace command_line_style ;
618
+ cmdline::style_t style;
619
+
620
+ style = cmdline::style_t (
621
+ allow_long | long_allow_adjacent
622
+ );
623
+
624
+ test_case test_cases1[] = {
625
+ {" --foo bar" , s_success, " foo: positional:bar" },
626
+ {" --foo=bar foobar" , s_success, " foo:bar positional:foobar" },
627
+ {0 , 0 , 0 }
628
+ };
629
+
630
+ test_cmdline (" positional= foo?" , style, test_cases1);
631
+
632
+ style = cmdline::style_t (
633
+ allow_short | allow_dash_for_short
634
+ | short_allow_adjacent);
635
+
636
+ test_case test_cases2[] = {
637
+ {" -f bar" , s_success, " -f: positional:bar" },
638
+ {" -fbar foobar" , s_success, " -f:bar positional:foobar" },
639
+ {0 , 0 , 0 }
640
+ };
641
+ test_cmdline (" positional= ,f?" , style, test_cases2);
642
+ }
643
+
610
644
int main (int /* ac*/ , char ** /* av*/ )
611
645
{
612
646
test_long_options ();
@@ -619,6 +653,7 @@ int main(int /*ac*/, char** /*av*/)
619
653
test_additional_parser ();
620
654
test_style_parser ();
621
655
test_unregistered ();
656
+ test_implicit_value ();
622
657
623
658
return 0 ;
624
659
}
0 commit comments