| 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_cameo_and_world_buffers_match_frozen_painter() { |
| 19 | let styles = [ |
| 20 | Style::default(), |
| 21 | Style::default().fg(Color::Rgb(21, 71, 129)), |
| 22 | Style::default() |
| 23 | .fg(Color::Cyan) |
| 24 | .bg(Color::Rgb(17, 19, 31)) |
| 25 | .add_modifier(Modifier::BOLD | Modifier::UNDERLINED), |
| 26 | ]; |
| 27 | for width in 0..=32 { |
| 28 | for height in 0..=12 { |
| 29 | let area = Rect::new(4, 3, width, height); |
| 30 | for label in [ |
| 31 | "m · 6", |
| 32 | "resting", |
| 33 | "鲸 · cafe\u{0301}", |
| 34 | "a cue wider than this viewport", |
| 35 | ] { |
| 36 | for &style in &styles { |
| 37 | // Includes the actual 18×5 cameo, transparent cells, and |
| 38 | // short/extra grids the shared embedded-world facade accepts. |
| 39 | let grid = (0..90) |
| 40 | .map(|i| if i % 4 == 0 { 0 } else { (i % 255 + 1) as u8 }) |
| 41 | .collect::<Vec<_>>(); |
| 42 | for cells in [&grid[..], &grid[..7], &[][..]] { |
| 43 | let mut actual = seeded(Rect::new(1, 1, 40, 18)); |
| 44 | let mut expected = actual.clone(); |
| 45 | super::pet_widget_legacy::render_grid( |
| 46 | area, |
| 47 | &mut expected, |
| 48 | cells, |
| 49 | label, |
| 50 | style, |
| 51 | ); |
| 52 | render_grid(area, &mut actual, cells, label, style); |
| 53 | assert_eq!( |
| 54 | actual, |
| 55 | expected, |
| 56 | "area={area:?} label={label:?} style={style:?} cells={}", |
| 57 | cells.len() |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn packed_native_grid_clips_without_reflow_or_changing_transparent_cells() { |
| 68 | let full_area = Rect::new(3, 2, 18, 6); |
| 69 | let clipped = Rect::new(13, 2, 6, 6); |
| 70 | let grid = (0..90) |
| 71 | .map(|i| if i % 3 == 0 { 0 } else { (i + 1) as u8 }) |
| 72 | .collect::<Vec<_>>(); |
| 73 | let style = Style::default() |
| 74 | .fg(Color::Rgb(33, 87, 142)) |
| 75 | .add_modifier(Modifier::BOLD); |
| 76 | let mut full = seeded(Rect::new(0, 0, 25, 10)); |
| 77 | render_grid(full_area, &mut full, &grid, "m · 6", style); |
| 78 | let mut actual = seeded(clipped); |
| 79 | render_grid(full_area, &mut actual, &grid, "m · 6", style); |
| 80 | for y in clipped.y..clipped.bottom() { |
| 81 | for x in clipped.x..clipped.right() { |
| 82 | assert_eq!(actual[(x, y)], full[(x, y)], "cell=({x},{y})"); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 |