@@ -11,18 +11,18 @@ namespace System.CommandLine.Subsystems.Tests;
11
11
public class ValidationSubsystemTests
12
12
{
13
13
// Running exactly the same code is important here because missing a step will result in a false positive. Ask me how I know
14
- private CliOption GetOptionWithSimpleRange < T > ( T lowerBound , T upperBound )
14
+ private CliOption < T > GetOptionWithSimpleRange < T > ( string name , T lowerBound , T upperBound )
15
15
where T : IComparable < T >
16
16
{
17
- var option = new CliOption < int > ( "--intOpt" ) ;
17
+ var option = new CliOption < T > ( name ) ;
18
18
option . SetRange ( lowerBound , upperBound ) ;
19
19
return option ;
20
20
}
21
21
22
- private CliOption GetOptionWithRangeBounds < T > ( ValueSource < T > lowerBound , ValueSource < T > upperBound )
22
+ private CliOption < T > GetOptionWithRangeBounds < T > ( string name , ValueSource < T > lowerBound , ValueSource < T > upperBound )
23
23
where T : IComparable < T >
24
24
{
25
- var option = new CliOption < int > ( "--intOpt" ) ;
25
+ var option = new CliOption < T > ( name ) ;
26
26
option . SetRange ( lowerBound , upperBound ) ;
27
27
return option ;
28
28
}
@@ -45,7 +45,7 @@ private PipelineResult ExecutedPipelineResultForCommand(CliCommand command, stri
45
45
[ Fact ]
46
46
public void Int_values_in_specified_range_do_not_have_errors ( )
47
47
{
48
- var option = GetOptionWithSimpleRange ( 0 , 50 ) ;
48
+ var option = GetOptionWithSimpleRange ( "--intOpt" , 0 , 50 ) ;
49
49
50
50
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
51
51
@@ -56,7 +56,7 @@ public void Int_values_in_specified_range_do_not_have_errors()
56
56
[ Fact ]
57
57
public void Int_values_above_upper_bound_report_error ( )
58
58
{
59
- var option = GetOptionWithSimpleRange ( 0 , 5 ) ;
59
+ var option = GetOptionWithSimpleRange ( "--intOpt" , 0 , 5 ) ;
60
60
61
61
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
62
62
@@ -69,7 +69,7 @@ public void Int_values_above_upper_bound_report_error()
69
69
[ Fact ]
70
70
public void Int_below_lower_bound_report_error ( )
71
71
{
72
- var option = GetOptionWithSimpleRange ( 0 , 5 ) ;
72
+ var option = GetOptionWithSimpleRange ( "--intOpt" , 0 , 5 ) ;
73
73
74
74
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt -42" ) ;
75
75
@@ -82,7 +82,7 @@ public void Int_below_lower_bound_report_error()
82
82
[ Fact ]
83
83
public void Int_values_on_lower_range_bound_do_not_report_error ( )
84
84
{
85
- var option = GetOptionWithSimpleRange ( 42 , 50 ) ;
85
+ var option = GetOptionWithSimpleRange ( "--intOpt" , 42 , 50 ) ;
86
86
87
87
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
88
88
@@ -93,7 +93,7 @@ public void Int_values_on_lower_range_bound_do_not_report_error()
93
93
[ Fact ]
94
94
public void Int_values_on_upper_range_bound_do_not_report_error ( )
95
95
{
96
- var option = GetOptionWithSimpleRange ( 0 , 42 ) ;
96
+ var option = GetOptionWithSimpleRange ( "--intOpt" , 0 , 42 ) ;
97
97
98
98
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
99
99
@@ -104,7 +104,7 @@ public void Int_values_on_upper_range_bound_do_not_report_error()
104
104
[ Fact ]
105
105
public void Values_below_calculated_lower_bound_report_error ( )
106
106
{
107
- var option = GetOptionWithRangeBounds < int > ( ValueSource . Create ( ( ) => ( true , 1 ) ) , 50 ) ;
107
+ var option = GetOptionWithRangeBounds < int > ( "--intOpt" , ValueSource . Create ( ( ) => ( true , 1 ) ) , 50 ) ;
108
108
109
109
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 0" ) ;
110
110
@@ -118,7 +118,7 @@ public void Values_below_calculated_lower_bound_report_error()
118
118
[ Fact ]
119
119
public void Values_within_calculated_range_do_not_report_error ( )
120
120
{
121
- var option = GetOptionWithRangeBounds ( ValueSource < int > . Create ( ( ) => ( true , 1 ) ) , ValueSource < int > . Create ( ( ) => ( true , 50 ) ) ) ;
121
+ var option = GetOptionWithRangeBounds ( "--intOpt" , ValueSource . Create ( ( ) => ( true , 1 ) ) , ValueSource . Create ( ( ) => ( true , 50 ) ) ) ;
122
122
123
123
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
124
124
@@ -129,7 +129,7 @@ public void Values_within_calculated_range_do_not_report_error()
129
129
[ Fact ]
130
130
public void Values_above_calculated_upper_bound_report_error ( )
131
131
{
132
- var option = GetOptionWithRangeBounds ( 0 , ValueSource < int > . Create ( ( ) => ( true , 40 ) ) ) ;
132
+ var option = GetOptionWithRangeBounds ( "--intOpt" , 0 , ValueSource . Create ( ( ) => ( true , 40 ) ) ) ;
133
133
134
134
var pipelineResult = ExecutedPipelineResultForRangeOption ( option , "--intOpt 42" ) ;
135
135
@@ -143,7 +143,7 @@ public void Values_above_calculated_upper_bound_report_error()
143
143
public void Values_below_relative_lower_bound_report_error ( )
144
144
{
145
145
var otherOption = new CliOption < int > ( "-a" ) ;
146
- var option = GetOptionWithRangeBounds ( ValueSource . Create ( otherOption , o => ( true , ( int ) o + 1 ) ) , 50 ) ;
146
+ var option = GetOptionWithRangeBounds ( "--intOpt" , ValueSource . Create < int > ( otherOption , o => ( true , o + 1 ) ) , 50 ) ;
147
147
var command = new CliCommand ( "cmd" ) { option , otherOption } ;
148
148
149
149
var pipelineResult = ExecutedPipelineResultForCommand ( command , "--intOpt 0 -a 0" ) ;
@@ -159,7 +159,9 @@ public void Values_below_relative_lower_bound_report_error()
159
159
public void Values_within_relative_range_do_not_report_error ( )
160
160
{
161
161
var otherOption = new CliOption < int > ( "-a" ) ;
162
- var option = GetOptionWithRangeBounds ( ValueSource < int > . Create ( otherOption , o => ( true , ( int ) o + 1 ) ) , ValueSource < int > . Create ( otherOption , o => ( true , ( int ) o + 10 ) ) ) ;
162
+ var option = GetOptionWithRangeBounds ( "--intOpt" ,
163
+ ValueSource . Create < int > ( otherOption , o => ( true , o + 1 ) ) ,
164
+ ValueSource . Create < int > ( otherOption , o => ( true , o + 10 ) ) ) ;
163
165
var command = new CliCommand ( "cmd" ) { option , otherOption } ;
164
166
165
167
var pipelineResult = ExecutedPipelineResultForCommand ( command , "--intOpt 11 -a 3" ) ;
@@ -172,7 +174,7 @@ public void Values_within_relative_range_do_not_report_error()
172
174
public void Values_above_relative_upper_bound_report_error ( )
173
175
{
174
176
var otherOption = new CliOption < int > ( "-a" ) ;
175
- var option = GetOptionWithRangeBounds ( 0 , ValueSource < int > . Create ( otherOption , o => ( true , ( int ) o + 10 ) ) ) ;
177
+ var option = GetOptionWithRangeBounds ( "--intOpt" , 0 , ValueSource . Create < int > ( otherOption , o => ( true , o + 10 ) ) ) ;
176
178
var command = new CliCommand ( "cmd" ) { option , otherOption } ;
177
179
178
180
var pipelineResult = ExecutedPipelineResultForCommand ( command , "--intOpt 9 -a -2" ) ;
0 commit comments