mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-21 20:23:11 +00:00
test(Scrollbar): port test 🚨
This commit is contained in:
parent
61e3ab5f99
commit
13de3daf73
1 changed files with 24 additions and 19 deletions
|
@ -708,29 +708,34 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[rstest]
|
||||||
fn test_renders_empty_with_content_length_is_zero() {
|
#[case(" ", 0)]
|
||||||
let mut buffer = Buffer::empty(Rect::new(0, 0, 2, 8));
|
#[case("████████", 1)]
|
||||||
let mut state = ScrollbarState::default().position(0);
|
#[case("████████", 2)]
|
||||||
|
#[case("████████", 3)]
|
||||||
|
#[case("████████", 4)]
|
||||||
|
#[case("████████", 5)]
|
||||||
|
#[case("████████", 6)]
|
||||||
|
#[case("████████", 7)]
|
||||||
|
#[case("████████", 8)]
|
||||||
|
fn test_renders_empty_with_content_length_is_zero(
|
||||||
|
#[case] expected: &str,
|
||||||
|
#[case] content_length: usize,
|
||||||
|
) {
|
||||||
|
let size = expected.width();
|
||||||
|
let mut buffer = Buffer::empty(Rect::new(0, 0, 2, size as u16));
|
||||||
|
let mut state = ScrollbarState::new(content_length).position(0);
|
||||||
Scrollbar::default()
|
Scrollbar::default()
|
||||||
.begin_symbol(None)
|
.begin_symbol(None)
|
||||||
.end_symbol(None)
|
.end_symbol(None)
|
||||||
.render(buffer.area, &mut buffer, &mut state);
|
.render(buffer.area, &mut buffer, &mut state);
|
||||||
assert_buffer_eq!(
|
let empty_string: String = " ".repeat(size);
|
||||||
buffer,
|
let bar = empty_string
|
||||||
Buffer::with_lines(vec![" ", " ", " ", " ", " ", " ", " ", " "])
|
.chars()
|
||||||
);
|
.zip(expected.chars())
|
||||||
|
.map(|(a, b)| format!("{a}{b}"))
|
||||||
let mut buffer = Buffer::empty(Rect::new(0, 0, 2, 8));
|
.collect_vec();
|
||||||
let mut state = ScrollbarState::new(8).position(0);
|
assert_buffer_eq!(buffer, Buffer::with_lines(bar));
|
||||||
Scrollbar::default()
|
|
||||||
.begin_symbol(None)
|
|
||||||
.end_symbol(None)
|
|
||||||
.render(buffer.area, &mut buffer, &mut state);
|
|
||||||
assert_buffer_eq!(
|
|
||||||
buffer,
|
|
||||||
Buffer::with_lines(vec![" █", " █", " █", " █", " █", " █", " █", " █"])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue