mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 12:43:16 +00:00
5498a889ae
The `Spans` type (plural, not singular) was replaced with a more ergonomic `Line` type in Ratatui v0.21.0 and marked deprecated byt left for backwards compatibility. This is now removed. - `Line` replaces `Spans` - `Buffer::set_line` replaces `Buffer::set_spans`
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use ratatui::{
|
|
backend::TestBackend, buffer::Buffer, layout::Rect, symbols, text::Line, widgets::Tabs,
|
|
Terminal,
|
|
};
|
|
|
|
#[test]
|
|
fn widgets_tabs_should_not_panic_on_narrow_areas() {
|
|
let backend = TestBackend::new(1, 1);
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
terminal
|
|
.draw(|f| {
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::from).collect());
|
|
f.render_widget(
|
|
tabs,
|
|
Rect {
|
|
x: 0,
|
|
y: 0,
|
|
width: 1,
|
|
height: 1,
|
|
},
|
|
);
|
|
})
|
|
.unwrap();
|
|
let expected = Buffer::with_lines(vec![" "]);
|
|
terminal.backend().assert_buffer(&expected);
|
|
}
|
|
|
|
#[test]
|
|
fn widgets_tabs_should_truncate_the_last_item() {
|
|
let backend = TestBackend::new(10, 1);
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
terminal
|
|
.draw(|f| {
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::from).collect());
|
|
f.render_widget(
|
|
tabs,
|
|
Rect {
|
|
x: 0,
|
|
y: 0,
|
|
width: 9,
|
|
height: 1,
|
|
},
|
|
);
|
|
})
|
|
.unwrap();
|
|
let expected = Buffer::with_lines(vec![format!(" Tab1 {} T ", symbols::line::VERTICAL)]);
|
|
terminal.backend().assert_buffer(&expected);
|
|
}
|