22// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
44using System . Collections . Generic ;
5+ using System . CommandLine . Parsing ;
56using System . CommandLine . Tests . Utility ;
6- using System . Threading . Tasks ;
7+ using System . Linq ;
78using FluentAssertions ;
89using FluentAssertions . Execution ;
910using Xunit ;
@@ -149,17 +150,12 @@ public void Multiple_arguments_of_unspecified_type_are_parsed_correctly()
149150 public void When_multiple_arguments_are_defined_but_not_provided_then_option_parses_correctly ( )
150151 {
151152 var option = new Option < string > ( "-e" ) ;
152- var command = new Command ( "the-command" ) { option } ;
153-
154- command . AddArgument ( new Argument < string >
155- {
156- Name = "arg1" ,
157- } ) ;
158-
159- command . AddArgument ( new Argument < string >
153+ var command = new Command ( "the-command" )
160154 {
161- Name = "arg2" ,
162- } ) ;
155+ option ,
156+ new Argument < string > ( ) ,
157+ new Argument < string > ( )
158+ } ;
163159
164160 var result = command . Parse ( "-e foo" ) ;
165161
@@ -168,9 +164,8 @@ public void When_multiple_arguments_are_defined_but_not_provided_then_option_par
168164 optionResult . Should ( ) . Be ( "foo" ) ;
169165 }
170166
171-
172167 [ Fact ]
173- public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_next_multiple_arity_argument ( )
168+ public void Tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_next_multiple_arity_argument ( )
174169 {
175170 var ints = new Argument < int [ ] > ( ) ;
176171 var strings = new Argument < string [ ] > ( ) ;
@@ -197,7 +192,7 @@ public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_n
197192 }
198193
199194 [ Fact ]
200- public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_next_single_arity_argument ( )
195+ public void Tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_next_single_arity_argument ( )
201196 {
202197 var ints = new Argument < int [ ] > ( ) ;
203198 var strings = new Argument < string > ( ) ;
@@ -232,11 +227,11 @@ public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_n
232227 [ Fact ]
233228 public void Unsatisfied_subsequent_argument_with_min_arity_0_parses_as_default_value ( )
234229 {
235- var arg1 = new Argument < string > ( "arg1" )
230+ var arg1 = new Argument < string >
236231 {
237232 Arity = ArgumentArity . ExactlyOne
238233 } ;
239- var arg2 = new Argument < string > ( "arg2" )
234+ var arg2 = new Argument < string >
240235 {
241236 Arity = ArgumentArity . ZeroOrOne ,
242237 } ;
@@ -290,6 +285,34 @@ public void When_subsequent_argument_with_ZeroOrOne_arity_is_not_provided_then_p
290285
291286 result . GetValueForArgument ( argument1 ) . Should ( ) . Be ( "one" ) ;
292287 }
288+
289+ [ Theory ] // https://github.com/dotnet/command-line-api/issues/1711
290+ [ InlineData ( "" ) ]
291+ [ InlineData ( "a" ) ]
292+ [ InlineData ( "a b" ) ]
293+ [ InlineData ( "a b c" ) ]
294+ public void When_there_are_not_enough_tokens_for_all_arguments_then_the_correct_number_of_errors_is_reported (
295+ string providedArgs )
296+ {
297+ var command = new Command ( "command" )
298+ {
299+ new Argument < string > ( ) ,
300+ new Argument < string > ( ) ,
301+ new Argument < string > ( ) ,
302+ new Argument < string > ( )
303+ } ;
304+
305+ var result = new Parser ( command ) . Parse ( providedArgs ) ;
306+
307+ var numberOfMissingArgs =
308+ result
309+ . Errors
310+ . Count ( e => e . Message == LocalizationResources . Instance . RequiredArgumentMissing ( result . CommandResult ) ) ;
311+
312+ numberOfMissingArgs
313+ . Should ( )
314+ . Be ( 4 - providedArgs . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) . Length ) ;
315+ }
293316 }
294317 }
295318}
0 commit comments