Skip to content

Commit

Permalink
pb: add test for max_refresh_rate finish
Browse files Browse the repository at this point in the history
Closed #45
  • Loading branch information
a8m committed Sep 21, 2019
1 parent 9fa7b0e commit f0aec5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ fn fract_dur(d: Duration) -> f64 {
#[cfg(test)]
mod test {
use pb::{ProgressBar, Units};
use std::time::Duration;

#[test]
fn add() {
Expand Down Expand Up @@ -611,4 +612,34 @@ mod test {
"\r0 B / 10 B [--------------------------------------------------] ",
);
}

#[test]
fn max_refresh_rate_finish() {
let count = 500;
let mut out = Vec::new();
let mut pb = ProgressBar::on(&mut out, count);
pb.format("╢▌▌░╟");
pb.set_width(Some(80));
pb.set_max_refresh_rate(Some(Duration::from_millis(100)));
pb.show_speed = false;
pb.show_time_left = false;
pb.add(count / 2);
pb.add(count / 2);
let mut split = std::str::from_utf8(&out)
.unwrap()
.trim_start_matches('\r')
.split('\r');
assert_eq!(
split.next(),
Some(
"250 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟ 50.00 %"
)
);
assert_eq!(
split.next(),
Some(
"500 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌╟ 100.00 %"
)
);
}
}
1 change: 0 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,3 @@ fn final_redraw_max_refresh_rate() {
}
pb.finish_println("done!");
}

0 comments on commit f0aec5e

Please sign in to comment.