4
4
using FluentAssertions ;
5
5
using System . Collections ;
6
6
using System . Collections . Generic ;
7
- using System . CommandLine . Utility ;
8
7
using System . IO ;
9
8
using System . Linq ;
10
9
using System . Net ;
@@ -134,14 +133,17 @@ public void Command_Argument_defaults_arity_to_ZeroOrOne_for_nullable_types()
134
133
command . Arguments . Single ( ) . Arity . Should ( ) . BeEquivalentTo ( ArgumentArity . ZeroOrOne ) ;
135
134
}
136
135
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 ( )
142
137
{
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
+ }
144
142
143
+ [ Theory ]
144
+ [ MemberData ( nameof ( EnumerableTypes ) ) ]
145
+ public void Argument_infers_arity_of_IEnumerable_types_as_OneOrMore ( Argument argument )
146
+ {
145
147
argument . Arity . Should ( ) . BeEquivalentTo ( ArgumentArity . OneOrMore ) ;
146
148
}
147
149
@@ -693,34 +695,28 @@ public void Values_can_be_correctly_converted_to_nullable_uint_without_the_parse
693
695
public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser_specifying_a_custom_converter ( )
694
696
=> GetValue ( new Option < int [ ] > ( "-x" ) , "-x 1 -x 2 -x 3" ) . Should ( ) . BeEquivalentTo ( new [ ] { 1 , 2 , 3 } ) ;
695
697
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
+
696
713
[ 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 ) ) ]
718
715
public void Max_arity_greater_than_1_converts_to_enumerable_types (
719
716
int minArity ,
720
717
int maxArity ,
721
- Type argumentType )
718
+ Option option )
722
719
{
723
- var option = OptionBuilder . CreateOption ( "--items" , valueType : argumentType ) ;
724
720
option . Arity = new ArgumentArity ( minArity , maxArity ) ;
725
721
726
722
var command = new RootCommand
@@ -731,7 +727,7 @@ public void Max_arity_greater_than_1_converts_to_enumerable_types(
731
727
var result = command . Parse ( "--items one --items two --items three" ) ;
732
728
733
729
result . Errors . Should ( ) . BeEmpty ( ) ;
734
- result . GetResult ( option ) . GetValueOrDefault < object > ( ) . Should ( ) . BeAssignableTo ( argumentType ) ;
730
+ result . GetResult ( option ) . GetValueOrDefault < object > ( ) . Should ( ) . BeAssignableTo ( option . ValueType ) ;
735
731
}
736
732
737
733
[ Fact ]
0 commit comments