Skip to content

Commit f653cac

Browse files
multi: add tests for ProgressBar::visual_index
1 parent c056e7f commit f653cac

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

src/multi.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,28 @@ mod tests {
558558
let p1 = mp.add(ProgressBar::new(1));
559559
let p2 = mp.add(ProgressBar::new(1));
560560
let p3 = mp.add(ProgressBar::new(1));
561+
562+
// Check position of bars on screen
563+
assert_eq!(
564+
&[
565+
p0.visual_index().unwrap(),
566+
p1.visual_index().unwrap(),
567+
p2.visual_index().unwrap(),
568+
p3.visual_index().unwrap()
569+
],
570+
&[0, 1, 2, 3]
571+
);
572+
561573
mp.remove(&p2);
562574
mp.remove(&p1);
575+
576+
assert_eq!(
577+
&[p0.visual_index().unwrap(), p3.visual_index().unwrap(),],
578+
&[0, 1]
579+
);
580+
563581
let p4 = mp.insert(1, ProgressBar::new(1));
582+
assert_eq!(p4.visual_index().unwrap(), 1);
564583

565584
let state = mp.state.read().unwrap();
566585
// the removed place for p1 is reused
@@ -586,6 +605,18 @@ mod tests {
586605
assert_eq!(p1.index(), None);
587606
assert_eq!(p2.index(), None);
588607
assert_eq!(p3.index().unwrap(), 3);
608+
609+
// Check position of bars on screen
610+
assert_eq!(
611+
&[
612+
p0.visual_index(),
613+
p1.visual_index(),
614+
p2.visual_index(),
615+
p3.visual_index(),
616+
p4.visual_index()
617+
],
618+
&[Some(0), None, None, Some(2), Some(1)]
619+
);
589620
}
590621

591622
#[test]
@@ -604,6 +635,18 @@ mod tests {
604635
assert_eq!(p2.index().unwrap(), 2);
605636
assert_eq!(p3.index().unwrap(), 3);
606637
assert_eq!(p4.index().unwrap(), 4);
638+
639+
// Check position of bars on screen
640+
assert_eq!(
641+
&[
642+
p0.visual_index().unwrap(),
643+
p1.visual_index().unwrap(),
644+
p2.visual_index().unwrap(),
645+
p3.visual_index().unwrap(),
646+
p4.visual_index().unwrap()
647+
],
648+
&[1, 2, 4, 3, 0]
649+
);
607650
}
608651

609652
#[test]
@@ -622,6 +665,18 @@ mod tests {
622665
assert_eq!(p2.index().unwrap(), 2);
623666
assert_eq!(p3.index().unwrap(), 3);
624667
assert_eq!(p4.index().unwrap(), 4);
668+
669+
// Check position of bars on screen
670+
assert_eq!(
671+
&[
672+
p0.visual_index().unwrap(),
673+
p1.visual_index().unwrap(),
674+
p2.visual_index().unwrap(),
675+
p3.visual_index().unwrap(),
676+
p4.visual_index().unwrap()
677+
],
678+
&[0, 2, 3, 4, 1]
679+
);
625680
}
626681

627682
#[test]
@@ -640,6 +695,18 @@ mod tests {
640695
assert_eq!(p2.index().unwrap(), 2);
641696
assert_eq!(p3.index().unwrap(), 3);
642697
assert_eq!(p4.index().unwrap(), 4);
698+
699+
// Check position of bars on screen
700+
assert_eq!(
701+
&[
702+
p0.visual_index().unwrap(),
703+
p1.visual_index().unwrap(),
704+
p2.visual_index().unwrap(),
705+
p3.visual_index().unwrap(),
706+
p4.visual_index().unwrap()
707+
],
708+
&[1, 2, 4, 0, 3]
709+
);
643710
}
644711

645712
#[test]
@@ -662,6 +729,20 @@ mod tests {
662729
assert_eq!(p4.index().unwrap(), 4);
663730
assert_eq!(p5.index().unwrap(), 5);
664731
assert_eq!(p6.index().unwrap(), 6);
732+
733+
// Check position of bars on screen
734+
assert_eq!(
735+
&[
736+
p0.visual_index().unwrap(),
737+
p1.visual_index().unwrap(),
738+
p2.visual_index().unwrap(),
739+
p3.visual_index().unwrap(),
740+
p4.visual_index().unwrap(),
741+
p5.visual_index().unwrap(),
742+
p6.visual_index().unwrap()
743+
],
744+
&[3, 5, 6, 0, 2, 1, 4]
745+
);
665746
}
666747

667748
#[test]

0 commit comments

Comments
 (0)