mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Tests: the tool.options test reads each tool's dialog value from the params text
The tool.options test compared the params text with fixed phrases and hard-coded the `dialog` value each tool returns. It now parses the "<values> for <tools>" pairs after "The returned `dialog` field holds" and checks each tool's response against the value the text gives it. It fails when the text names a tool the test does not run, gives a tool two values, or gives transform values to tools other than the transform tools. It also checks that the text says the dialog names are the `key` in ui.inspect.
This commit is contained in:
1 parent
e1b3943f46
commit
a1bba4a8e4
1 file changed
+42
-12
@@ -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`: "<values> for <tools>" pairs, where <values> names the tool
|
||||
// itself (with <tools> "the corresponding transform tool" and every value in the transform group) or one value for
|
||||
// every tool in <tools>.
|
||||
let documented_dialog = |tool: &str| -> Option<String> {
|
||||
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"));
|
||||
|
||||
Reference in new issue
Block a user