33
44using System . Collections . Generic ;
55using System . CommandLine . Builder ;
6+ using System . CommandLine . Help ;
67using System . CommandLine . Invocation ;
78using System . CommandLine . Parsing ;
89using System . IO ;
@@ -120,7 +121,7 @@ public void GetDefaultValue_can_return_null()
120121 }
121122
122123 [ Fact ]
123- public void Validation_failure_message_can_be_specified ( )
124+ public void Validation_failure_message_can_be_specified_when_parsing_tokens ( )
124125 {
125126 var argument = new Argument < FileSystemInfo > ( result =>
126127 {
@@ -138,6 +139,46 @@ public void Validation_failure_message_can_be_specified()
138139 . Be ( "oops!" ) ;
139140 }
140141
142+ [ Fact ]
143+ public void Validation_failure_message_can_be_specified_when_evaluating_default_argument_value ( )
144+ {
145+ var argument = new Argument < FileSystemInfo > ( result =>
146+ {
147+ result . ErrorMessage = "oops!" ;
148+ return null ;
149+ } , true ) ;
150+
151+ argument . Parse ( "" )
152+ . Errors
153+ . Should ( )
154+ . ContainSingle ( e => e . SymbolResult . Symbol == argument )
155+ . Which
156+ . Message
157+ . Should ( )
158+ . Be ( "oops!" ) ;
159+ }
160+
161+ [ Fact ]
162+ public void Validation_failure_message_can_be_specified_when_evaluating_default_option_value ( )
163+ {
164+ var option = new Option < FileSystemInfo > (
165+ "-x" ,
166+ result =>
167+ {
168+ result . ErrorMessage = "oops!" ;
169+ return null ;
170+ } , true ) ;
171+
172+ option . Parse ( "" )
173+ . Errors
174+ . Should ( )
175+ . ContainSingle ( )
176+ . Which
177+ . Message
178+ . Should ( )
179+ . Be ( "oops!" ) ;
180+ }
181+
141182 [ Fact ]
142183 public void custom_parsing_of_scalar_value_from_an_argument_with_one_token ( )
143184 {
@@ -309,6 +350,42 @@ public void Default_value_and_custom_argument_parser_can_be_used_together()
309350 . Should ( )
310351 . Be ( 123 ) ;
311352 }
353+
354+ [ Fact ]
355+ public void Multiple_command_arguments_can_have_custom_parse_delegates ( )
356+ {
357+ var root = new RootCommand
358+ {
359+ new Argument < FileInfo [ ] > ( "from" , argumentResult =>
360+ {
361+ argumentResult . ErrorMessage = "nope" ;
362+ return null ;
363+ } , true )
364+ {
365+ Arity = new ArgumentArity ( 0 , 2 )
366+ } ,
367+ new Argument < DirectoryInfo > ( "to" , argumentResult =>
368+ {
369+ argumentResult . ErrorMessage = "UH UH" ;
370+ return null ;
371+ } , true )
372+ {
373+ Arity = ArgumentArity . ExactlyOne
374+ }
375+ } ;
376+
377+ var result = root . Parse ( "a.txt b.txt /path/to/dir" ) ;
378+
379+ result . Errors
380+ . Select ( e => e . Message )
381+ . Should ( )
382+ . Contain ( "nope" ) ;
383+
384+ result . Errors
385+ . Select ( e => e . Message )
386+ . Should ( )
387+ . Contain ( "UH UH" ) ;
388+ }
312389
313390 [ Fact ]
314391 public void When_custom_conversion_fails_then_an_option_does_not_accept_further_arguments ( )
0 commit comments