Skip to content

Commit 3d5dbb3

Browse files
RDruondjc
authored andcommitted
Add render tests
1 parent 66a90a6 commit 3d5dbb3

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tests/render.rs

+128
Original file line numberDiff line numberDiff line change
@@ -916,3 +916,131 @@ fn multi_progress_bottom_alignment() {
916916
in_mem.write_line("anchor").unwrap();
917917
assert_eq!(in_mem.contents(), "\n\nanchor");
918918
}
919+
920+
#[test]
921+
fn progress_bar_terminal_wrap() {
922+
use std::cmp::min;
923+
let in_mem = InMemoryTerm::new(10, 20);
924+
925+
let mut downloaded = 0;
926+
let total_size = 231231231;
927+
928+
let pb = ProgressBar::with_draw_target(
929+
None,
930+
ProgressDrawTarget::term_like(Box::new(in_mem.clone())),
931+
);
932+
pb.set_style(ProgressStyle::default_bar()
933+
.template("{msg:>12.cyan.bold} {spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes}").unwrap()
934+
.progress_chars("#>-"));
935+
936+
pb.set_message("Downloading");
937+
assert_eq!(
938+
in_mem.contents(),
939+
r#" Downloading ⠁ [00:0
940+
0:00] [-------------
941+
--------------------
942+
-------] 0B/0B"#
943+
);
944+
945+
let new = min(downloaded + 223211, total_size);
946+
downloaded = new;
947+
pb.set_position(new);
948+
assert_eq!(
949+
in_mem.contents(),
950+
r#" Downloading ⠁ [00:0
951+
0:00] [-------------
952+
--------------------
953+
-------] 217.98 KiB/
954+
217.98 KiB"#
955+
);
956+
957+
let new = min(downloaded + 223211, total_size);
958+
pb.set_position(new);
959+
assert_eq!(
960+
in_mem.contents(),
961+
r#" Downloading ⠉ [00:0
962+
0:00] [-------------
963+
--------------------
964+
-------] 435.96 KiB/
965+
435.96 KiB"#
966+
);
967+
968+
pb.set_style(
969+
ProgressStyle::default_bar()
970+
.template("{msg:>12.green.bold} downloading {total_bytes:.green} in {elapsed:.green}")
971+
.unwrap(),
972+
);
973+
pb.finish_with_message("Finished");
974+
assert_eq!(
975+
in_mem.contents(),
976+
r#" Finished downloa
977+
ding 435.96 KiB in 0
978+
s"#
979+
);
980+
981+
println!("{:?}", in_mem.contents())
982+
}
983+
984+
#[test]
985+
fn multi_progress_println_terminal_wrap() {
986+
let in_mem = InMemoryTerm::new(10, 48);
987+
let mp =
988+
MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(in_mem.clone())));
989+
990+
let pb1 = mp.add(ProgressBar::new(10));
991+
let pb2 = mp.add(ProgressBar::new(5));
992+
let pb3 = mp.add(ProgressBar::new(100));
993+
994+
assert_eq!(in_mem.contents(), "");
995+
996+
pb1.inc(2);
997+
mp.println("message printed that is longer than terminal width :)")
998+
.unwrap();
999+
assert_eq!(
1000+
in_mem.contents(),
1001+
r#"message printed that is longer than terminal wid
1002+
th :)
1003+
████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2/10"#
1004+
);
1005+
1006+
mp.println("another great message!").unwrap();
1007+
assert_eq!(
1008+
in_mem.contents(),
1009+
r#"message printed that is longer than terminal wid
1010+
th :)
1011+
another great message!
1012+
████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2/10"#
1013+
);
1014+
1015+
pb2.inc(1);
1016+
pb3.tick();
1017+
mp.println("one last message but this one is also longer than terminal width")
1018+
.unwrap();
1019+
1020+
assert_eq!(
1021+
in_mem.contents(),
1022+
r#"message printed that is longer than terminal wid
1023+
th :)
1024+
another great message!
1025+
one last message but this one is also longer tha
1026+
n terminal width
1027+
████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2/10
1028+
████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 1/5
1029+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/100"#
1030+
.trim()
1031+
);
1032+
1033+
drop(pb1);
1034+
drop(pb2);
1035+
drop(pb3);
1036+
1037+
assert_eq!(
1038+
in_mem.contents(),
1039+
r#"message printed that is longer than terminal wid
1040+
th :)
1041+
another great message!
1042+
one last message but this one is also longer tha
1043+
n terminal width"#
1044+
.trim()
1045+
);
1046+
}

0 commit comments

Comments
 (0)