diff --git a/asyncgit/src/progress.rs b/asyncgit/src/progress.rs index 2474c47b..55ae92c0 100644 --- a/asyncgit/src/progress.rs +++ b/asyncgit/src/progress.rs @@ -15,7 +15,7 @@ impl ProgressPercent { pub fn new(current: usize, total: usize) -> Self { let total = f64::conv(cmp::max(current, total)); let progress = f64::conv(current) / total * 100.0; - let progress = u8::conv_nearest(progress); + let progress = u8::try_conv_nearest(progress).unwrap_or(100); Self { progress } } /// @@ -39,6 +39,12 @@ mod tests { assert_eq!(prog.progress, 100); } + #[test] + fn test_progress_zero_all() { + let prog = ProgressPercent::new(0, 0); + assert_eq!(prog.progress, 100); + } + #[test] fn test_progress_rounding() { let prog = ProgressPercent::new(2, 10);