44using FluentAssertions ;
55using System . Collections ;
66using System . Collections . Generic ;
7- using System . CommandLine . Utility ;
87using System . IO ;
98using System . Linq ;
109using System . Net ;
@@ -134,14 +133,17 @@ public void Command_Argument_defaults_arity_to_ZeroOrOne_for_nullable_types()
134133 command . Arguments . Single ( ) . Arity . Should ( ) . BeEquivalentTo ( ArgumentArity . ZeroOrOne ) ;
135134 }
136135
137- [ Theory ]
138- [ InlineData ( typeof ( int [ ] ) ) ]
139- [ InlineData ( typeof ( IEnumerable < int > ) ) ]
140- [ InlineData ( typeof ( List < int > ) ) ]
141- public void Argument_infers_arity_of_IEnumerable_types_as_OneOrMore ( Type type )
136+ public static IEnumerable < object [ ] > EnumerableTypes ( )
142137 {
143- var argument = ArgumentBuilder . CreateArgument ( type ) ;
138+ yield return new object [ ] { new Argument < int [ ] > ( "array" ) } ;
139+ yield return new object [ ] { new Argument < IEnumerable < int > > ( "enumerable" ) } ;
140+ yield return new object [ ] { new Argument < List < int > > ( "list" ) } ;
141+ }
144142
143+ [ Theory ]
144+ [ MemberData ( nameof ( EnumerableTypes ) ) ]
145+ public void Argument_infers_arity_of_IEnumerable_types_as_OneOrMore ( Argument argument )
146+ {
145147 argument . Arity . Should ( ) . BeEquivalentTo ( ArgumentArity . OneOrMore ) ;
146148 }
147149
@@ -693,34 +695,28 @@ public void Values_can_be_correctly_converted_to_nullable_uint_without_the_parse
693695 public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser_specifying_a_custom_converter ( )
694696 => GetValue ( new Option < int [ ] > ( "-x" ) , "-x 1 -x 2 -x 3" ) . Should ( ) . BeEquivalentTo ( new [ ] { 1 , 2 , 3 } ) ;
695697
698+ public static IEnumerable < object [ ] > AritiesAndEnumerableTypes ( )
699+ {
700+ foreach ( int minArity in new [ ] { 0 , 1 } )
701+ {
702+ foreach ( int maxArity in new [ ] { 3 , 100_000 } )
703+ {
704+ yield return new object [ ] { minArity , maxArity , new Option < string [ ] > ( "--items" ) } ;
705+ yield return new object [ ] { minArity , maxArity , new Option < IEnumerable < string > > ( "--items" ) } ;
706+ yield return new object [ ] { minArity , maxArity , new Option < List < string > > ( "--items" ) } ;
707+ yield return new object [ ] { minArity , maxArity , new Option < IList < string > > ( "--items" ) } ;
708+ yield return new object [ ] { minArity , maxArity , new Option < ICollection < string > > ( "--items" ) } ;
709+ }
710+ }
711+ }
712+
696713 [ Theory ]
697- [ InlineData ( 0 , 100_000 , typeof ( string [ ] ) ) ]
698- [ InlineData ( 0 , 3 , typeof ( string [ ] ) ) ]
699- [ InlineData ( 0 , 100_000 , typeof ( IEnumerable < string > ) ) ]
700- [ InlineData ( 0 , 3 , typeof ( IEnumerable < string > ) ) ]
701- [ InlineData ( 0 , 100_000 , typeof ( List < string > ) ) ]
702- [ InlineData ( 0 , 3 , typeof ( List < string > ) ) ]
703- [ InlineData ( 0 , 100_000 , typeof ( IList < string > ) ) ]
704- [ InlineData ( 0 , 3 , typeof ( IList < string > ) ) ]
705- [ InlineData ( 0 , 100_000 , typeof ( ICollection < string > ) ) ]
706- [ InlineData ( 0 , 3 , typeof ( ICollection < string > ) ) ]
707-
708- [ InlineData ( 1 , 100_000 , typeof ( string [ ] ) ) ]
709- [ InlineData ( 1 , 3 , typeof ( string [ ] ) ) ]
710- [ InlineData ( 1 , 100_000 , typeof ( IEnumerable < string > ) ) ]
711- [ InlineData ( 1 , 3 , typeof ( IEnumerable < string > ) ) ]
712- [ InlineData ( 1 , 100_000 , typeof ( List < string > ) ) ]
713- [ InlineData ( 1 , 3 , typeof ( List < string > ) ) ]
714- [ InlineData ( 1 , 100_000 , typeof ( IList < string > ) ) ]
715- [ InlineData ( 1 , 3 , typeof ( IList < string > ) ) ]
716- [ InlineData ( 1 , 100_000 , typeof ( ICollection < string > ) ) ]
717- [ InlineData ( 1 , 3 , typeof ( ICollection < string > ) ) ]
714+ [ MemberData ( nameof ( AritiesAndEnumerableTypes ) ) ]
718715 public void Max_arity_greater_than_1_converts_to_enumerable_types (
719716 int minArity ,
720717 int maxArity ,
721- Type argumentType )
718+ Option option )
722719 {
723- var option = OptionBuilder . CreateOption ( "--items" , valueType : argumentType ) ;
724720 option . Arity = new ArgumentArity ( minArity , maxArity ) ;
725721
726722 var command = new RootCommand
@@ -731,7 +727,7 @@ public void Max_arity_greater_than_1_converts_to_enumerable_types(
731727 var result = command . Parse ( "--items one --items two --items three" ) ;
732728
733729 result . Errors . Should ( ) . BeEmpty ( ) ;
734- result . GetResult ( option ) . GetValueOrDefault < object > ( ) . Should ( ) . BeAssignableTo ( argumentType ) ;
730+ result . GetResult ( option ) . GetValueOrDefault < object > ( ) . Should ( ) . BeAssignableTo ( option . ValueType ) ;
735731 }
736732
737733 [ Fact ]
0 commit comments