File tree 2 files changed +30
-0
lines changed
Spectre.Console/Live/Progress
Tests/Spectre.Console.Tests/Unit/Live/Progress
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ private void Update(
224
224
225
225
private double GetPercentage ( )
226
226
{
227
+ if ( MaxValue == 0 )
228
+ {
229
+ return 100 ;
230
+ }
231
+
227
232
var percentage = ( Value / MaxValue ) * 100 ;
228
233
percentage = Math . Min ( 100 , Math . Max ( 0 , percentage ) ) ;
229
234
return percentage ;
Original file line number Diff line number Diff line change @@ -118,6 +118,31 @@ public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value()
118
118
task . Value . ShouldBe ( 20 ) ;
119
119
}
120
120
121
+ [ Fact ]
122
+ public void Setting_Max_Value_To_Zero_Should_Make_Percentage_OneHundred ( )
123
+ {
124
+ // Given
125
+ var console = new TestConsole ( )
126
+ . Interactive ( ) ;
127
+
128
+ var task = default ( ProgressTask ) ;
129
+ var progress = new Progress ( console )
130
+ . Columns ( new [ ] { new ProgressBarColumn ( ) } )
131
+ . AutoRefresh ( false )
132
+ . AutoClear ( false ) ;
133
+
134
+ // When
135
+ progress . Start ( ctx =>
136
+ {
137
+ task = ctx . AddTask ( "foo" ) ;
138
+ task . MaxValue = 0 ;
139
+ } ) ;
140
+
141
+ // Then
142
+ task . Value . ShouldBe ( 0 ) ;
143
+ task . Percentage . ShouldBe ( 100 ) ;
144
+ }
145
+
121
146
[ Fact ]
122
147
public void Setting_Value_Should_Override_Incremented_Value ( )
123
148
{
You can’t perform that action at this time.
0 commit comments