diff --git a/crates/improvise-command/src/command/cmd/registry.rs b/crates/improvise-command/src/command/cmd/registry.rs index d9f1d47a..e8f8e04d 100644 --- a/crates/improvise-command/src/command/cmd/registry.rs +++ b/crates/improvise-command/src/command/cmd/registry.rs @@ -573,6 +573,9 @@ mod tests { vec!["1", "1"], vec!["formula", "1"], vec!["editing", "5", "Region", "East"], + vec!["editing", "5", "Region/East"], + vec!["formula", "false", "false"], + vec!["Region/East"], ] .into_iter() .map(|v| v.into_iter().map(String::from).collect()) @@ -734,6 +737,62 @@ mod tests { "only {checked} ex-command examples were found; the scan has stopped seeing them" ); } + + /// Evidence: `context/test-evidence/cli.md`. + #[test] + fn commit_cell_edit_honours_an_explicit_value_and_cell_over_the_cursor() { + let mut app = crate::ui::app::App::new(two_cat_model(), None); + app.view_state + .buffers + .insert("edit".into(), "decoy".into()); + let ctx = app.cmd_context( + crate::command::key::KeyCode::Null, + crate::command::key::KeyModifiers::NONE, + ); + let target = CellKey::new(vec![ + ("Month".into(), "Feb".into()), + ("Type".into(), "Clothing".into()), + ]); + assert_ne!(ctx.cell_key().as_ref(), Some(&target), "the cursor is elsewhere"); + let args: Vec = ["editing", "5", "Type/Clothing", "Month/Feb"] + .map(String::from) + .into(); + let dbg = format!( + "{:?}", + ctx.registry + .interactive("commit-cell-edit", &args, &ctx) + .expect("commit-cell-edit resolves") + ); + assert!(dbg.contains(&format!("key: {target:?}")), "wrong cell: {dbg}"); + assert!(dbg.contains("value: \"5\""), "wrong value: {dbg}"); + } + + /// Evidence: `context/test-evidence/cli.md`. + #[test] + fn every_argument_list_the_gate_accepts_the_run_accepts_too() { + let r = default_registry(); + let mut wb = crate::workbook::Workbook::new("Empty"); + wb.add_category("Foo").expect("a category with no items"); + let app = crate::ui::app::App::new(wb, None); + let ctx = app.cmd_context( + crate::command::key::KeyCode::Null, + crate::command::key::KeyModifiers::NONE, + ); + assert!(ctx.cell_key().is_none(), "the cursor must sit on no cell"); + let mut accepted = 0; + for name in r.names().collect::>() { + for args in candidate_args() { + if r.parse(name, &args).is_err() { + continue; + } + accepted += 1; + if let Err(e) = r.interactive(name, &args, &ctx) { + panic!("the gate accepts `{name} {args:?}` but the run refuses it: {e}"); + } + } + } + assert!(accepted > 50, "only {accepted} accepted pairs were tried"); + } } #[cfg(test)] @@ -839,4 +898,29 @@ mod panel_open_tests { ); } } + + /// Evidence: `context/test-evidence/cli.md`. + #[test] + fn explicit_open_and_focus_arguments_beat_the_toggle() { + for panel in Panel::ALL { + let mut app = App::new(two_cat_model(), None); + app.view_state.formula_panel_open = false; + app.view_state.category_panel_open = false; + app.view_state.view_panel_open = false; + let ctx = app.cmd_context(KeyCode::Null, KeyModifiers::NONE); + let args = [panel.name().to_string(), "false".into(), "false".into()]; + let dbg = format!( + "{:?}", + ctx.registry + .interactive("toggle-panel-and-focus", &args, &ctx) + .expect("toggle-panel-and-focus resolves") + .execute(&ctx) + ); + assert!( + dbg.contains("open: false") && !dbg.contains("open: true"), + "`{} false false` on a closed panel toggled it open: {dbg}", + panel.name() + ); + } + } }