test(Scrollbar): port test 🚨

This commit is contained in:
Dheepak Krishnamurthy 2024-01-19 16:41:05 -05:00
parent 61e3ab5f99
commit 13de3daf73
No known key found for this signature in database
GPG key ID: 602B439E509219ED

View file

@ -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]