Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Spectre.Console/Live/Progress/ProgressTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ private void Update(

private double GetPercentage()
{
if (MaxValue == 0)
{
return 100;
}

var percentage = (Value / MaxValue) * 100;
percentage = Math.Min(100, Math.Max(0, percentage));
return percentage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value()
task.Value.ShouldBe(20);
}

[Fact]
public void Setting_Max_Value_To_Zero_Should_Make_Percentage_OneHundred()
{
// Given
var console = new TestConsole()
.Interactive();

var task = default(ProgressTask);
var progress = new Progress(console)
.Columns(new[] { new ProgressBarColumn() })
.AutoRefresh(false)
.AutoClear(false);

// When
progress.Start(ctx =>
{
task = ctx.AddTask("foo");
task.MaxValue = 0;
});

// Then
task.Value.ShouldBe(0);
task.Percentage.ShouldBe(100);
}

[Fact]
public void Setting_Value_Should_Override_Incremented_Value()
{
Expand Down