File tree Expand file tree Collapse file tree
Spectre.Console/Live/Progress
Tests/Spectre.Console.Tests/Unit/Live/Progress Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ private void Update(
224224
225225 private double GetPercentage ( )
226226 {
227+ if ( MaxValue == 0 )
228+ {
229+ return 100 ;
230+ }
231+
227232 var percentage = ( Value / MaxValue ) * 100 ;
228233 percentage = Math . Min ( 100 , Math . Max ( 0 , percentage ) ) ;
229234 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()
118118 task . Value . ShouldBe ( 20 ) ;
119119 }
120120
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+
121146 [ Fact ]
122147 public void Setting_Value_Should_Override_Incremented_Value ( )
123148 {
You can’t perform that action at this time.
0 commit comments