Skip to content

Commit fbbb28a

Browse files
committed
test(render/grid_table): cover the inline layout honouring right alignment so content sits flush against the right edge with leading padding, and render's defence-in-depth guard drawing nothing instead of panicking when handed a non-Entries body directly
1 parent ebfe8ee commit fbbb28a

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

‎src/render/grid_table.rs‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ fn to_row<'a>(item: &'a Entry, aligns: [Alignment; 2], theme: &Theme) -> Row<'a>
183183

184184
#[cfg(test)]
185185
mod tests {
186+
use ratatui::{Terminal, backend::TestBackend};
187+
186188
use super::*;
187-
use crate::payload::{EntriesData, Entry, Payload, Status};
189+
use crate::payload::{EntriesData, Entry, Payload, Status, TextData};
188190
use crate::render::test_utils::{line_text, render_to_buffer, render_to_buffer_with_spec};
189191
use crate::render::{Registry, RenderSpec};
190192

@@ -237,4 +239,51 @@ mod tests {
237239
assert!(row.contains("license: MIT"), "row: {row:?}");
238240
assert!(row.contains('·'), "separator missing: {row:?}");
239241
}
242+
243+
#[test]
244+
fn inline_layout_honours_right_alignment() {
245+
let registry = Registry::with_builtins();
246+
#[derive(serde::Deserialize)]
247+
struct W {
248+
render: RenderSpec,
249+
}
250+
let w: W = toml::from_str(
251+
r#"render = { type = "grid_table", layout = "inline", align = "right" }"#,
252+
)
253+
.unwrap();
254+
let p = payload(vec![Entry {
255+
key: "stars".into(),
256+
value: Some("1.2k".into()),
257+
status: None,
258+
}]);
259+
let buf = render_to_buffer_with_spec(&p, Some(&w.render), &registry, 60, 1);
260+
let row = line_text(&buf, 0);
261+
// Right-aligned: content sits flush against the right edge, leaving leading padding.
262+
assert!(row.starts_with(' '), "expected leading padding: {row:?}");
263+
assert!(row.ends_with("stars: 1.2k"), "row: {row:?}");
264+
}
265+
266+
#[test]
267+
fn render_ignores_a_non_entries_body() {
268+
// The runtime guards shape mismatches upstream, but the renderer must also no-op
269+
// gracefully (not panic) if a non-`Entries` body reaches it directly.
270+
let mut terminal = Terminal::new(TestBackend::new(20, 3)).unwrap();
271+
let theme = Theme::default();
272+
let registry = Registry::with_builtins();
273+
let opts = RenderOptions::default();
274+
let body = Body::Text(TextData {
275+
value: "ignored".into(),
276+
});
277+
terminal
278+
.draw(|f| {
279+
let area = f.area();
280+
GridTableRenderer.render(f, area, &body, &opts, &theme, &registry);
281+
})
282+
.unwrap();
283+
let buf = terminal.backend().buffer().clone();
284+
assert!(
285+
line_text(&buf, 0).trim().is_empty(),
286+
"non-entries body should draw nothing",
287+
);
288+
}
240289
}

0 commit comments

Comments
 (0)