diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 12ad414fc5..8b8070257c 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -1151,12 +1151,45 @@ fn menu_dialog_params_text_lists_every_command_whose_dialog_it_opens() { #[test] fn tool_options_opens_the_dialog_keys_its_params_text_names() { let doc = crate::menus::UI_COMMANDS.iter().find(|c| c.0 == "tool.options").expect("registered").3; - for (group, response_doc) in [ - ("rotate|scale|reflect|shear", "rotate|scale|reflect|shear for the corresponding transform tool"), - ("selection|directSelection|groupSelection", "move for selection|directSelection|groupSelection"), - ("typeOnPath|verticalTypeOnPath", "command for typeOnPath|verticalTypeOnPath"), - ] { - assert!(doc.contains(response_doc), "{group}: the params text must document its expected response dialog values"); + let plain = doc.replace('`', ""); + assert!(plain.contains("key in ui.inspect"), "the params text must say the dialog names are the `key` in ui.inspect"); + let field = clause(&plain, "returned dialog field holds ", &['.']); + // The `dialog` value the params text gives for `tool`: " for " pairs, where names the tool + // itself (with "the corresponding transform tool" and every value in the transform group) or one value for + // every tool in . + let documented_dialog = |tool: &str| -> Option { + let mut mappings = field.split(", ").map(|part| part.trim_start_matches("and ")).filter_map(|part| { + let (values, tools) = part.split_once(" for ")?; + if tools == "the corresponding transform tool" && values.split('|').any(|v| v == tool) { + Some(tool.to_string()) + } else if tools.split('|').any(|t| t == tool) { + Some(values.to_string()) + } else { + None + } + }); + let mapping = mappings.next(); + assert!(mappings.next().is_none(), "{tool}: the params text gives more than one `dialog` mapping"); + mapping + }; + let groups = ["rotate|scale|reflect|shear", "selection|directSelection|groupSelection", "typeOnPath|verticalTypeOnPath"]; + let checked: Vec<&str> = groups.iter().flat_map(|g| g.split('|')).collect(); + let mut named_tools = Vec::new(); + for part in field.split(", ").map(|part| part.trim_start_matches("and ")) { + let (values, tools) = part.split_once(" for ").unwrap_or_else(|| panic!("`{part}` pairs no dialog value with tools")); + let named = if tools == "the corresponding transform tool" { + assert!(values.split('|').all(|value| groups[0].split('|').any(|tool| tool == value)), "`{part}` names a non-transform tool"); + values + } else { + tools + }; + for tool in named.split('|') { + assert!(checked.contains(&tool), "the params text gives a `dialog` value for {tool}, which this test does not check"); + assert!(!named_tools.contains(&tool), "{tool}: the params text gives more than one `dialog` mapping"); + named_tools.push(tool); + } + } + for group in groups { let documented = clause(doc, &format!("{group} → "), &[';']); let keys: Vec<&str> = documented.split('`').skip(1).step_by(2).collect(); let tools: Vec<&str> = group.split('|').collect(); @@ -1171,12 +1204,9 @@ fn tool_options_opens_the_dialog_keys_its_params_text_names() { app.session.execute("select.set", &json!({"ids": [text["id"]]})).unwrap(); } let response = app.run("tool.options", json!({"tool": tool})).unwrap_or_else(|e| panic!("{tool}: {e}")); - let expected_dialog = match tool { - "selection" | "directSelection" | "groupSelection" => "move", - "typeOnPath" | "verticalTypeOnPath" => "command", - _ => tool, - }; - assert_eq!(response["dialog"], expected_dialog, "{tool}: its response names the wrong dialog"); + let expected_dialog = + documented_dialog(tool).unwrap_or_else(|| panic!("{tool}: the params text does not say which `dialog` its response holds")); + assert_eq!(response["dialog"], expected_dialog.as_str(), "{tool}: its response names a `dialog` other than the params text's"); settle(&mut app); let keys = dialog_keys(&app); let key = keys.last().unwrap_or_else(|| panic!("{tool} opens no dialog"));