refactor: remove Axis::Unassigned; axis_of returns Option<Axis>
Axis::Unassigned served two purposes that Option already covers:
1. "this category has no assignment yet" → None
2. "this category doesn't exist" → None
By removing the variant and changing axis_of to return Option<Axis>,
callers are forced by the compiler to handle the absent-category case
explicitly (via match or unwrap_or), rather than silently treating it
like a real axis value.
SetAxis { axis: String } also upgraded to SetAxis { axis: Axis }.
Previously, constructing SetAxis with an invalid string (e.g. "diagonal")
would compile and then silently fail at dispatch. Now the type only admits
valid axis values; the dispatch string-parser is gone.
Axis gains #[serde(rename_all = "lowercase")] so existing JSON command
files (smoke.jsonl, etc.) using "row"/"column"/"page" continue to work.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -322,7 +322,7 @@ mod model_tests {
|
||||
fn add_category_notifies_existing_views() {
|
||||
let mut m = Model::new("Test");
|
||||
m.add_category("Region").unwrap();
|
||||
assert_ne!(m.active_view().unwrap().axis_of("Region"), Axis::Unassigned);
|
||||
assert_ne!(m.active_view().unwrap().axis_of("Region"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -378,8 +378,8 @@ mod model_tests {
|
||||
m.add_category("Product").unwrap();
|
||||
m.create_view("Secondary");
|
||||
let v = m.views.get("Secondary").unwrap();
|
||||
assert_ne!(v.axis_of("Region"), Axis::Unassigned);
|
||||
assert_ne!(v.axis_of("Product"), Axis::Unassigned);
|
||||
assert_ne!(v.axis_of("Region"), None);
|
||||
assert_ne!(v.axis_of("Product"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -426,9 +426,9 @@ mod model_tests {
|
||||
m.add_category("Product").unwrap();
|
||||
m.add_category("Time").unwrap();
|
||||
let v = m.active_view().unwrap();
|
||||
assert_eq!(v.axis_of("Region"), Axis::Row);
|
||||
assert_eq!(v.axis_of("Product"), Axis::Column);
|
||||
assert_eq!(v.axis_of("Time"), Axis::Page);
|
||||
assert_eq!(v.axis_of("Region"), Some(Axis::Row));
|
||||
assert_eq!(v.axis_of("Product"), Some(Axis::Column));
|
||||
assert_eq!(v.axis_of("Time"), Some(Axis::Page));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -968,11 +968,11 @@ mod five_category {
|
||||
fn default_view_first_two_on_axes_rest_on_page() {
|
||||
let m = build_model();
|
||||
let v = m.active_view().unwrap();
|
||||
assert_eq!(v.axis_of("Region"), Axis::Row);
|
||||
assert_eq!(v.axis_of("Product"), Axis::Column);
|
||||
assert_eq!(v.axis_of("Channel"), Axis::Page);
|
||||
assert_eq!(v.axis_of("Time"), Axis::Page);
|
||||
assert_eq!(v.axis_of("Measure"), Axis::Page);
|
||||
assert_eq!(v.axis_of("Region"), Some(Axis::Row));
|
||||
assert_eq!(v.axis_of("Product"), Some(Axis::Column));
|
||||
assert_eq!(v.axis_of("Channel"), Some(Axis::Page));
|
||||
assert_eq!(v.axis_of("Time"), Some(Axis::Page));
|
||||
assert_eq!(v.axis_of("Measure"), Some(Axis::Page));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -999,9 +999,9 @@ mod five_category {
|
||||
v.set_axis("Product", Axis::Page);
|
||||
v.set_axis("Measure", Axis::Page);
|
||||
}
|
||||
assert_eq!(m.views.get("Default").unwrap().axis_of("Region"), Axis::Row);
|
||||
assert_eq!(m.views.get("Pivot").unwrap().axis_of("Time"), Axis::Row);
|
||||
assert_eq!(m.views.get("Pivot").unwrap().axis_of("Channel"), Axis::Column);
|
||||
assert_eq!(m.views.get("Default").unwrap().axis_of("Region"), Some(Axis::Row));
|
||||
assert_eq!(m.views.get("Pivot").unwrap().axis_of("Time"), Some(Axis::Row));
|
||||
assert_eq!(m.views.get("Pivot").unwrap().axis_of("Channel"), Some(Axis::Column));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user