Skip to content

Commit

Permalink
Demonstrate issues when multi has more entries than the terminal is high
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk authored and chris-laplante committed Jul 31, 2023
1 parent 8c27d55 commit 4dd47f1
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions tests/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,123 @@ hello
██████████████████████████████████████████████████████████████████████████ 10/10"
);
}

#[test]
fn multi_progress_many_bars() {
let in_mem = InMemoryTerm::new(4, 80);
let mp =
MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(in_mem.clone())));

let pb1 = mp.add(ProgressBar::new(10).with_finish(ProgressFinish::AndLeave));
let mut spinners = vec![];
for i in 0..7 {
let spinner = ProgressBar::new_spinner().with_message(i.to_string());
mp.add(spinner.clone());
spinners.push(spinner);
}

assert_eq!(in_mem.contents(), String::new());

pb1.tick();
assert_eq!(
in_mem.contents(),
r#"░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10"#
);

for spinner in &spinners {
spinner.tick()
}

assert_eq!(
in_mem.contents(),
r#"
⠁ 3
⠁ 4
⠁ 5
⠁ 6"#
.trim_start()
);

drop(pb1);
assert_eq!(
in_mem.contents(),
r#"
⠁ 3
⠁ 4
⠁ 5
⠁ 6"#
.trim_start()
);

drop(spinners);

assert_eq!(in_mem.contents(), r#""#);
}

#[test]
fn multi_progress_many_spinners() {
let in_mem = InMemoryTerm::new(4, 80);
let mp =
MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(in_mem.clone())));

let pb1 = mp.add(ProgressBar::new(10).with_finish(ProgressFinish::AndLeave));
let mut spinners = vec![];
for i in 0..7 {
let spinner = ProgressBar::new_spinner().with_message(i.to_string());
mp.add(spinner.clone());
spinners.push(spinner);
}

assert_eq!(in_mem.contents(), String::new());

pb1.tick();
assert_eq!(
in_mem.contents(),
r#"░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10"#
);

for spinner in &spinners {
spinner.tick()
}

assert_eq!(
in_mem.contents(),
r#"
⠁ 3
⠁ 4
⠁ 5
⠁ 6"#
.trim_start()
);

spinners.remove(3);

assert_eq!(
in_mem.contents(),
r#"
⠁ 2
⠁ 4
⠁ 5
⠁ 6"#
.trim_start()
);

spinners.remove(4);

assert_eq!(
in_mem.contents(),
r#"
⠁ 1
⠁ 2
⠁ 4
⠁ 6"#
.trim_start()
);

drop(spinners);

assert_eq!(
in_mem.contents(),
r#"░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10"#
);
}

0 comments on commit 4dd47f1

Please sign in to comment.