| 1 | use super::*; |
| 2 | use ratatui::style::Modifier; |
| 3 | |
| 4 | fn seeded(area: Rect) -> Buffer { |
| 5 | let mut buffer = Buffer::empty(area); |
| 6 | for cell in &mut buffer.content { |
| 7 | cell.set_symbol("~").set_style( |
| 8 | Style::default() |
| 9 | .fg(Color::Yellow) |
| 10 | .bg(Color::Rgb(9, 23, 41)) |
| 11 | .add_modifier(Modifier::ITALIC | Modifier::REVERSED), |
| 12 | ); |
| 13 | } |
| 14 | buffer |
| 15 | } |
| 16 | |
| 17 | #[test] |
| 18 | fn packed_native_grid_clips_without_reflow_or_changing_transparent_cells() { |
| 19 | let full_area = Rect::new(3, 2, 18, 6); |
| 20 | let clipped = Rect::new(13, 2, 6, 6); |
| 21 | let grid = (0..90) |
| 22 | .map(|i| if i % 3 == 0 { 0 } else { (i + 1) as u8 }) |
| 23 | .collect::<Vec<_>>(); |
| 24 | let style = Style::default() |
| 25 | .fg(Color::Rgb(33, 87, 142)) |
| 26 | .add_modifier(Modifier::BOLD); |
| 27 | let mut full = seeded(Rect::new(0, 0, 25, 10)); |
| 28 | render_grid(full_area, &mut full, &grid, "m · 6", style); |
| 29 | let mut actual = seeded(clipped); |
| 30 | render_grid(full_area, &mut actual, &grid, "m · 6", style); |
| 31 | for y in clipped.y..clipped.bottom() { |
| 32 | for x in clipped.x..clipped.right() { |
| 33 | assert_eq!(actual[(x, y)], full[(x, y)], "cell=({x},{y})"); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 |