Skip to content

Commit f3b522b

Browse files
committed
test: add insta tests for OutputWidget highlighting and navigation
1 parent e0ccd6d commit f3b522b

7 files changed

Lines changed: 134 additions & 0 deletions

src/output_widget.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,56 @@ mod tests {
569569
assert_snapshot!("scroll up page", terminal.backend());
570570
}
571571

572+
#[test]
573+
fn highlighting() {
574+
let mut terminal = Terminal::new(TestBackend::new(20, 10)).unwrap();
575+
576+
let mut widget = OutputWidget::default();
577+
578+
widget.handle_command_output(Output::ok_stdin(&generate_lines(50)));
579+
terminal
580+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
581+
.unwrap();
582+
assert_snapshot!("highlight base", terminal.backend());
583+
584+
widget.highlight("line2", false);
585+
terminal
586+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
587+
.unwrap();
588+
assert_snapshot!("highlight", terminal.backend());
589+
590+
widget.highlight_next();
591+
widget.highlight_next();
592+
widget.highlight_next();
593+
widget.highlight_next();
594+
terminal
595+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
596+
.unwrap();
597+
assert_snapshot!("highlight next 4x", terminal.backend());
598+
599+
// in visible area - should not move offset
600+
widget.highlight_next();
601+
terminal
602+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
603+
.unwrap();
604+
assert_snapshot!("highlight next 1x", terminal.backend());
605+
606+
widget.highlight_prev();
607+
widget.highlight_prev();
608+
widget.highlight_prev();
609+
widget.highlight_prev();
610+
terminal
611+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
612+
.unwrap();
613+
assert_snapshot!("highlight prev 4x", terminal.backend());
614+
615+
widget.highlight("line50", false);
616+
terminal
617+
.draw(|frame| widget.render(frame.area(), frame.buffer_mut()))
618+
.unwrap();
619+
assert_snapshot!("highlight another highlight", terminal.backend());
620+
}
621+
572622
#[test]
573623
fn split_line_into_parts_by_ranges_test() {
574624
let str = "01234567890123456789";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
"45 line45 ▲"
6+
"46 line46 ║"
7+
"47 line47 ║"
8+
"48 line48 ║"
9+
"49 line49 ║"
10+
"50 line50 ║"
11+
""
12+
""
13+
""
14+
""
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
" 1 line1 ▲"
6+
" 2 line2 █"
7+
" 3 line3 █"
8+
" 4 line4 ║"
9+
" 5 line5 ║"
10+
" 6 line6 ║"
11+
" 7 line7 ║"
12+
" 8 line8 ║"
13+
" 9 line9 ║"
14+
"10 line10 ▼"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
"18 line18 ▲"
6+
"19 line19 ║"
7+
"20 line20 ║"
8+
"21 line21 ║"
9+
"22 line22 █"
10+
"23 line23 ║"
11+
"24 line24 ║"
12+
"25 line25 ║"
13+
"26 line26 ║"
14+
"27 line27 ▼"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
"18 line18 ▲"
6+
"19 line19 ║"
7+
"20 line20 ║"
8+
"21 line21 ║"
9+
"22 line22 █"
10+
"23 line23 ║"
11+
"24 line24 ║"
12+
"25 line25 ║"
13+
"26 line26 ║"
14+
"27 line27 ▼"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
"18 line18 ▲"
6+
"19 line19 ║"
7+
"20 line20 ║"
8+
"21 line21 ║"
9+
"22 line22 █"
10+
"23 line23 ║"
11+
"24 line24 ║"
12+
"25 line25 ║"
13+
"26 line26 ║"
14+
"27 line27 ▼"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/output_widget.rs
3+
expression: terminal.backend()
4+
---
5+
" 1 line1 ▲"
6+
" 2 line2 █"
7+
" 3 line3 █"
8+
" 4 line4 ║"
9+
" 5 line5 ║"
10+
" 6 line6 ║"
11+
" 7 line7 ║"
12+
" 8 line8 ║"
13+
" 9 line9 ║"
14+
"10 line10 ▼"

0 commit comments

Comments
 (0)