refactor(tests): rename integration tests to be able to call group of tests

This commit is contained in:
Florian Dehau 2020-05-21 20:42:34 +02:00
parent a00350ab54
commit 4fe647df0a
8 changed files with 25 additions and 29 deletions

View file

@ -1,8 +1,10 @@
use tui::backend::{Backend, TestBackend}; use tui::{
use tui::Terminal; backend::{Backend, TestBackend},
Terminal,
};
#[test] #[test]
fn buffer_size_limited() { fn terminal_buffer_size_should_be_limited() {
let backend = TestBackend::new(400, 400); let backend = TestBackend::new(400, 400);
let terminal = Terminal::new(backend).unwrap(); let terminal = Terminal::new(backend).unwrap();
let size = terminal.backend().size().unwrap(); let size = terminal.backend().size().unwrap();

View file

@ -6,7 +6,7 @@ use tui::widgets::{Block, Borders};
use tui::Terminal; use tui::Terminal;
#[test] #[test]
fn it_draws_a_block() { fn widgets_block_renders() {
let backend = TestBackend::new(10, 10); let backend = TestBackend::new(10, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
terminal terminal

View file

@ -8,7 +8,7 @@ use tui::{
}; };
#[test] #[test]
fn zero_axes_ok() { fn widgets_chart_can_have_axis_with_zero_length_bounds() {
let backend = TestBackend::new(100, 100); let backend = TestBackend::new(100, 100);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -37,7 +37,7 @@ fn zero_axes_ok() {
} }
#[test] #[test]
fn handles_overflow() { fn widgets_chart_handles_overflows() {
let backend = TestBackend::new(80, 30); let backend = TestBackend::new(80, 30);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -74,7 +74,7 @@ fn handles_overflow() {
} }
#[test] #[test]
fn empty_dataset_line_test() { fn widgets_chart_can_have_empty_datasets() {
let backend = TestBackend::new(100, 100); let backend = TestBackend::new(100, 100);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();

View file

@ -7,7 +7,7 @@ use tui::{
}; };
#[test] #[test]
fn gauge_render() { fn widgets_gauge_renders() {
let backend = TestBackend::new(40, 10); let backend = TestBackend::new(40, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
terminal terminal

View file

@ -9,7 +9,7 @@ use tui::{
}; };
#[test] #[test]
fn it_should_highlight_the_selected_item() { fn widgets_list_should_highlight_the_selected_item() {
let backend = TestBackend::new(10, 3); let backend = TestBackend::new(10, 3);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
let mut state = ListState::default(); let mut state = ListState::default();
@ -32,24 +32,23 @@ fn it_should_highlight_the_selected_item() {
for x in 0..9 { for x in 0..9 {
expected.get_mut(x, 1).set_bg(Color::Yellow); expected.get_mut(x, 1).set_bg(Color::Yellow);
} }
assert_eq!(*terminal.backend().buffer(), expected); terminal.backend().assert_buffer(&expected);
} }
#[test] #[test]
fn it_should_truncate_items() { fn widgets_list_should_truncate_items() {
let backend = TestBackend::new(10, 2); let backend = TestBackend::new(10, 2);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
struct TruncateTestCase<'a> { struct TruncateTestCase<'a> {
name: &'a str,
selected: Option<usize>, selected: Option<usize>,
items: Vec<Text<'a>>, items: Vec<Text<'a>>,
expected: Buffer, expected: Buffer,
} }
let cases = vec![ let cases = vec![
// An item is selected
TruncateTestCase { TruncateTestCase {
name: "an item is selected",
selected: Some(0), selected: Some(0),
items: vec![Text::raw("A very long line"), Text::raw("A very long line")], items: vec![Text::raw("A very long line"), Text::raw("A very long line")],
expected: Buffer::with_lines(vec![ expected: Buffer::with_lines(vec![
@ -57,8 +56,8 @@ fn it_should_truncate_items() {
format!(" A ve{} ", symbols::line::VERTICAL), format!(" A ve{} ", symbols::line::VERTICAL),
]), ]),
}, },
// No item is selected
TruncateTestCase { TruncateTestCase {
name: "no item is selected",
selected: None, selected: None,
items: vec![Text::raw("A very long line"), Text::raw("A very long line")], items: vec![Text::raw("A very long line"), Text::raw("A very long line")],
expected: Buffer::with_lines(vec![ 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); f.render_stateful_widget(list, Rect::new(0, 0, 8, 2), &mut state);
}) })
.unwrap(); .unwrap();
assert_eq!( terminal.backend().assert_buffer(&case.expected);
*terminal.backend().buffer(),
case.expected,
"Failed to assert the buffer matches the expected one when {}",
case.name
);
} }
} }

View file

@ -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."; interactive UI, this may introduce overhead for highly dynamic content.";
#[test] #[test]
fn paragraph_render_wrap() { fn widgets_paragraph_can_wrap_its_content() {
let test_case = |alignment, expected| { let test_case = |alignment, expected| {
let backend = TestBackend::new(20, 10); let backend = TestBackend::new(20, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -79,7 +79,7 @@ fn paragraph_render_wrap() {
} }
#[test] #[test]
fn paragraph_render_double_width() { fn widgets_paragraph_renders_double_width_graphemes() {
let backend = TestBackend::new(10, 10); let backend = TestBackend::new(10, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -111,7 +111,7 @@ fn paragraph_render_double_width() {
} }
#[test] #[test]
fn paragraph_render_mixed_width() { fn widgets_paragraph_renders_mixed_width_graphemes() {
let backend = TestBackend::new(10, 7); let backend = TestBackend::new(10, 7);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();

View file

@ -5,7 +5,7 @@ use tui::widgets::{Block, Borders, Row, Table};
use tui::Terminal; use tui::Terminal;
#[test] #[test]
fn table_column_spacing() { fn widgets_table_column_spacing_can_be_changed() {
let test_case = |column_spacing, expected| { let test_case = |column_spacing, expected| {
let backend = TestBackend::new(30, 10); let backend = TestBackend::new(30, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -106,7 +106,7 @@ fn table_column_spacing() {
} }
#[test] #[test]
fn table_widths() { fn widgets_table_columns_widths_can_use_fixed_length_constraints() {
let test_case = |widths, expected| { let test_case = |widths, expected| {
let backend = TestBackend::new(30, 10); let backend = TestBackend::new(30, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -197,7 +197,7 @@ fn table_widths() {
} }
#[test] #[test]
fn table_percentage_widths() { fn widgets_table_columns_widths_can_use_percentage_constraints() {
let test_case = |widths, expected| { let test_case = |widths, expected| {
let backend = TestBackend::new(30, 10); let backend = TestBackend::new(30, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
@ -306,7 +306,7 @@ fn table_percentage_widths() {
} }
#[test] #[test]
fn table_mixed_widths() { fn widgets_table_columns_widths_can_use_mixed_constraints() {
let test_case = |widths, expected| { let test_case = |widths, expected| {
let backend = TestBackend::new(30, 10); let backend = TestBackend::new(30, 10);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();

View file

@ -1,7 +1,7 @@
use tui::{backend::TestBackend, buffer::Buffer, layout::Rect, symbols, widgets::Tabs, Terminal}; use tui::{backend::TestBackend, buffer::Buffer, layout::Rect, symbols, widgets::Tabs, Terminal};
#[test] #[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 backend = TestBackend::new(1, 1);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
terminal terminal
@ -23,7 +23,7 @@ fn tabs_should_not_panic_on_narrow_areas() {
} }
#[test] #[test]
fn tabs_should_truncate_the_last_item() { fn widgets_tabs_should_truncate_the_last_item() {
let backend = TestBackend::new(10, 1); let backend = TestBackend::new(10, 1);
let mut terminal = Terminal::new(backend).unwrap(); let mut terminal = Terminal::new(backend).unwrap();
terminal terminal