2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections . Generic ;
5
+ using System . CommandLine . Parsing ;
5
6
using System . CommandLine . Tests . Utility ;
6
- using System . Threading . Tasks ;
7
+ using System . Linq ;
7
8
using FluentAssertions ;
8
9
using FluentAssertions . Execution ;
9
10
using Xunit ;
@@ -149,17 +150,12 @@ public void Multiple_arguments_of_unspecified_type_are_parsed_correctly()
149
150
public void When_multiple_arguments_are_defined_but_not_provided_then_option_parses_correctly ( )
150
151
{
151
152
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" )
160
154
{
161
- Name = "arg2" ,
162
- } ) ;
155
+ option ,
156
+ new Argument < string > ( ) ,
157
+ new Argument < string > ( )
158
+ } ;
163
159
164
160
var result = command . Parse ( "-e foo" ) ;
165
161
@@ -168,9 +164,8 @@ public void When_multiple_arguments_are_defined_but_not_provided_then_option_par
168
164
optionResult . Should ( ) . Be ( "foo" ) ;
169
165
}
170
166
171
-
172
167
[ 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 ( )
174
169
{
175
170
var ints = new Argument < int [ ] > ( ) ;
176
171
var strings = new Argument < string [ ] > ( ) ;
@@ -197,7 +192,7 @@ public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_n
197
192
}
198
193
199
194
[ 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 ( )
201
196
{
202
197
var ints = new Argument < int [ ] > ( ) ;
203
198
var strings = new Argument < string > ( ) ;
@@ -232,11 +227,11 @@ public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_n
232
227
[ Fact ]
233
228
public void Unsatisfied_subsequent_argument_with_min_arity_0_parses_as_default_value ( )
234
229
{
235
- var arg1 = new Argument < string > ( "arg1" )
230
+ var arg1 = new Argument < string >
236
231
{
237
232
Arity = ArgumentArity . ExactlyOne
238
233
} ;
239
- var arg2 = new Argument < string > ( "arg2" )
234
+ var arg2 = new Argument < string >
240
235
{
241
236
Arity = ArgumentArity . ZeroOrOne ,
242
237
} ;
@@ -290,6 +285,34 @@ public void When_subsequent_argument_with_ZeroOrOne_arity_is_not_provided_then_p
290
285
291
286
result . GetValueForArgument ( argument1 ) . Should ( ) . Be ( "one" ) ;
292
287
}
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
+ }
293
316
}
294
317
}
295
318
}
0 commit comments