mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 12:43:16 +00:00
refactor(tests): rename integration tests to be able to call group of tests
This commit is contained in:
parent
a00350ab54
commit
4fe647df0a
8 changed files with 25 additions and 29 deletions
|
@ -1,8 +1,10 @@
|
|||
use tui::backend::{Backend, TestBackend};
|
||||
use tui::Terminal;
|
||||
use tui::{
|
||||
backend::{Backend, TestBackend},
|
||||
Terminal,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn buffer_size_limited() {
|
||||
fn terminal_buffer_size_should_be_limited() {
|
||||
let backend = TestBackend::new(400, 400);
|
||||
let terminal = Terminal::new(backend).unwrap();
|
||||
let size = terminal.backend().size().unwrap();
|
|
@ -6,7 +6,7 @@ use tui::widgets::{Block, Borders};
|
|||
use tui::Terminal;
|
||||
|
||||
#[test]
|
||||
fn it_draws_a_block() {
|
||||
fn widgets_block_renders() {
|
||||
let backend = TestBackend::new(10, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
|
|
|
@ -8,7 +8,7 @@ use tui::{
|
|||
};
|
||||
|
||||
#[test]
|
||||
fn zero_axes_ok() {
|
||||
fn widgets_chart_can_have_axis_with_zero_length_bounds() {
|
||||
let backend = TestBackend::new(100, 100);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
|
@ -37,7 +37,7 @@ fn zero_axes_ok() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn handles_overflow() {
|
||||
fn widgets_chart_handles_overflows() {
|
||||
let backend = TestBackend::new(80, 30);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
|
@ -74,7 +74,7 @@ fn handles_overflow() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn empty_dataset_line_test() {
|
||||
fn widgets_chart_can_have_empty_datasets() {
|
||||
let backend = TestBackend::new(100, 100);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use tui::{
|
|||
};
|
||||
|
||||
#[test]
|
||||
fn gauge_render() {
|
||||
fn widgets_gauge_renders() {
|
||||
let backend = TestBackend::new(40, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
|
|
|
@ -9,7 +9,7 @@ use tui::{
|
|||
};
|
||||
|
||||
#[test]
|
||||
fn it_should_highlight_the_selected_item() {
|
||||
fn widgets_list_should_highlight_the_selected_item() {
|
||||
let backend = TestBackend::new(10, 3);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
let mut state = ListState::default();
|
||||
|
@ -32,24 +32,23 @@ fn it_should_highlight_the_selected_item() {
|
|||
for x in 0..9 {
|
||||
expected.get_mut(x, 1).set_bg(Color::Yellow);
|
||||
}
|
||||
assert_eq!(*terminal.backend().buffer(), expected);
|
||||
terminal.backend().assert_buffer(&expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_should_truncate_items() {
|
||||
fn widgets_list_should_truncate_items() {
|
||||
let backend = TestBackend::new(10, 2);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
struct TruncateTestCase<'a> {
|
||||
name: &'a str,
|
||||
selected: Option<usize>,
|
||||
items: Vec<Text<'a>>,
|
||||
expected: Buffer,
|
||||
}
|
||||
|
||||
let cases = vec![
|
||||
// An item is selected
|
||||
TruncateTestCase {
|
||||
name: "an item is selected",
|
||||
selected: Some(0),
|
||||
items: vec![Text::raw("A very long line"), Text::raw("A very long line")],
|
||||
expected: Buffer::with_lines(vec![
|
||||
|
@ -57,8 +56,8 @@ fn it_should_truncate_items() {
|
|||
format!(" A ve{} ", symbols::line::VERTICAL),
|
||||
]),
|
||||
},
|
||||
// No item is selected
|
||||
TruncateTestCase {
|
||||
name: "no item is selected",
|
||||
selected: None,
|
||||
items: vec![Text::raw("A very long line"), Text::raw("A very long line")],
|
||||
expected: Buffer::with_lines(vec![
|
||||
|
@ -79,11 +78,6 @@ fn it_should_truncate_items() {
|
|||
f.render_stateful_widget(list, Rect::new(0, 0, 8, 2), &mut state);
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
*terminal.backend().buffer(),
|
||||
case.expected,
|
||||
"Failed to assert the buffer matches the expected one when {}",
|
||||
case.name
|
||||
);
|
||||
terminal.backend().assert_buffer(&case.expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ const SAMPLE_STRING: &str = "The library is based on the principle of immediate
|
|||
interactive UI, this may introduce overhead for highly dynamic content.";
|
||||
|
||||
#[test]
|
||||
fn paragraph_render_wrap() {
|
||||
fn widgets_paragraph_can_wrap_its_content() {
|
||||
let test_case = |alignment, expected| {
|
||||
let backend = TestBackend::new(20, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
@ -79,7 +79,7 @@ fn paragraph_render_wrap() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_render_double_width() {
|
||||
fn widgets_paragraph_renders_double_width_graphemes() {
|
||||
let backend = TestBackend::new(10, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
|
@ -111,7 +111,7 @@ fn paragraph_render_double_width() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_render_mixed_width() {
|
||||
fn widgets_paragraph_renders_mixed_width_graphemes() {
|
||||
let backend = TestBackend::new(10, 7);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use tui::widgets::{Block, Borders, Row, Table};
|
|||
use tui::Terminal;
|
||||
|
||||
#[test]
|
||||
fn table_column_spacing() {
|
||||
fn widgets_table_column_spacing_can_be_changed() {
|
||||
let test_case = |column_spacing, expected| {
|
||||
let backend = TestBackend::new(30, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
@ -106,7 +106,7 @@ fn table_column_spacing() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn table_widths() {
|
||||
fn widgets_table_columns_widths_can_use_fixed_length_constraints() {
|
||||
let test_case = |widths, expected| {
|
||||
let backend = TestBackend::new(30, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
@ -197,7 +197,7 @@ fn table_widths() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn table_percentage_widths() {
|
||||
fn widgets_table_columns_widths_can_use_percentage_constraints() {
|
||||
let test_case = |widths, expected| {
|
||||
let backend = TestBackend::new(30, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
@ -306,7 +306,7 @@ fn table_percentage_widths() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn table_mixed_widths() {
|
||||
fn widgets_table_columns_widths_can_use_mixed_constraints() {
|
||||
let test_case = |widths, expected| {
|
||||
let backend = TestBackend::new(30, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use tui::{backend::TestBackend, buffer::Buffer, layout::Rect, symbols, widgets::Tabs, Terminal};
|
||||
|
||||
#[test]
|
||||
fn tabs_should_not_panic_on_narrow_areas() {
|
||||
fn widgets_tabs_should_not_panic_on_narrow_areas() {
|
||||
let backend = TestBackend::new(1, 1);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
|
@ -23,7 +23,7 @@ fn tabs_should_not_panic_on_narrow_areas() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn tabs_should_truncate_the_last_item() {
|
||||
fn widgets_tabs_should_truncate_the_last_item() {
|
||||
let backend = TestBackend::new(10, 1);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
|
|
Loading…
Reference in a new issue