Prevent partial widget being written to prerender cache

This commit is contained in:
2023-11-05 10:02:19 +01:00
parent 2145aff76f
commit 90e86724df
3 changed files with 144 additions and 3 deletions

View File

@ -342,3 +342,140 @@ fn test_cache_moved() {
]);
assert_eq!(buf, expected);
}
#[test]
fn test_overflow_and_scroll() {
let mut bl = Backlog::default();
let prerender1 = Prerender::new();
let prerender2 = Prerender::new();
let prerender3 = Prerender::new();
let item1 = BufferItem {
text: Text::raw("line1 x"),
prerender: &prerender1,
};
let item2 = BufferItem {
text: Text::raw("line2 y\nline3 y\nline4 y"),
prerender: &prerender2,
};
let item3 = BufferItem {
text: Text::raw("line5 z"),
prerender: &prerender3,
};
let mut buf = Buffer::empty(rect(0, 0, 14, 7));
bl.draw_items(
&mut buf,
rect(1, 1, 12, 5),
vec![item3, item2, item1].into_iter(),
)
.context("Failed to draw")
.unwrap();
let expected = Buffer::with_lines(vec![
" ",
" ┌──────────┐ ",
" │line3 y │ ",
" │line4 y │ ",
" │line5 z │ ",
" └──────────┘ ",
" ",
]);
assert_eq!(buf, expected);
bl.scroll_up(1);
let item1 = BufferItem {
text: Text::raw("line1 x"),
prerender: &prerender1,
};
let item2 = BufferItem {
text: Text::raw("line2 y\nline3 y\nline4 y"),
prerender: &prerender2,
};
let item3 = BufferItem {
text: Text::raw("line5 z"),
prerender: &prerender3,
};
let mut buf = Buffer::empty(rect(0, 0, 14, 7));
bl.draw_items(
&mut buf,
rect(1, 1, 12, 5),
vec![item3, item2, item1].into_iter(),
)
.context("Failed to draw")
.unwrap();
let expected = Buffer::with_lines(vec![
" ",
" ┌──────────┐ ",
" │line2 y │ ",
" │line3 y │ ",
" │line4 y │ ",
" └──────────┘ ",
" ",
]);
assert_eq!(buf, expected);
bl.scroll_up(1);
let item1 = BufferItem {
text: Text::raw("line1 x"),
prerender: &prerender1,
};
let item2 = BufferItem {
text: Text::raw("line2 y\nline3 y\nline4 y"),
prerender: &prerender2,
};
let item3 = BufferItem {
text: Text::raw("line5 z"),
prerender: &prerender3,
};
let mut buf = Buffer::empty(rect(0, 0, 14, 7));
bl.draw_items(
&mut buf,
rect(1, 1, 12, 5),
vec![item3, item2, item1].into_iter(),
)
.context("Failed to draw")
.unwrap();
let expected = Buffer::with_lines(vec![
" ",
" ┌──────────┐ ",
" │line1 x │ ",
" │line2 y │ ",
" │line3 y │ ",
" └──────────┘ ",
" ",
]);
assert_eq!(buf, expected);
bl.scroll_up(1);
let item1 = BufferItem {
text: Text::raw("line1 x"),
prerender: &prerender1,
};
let item2 = BufferItem {
text: Text::raw("line2 y\nline3 y\nline4 y"),
prerender: &prerender2,
};
let item3 = BufferItem {
text: Text::raw("line5 z"),
prerender: &prerender3,
};
let mut buf = Buffer::empty(rect(0, 0, 14, 7));
bl.draw_items(
&mut buf,
rect(1, 1, 12, 5),
vec![item3, item2, item1].into_iter(),
)
.context("Failed to draw")
.unwrap();
let expected = Buffer::with_lines(vec![
" ",
" ┌──────────┐ ",
" │ │ ",
" │line1 x │ ",
" │line2 y │ ",
" └──────────┘ ",
" ",
]);
assert_eq!(buf, expected);
}