on 2158366 help sign in
helix/helix-tui/tests/widgets_block.rs
213 lines 6.0 kB history raw
1// use helix_tui::{
2// backend::TestBackend,
3// buffer::Buffer,
4// layout::Rect,
5// style::{Color, Style},
6// text::Span,
7// widgets::{Block, Borders},
8// Terminal,
9// };
11// #[test]
12// fn widgets_block_renders() {
13// let backend = TestBackend::new(10, 10);
14// let mut terminal = Terminal::new(backend).unwrap();
15// terminal
16// .draw(|f| {
17// let block = Block::default()
18// .title(Span::styled("Title", Style::default().fg(Color::LightBlue)))
19// .borders(Borders::ALL);
20// f.render_widget(
21// block,
22// Rect {
23// x: 0,
24// y: 0,
25// width: 8,
26// height: 8,
27// },
28// );
29// })
30// .unwrap();
31// let mut expected = Buffer::with_lines(vec![
32// "┌Title─┐ ",
33// "│ │ ",
34// "│ │ ",
35// "│ │ ",
36// "│ │ ",
37// "│ │ ",
38// "│ │ ",
39// "└──────┘ ",
40// " ",
41// " ",
42// ]);
43// for x in 1..=5 {
44// expected.get_mut(x, 0).set_fg(Color::LightBlue);
45// }
46// terminal.backend().assert_buffer(&expected);
47// }
49// #[test]
50// fn widgets_block_renders_on_small_areas() {
51// let test_case = |block, area: Rect, expected| {
52// let backend = TestBackend::new(area.width, area.height);
53// let mut terminal = Terminal::new(backend).unwrap();
54// terminal
55// .draw(|f| {
56// f.render_widget(block, area);
57// })
58// .unwrap();
59// terminal.backend().assert_buffer(&expected);
60// };
62// let one_cell_test_cases = [
63// (Borders::NONE, "T"),
64// (Borders::LEFT, "│"),
65// (Borders::TOP, "T"),
66// (Borders::RIGHT, "│"),
67// (Borders::BOTTOM, "T"),
68// (Borders::ALL, "┌"),
69// ];
70// for (borders, symbol) in one_cell_test_cases.iter().cloned() {
71// test_case(
72// Block::default().title("Test").borders(borders),
73// Rect {
74// x: 0,
75// y: 0,
76// width: 0,
77// height: 0,
78// },
79// Buffer::empty(Rect {
80// x: 0,
81// y: 0,
82// width: 0,
83// height: 0,
84// }),
85// );
86// test_case(
87// Block::default().title("Test").borders(borders),
88// Rect {
89// x: 0,
90// y: 0,
91// width: 1,
92// height: 0,
93// },
94// Buffer::empty(Rect {
95// x: 0,
96// y: 0,
97// width: 1,
98// height: 0,
99// }),
100// );
101// test_case(
102// Block::default().title("Test").borders(borders),
103// Rect {
104// x: 0,
105// y: 0,
106// width: 0,
107// height: 1,
108// },
109// Buffer::empty(Rect {
110// x: 0,
111// y: 0,
112// width: 0,
113// height: 1,
114// }),
115// );
116// test_case(
117// Block::default().title("Test").borders(borders),
118// Rect {
119// x: 0,
120// y: 0,
121// width: 1,
122// height: 1,
123// },
124// Buffer::with_lines(vec![symbol]),
125// );
126// }
127// test_case(
128// Block::default().title("Test").borders(Borders::LEFT),
129// Rect {
130// x: 0,
131// y: 0,
132// width: 4,
133// height: 1,
134// },
135// Buffer::with_lines(vec!["│Tes"]),
136// );
137// test_case(
138// Block::default().title("Test").borders(Borders::RIGHT),
139// Rect {
140// x: 0,
141// y: 0,
142// width: 4,
143// height: 1,
144// },
145// Buffer::with_lines(vec!["Tes│"]),
146// );
147// test_case(
148// Block::default().title("Test").borders(Borders::RIGHT),
149// Rect {
150// x: 0,
151// y: 0,
152// width: 4,
153// height: 1,
154// },
155// Buffer::with_lines(vec!["Tes│"]),
156// );
157// test_case(
158// Block::default()
159// .title("Test")
160// .borders(Borders::LEFT | Borders::RIGHT),
161// Rect {
162// x: 0,
163// y: 0,
164// width: 4,
165// height: 1,
166// },
167// Buffer::with_lines(vec!["│Te│"]),
168// );
169// test_case(
170// Block::default().title("Test").borders(Borders::TOP),
171// Rect {
172// x: 0,
173// y: 0,
174// width: 4,
175// height: 1,
176// },
177// Buffer::with_lines(vec!["Test"]),
178// );
179// test_case(
180// Block::default().title("Test").borders(Borders::TOP),
181// Rect {
182// x: 0,
183// y: 0,
184// width: 5,
185// height: 1,
186// },
187// Buffer::with_lines(vec!["Test─"]),
188// );
189// test_case(
190// Block::default()
191// .title("Test")
192// .borders(Borders::LEFT | Borders::TOP),
193// Rect {
194// x: 0,
195// y: 0,
196// width: 5,
197// height: 1,
198// },
199// Buffer::with_lines(vec!["┌Test"]),
200// );
201// test_case(
202// Block::default()
203// .title("Test")
204// .borders(Borders::LEFT | Borders::TOP),
205// Rect {
206// x: 0,
207// y: 0,
208// width: 6,
209// height: 1,
210// },
211// Buffer::with_lines(vec!["┌Test─"]),
212// );
213// }