fix(core): improve view robustness and axis management

`records_display` now returns `None` for out-of-bounds columns.

Added `try_axis_of` to `View` for non-panicking axis retrieval.

`cycle_axis` now uses `try_axis_of` to avoid panicking on unknown
categories.

Add regression tests for out-of-bounds access and unknown category cycling.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
Edward Langley
2026-06-09 21:43:13 -07:00
parent 45bfe2c4c7
commit f04fe517ae
2 changed files with 79 additions and 15 deletions
+22 -1
View File
@@ -182,11 +182,15 @@ impl GridLayout {
}
/// Get the display string for the cell at (row, col) in records mode.
/// Returns None for normal (non-records) layouts.
/// Returns None for normal (non-records) layouts and for out-of-bounds
/// rows/columns (symmetric with `cell_key`).
pub fn records_display(&self, row: usize, col: usize) -> Option<String> {
let records = self.records.as_ref()?;
let record = records.get(row)?;
let col_item = self.col_label(col);
if col_item.is_empty() {
return None;
}
if col_item == "Value" {
Some(record.1.to_string())
} else {
@@ -806,6 +810,23 @@ mod tests {
assert_eq!(last_value, "999", "new record should be the last row");
}
/// Regression test for improvise-byz: `records_display` for an
/// out-of-bounds column called `col_label(col)`, which returns `""`;
/// `""` fails the `== "Value"` check, gets looked up as a category name
/// in the record (never found), and the function returned `Some("")` —
/// masking view/data mismatches. It must return `None`, symmetric with
/// `cell_key`, which explicitly returns `None` for an empty col label.
#[test]
fn records_display_out_of_bounds_col_returns_none() {
let mut wb = records_workbook();
let v = wb.active_view_mut();
v.set_axis("_Index", Axis::Row);
v.set_axis("_Dim", Axis::Column);
let layout = GridLayout::new(&wb.model, wb.active_view());
assert!(layout.is_records_mode());
assert_eq!(layout.records_display(0, layout.col_count()), None);
}
fn coord(pairs: &[(&str, &str)]) -> CellKey {
CellKey::new(
pairs