test(derive): close fifth mutation shard
Fail closed when generated form field names cannot map to Rust identifiers and delete the redundant empty generated-parameter branch. req: form/004 req: diagnostics/003 req: test/022 req: test/023
This commit is contained in:
+13
-6
@@ -670,12 +670,8 @@ fn rust_ident(name: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
fn missing_handle_params(path: &PathBuf, ident: &str, function: &ItemFn) -> Vec<String> {
|
||||
let required = handle_params(path, ident);
|
||||
if required.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let args = handler_arg_names(function);
|
||||
required
|
||||
handle_params(path, ident)
|
||||
.into_iter()
|
||||
.filter(|param| !args.contains(param))
|
||||
.collect()
|
||||
@@ -1029,7 +1025,7 @@ mod tests {
|
||||
handler_syms_path, has_form_param, has_non_unit_return, is_type_named,
|
||||
join_contract_errors, missing_component_handlers, missing_form_generated_files_message,
|
||||
missing_handle_params, missing_handler_generated_files_message, parser_type,
|
||||
returns_result, syms_contains_handle, HandlerPlacement,
|
||||
returns_result, rust_ident, syms_contains_handle, HandlerPlacement,
|
||||
};
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{parse_quote, ItemFn, Type};
|
||||
@@ -1432,6 +1428,16 @@ mod tests {
|
||||
assert!(form_model_type(&foreign_form).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_form_field_names_map_only_to_valid_rust_identifiers() {
|
||||
assert_eq!(rust_ident("first-name").as_deref(), Some("first_name"));
|
||||
assert_eq!(rust_ident("_private2").as_deref(), Some("_private2"));
|
||||
for invalid in ["", "2fast", "with space", "naïve"] {
|
||||
assert_eq!(rust_ident(invalid), None, "{invalid:?} must fail closed");
|
||||
}
|
||||
// test req: form/004 req: diagnostics/003
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handler_params_match_generated_param_names() {
|
||||
let path = std::env::temp_dir().join("hemx-derive-param-test.syms");
|
||||
@@ -1453,6 +1459,7 @@ mod tests {
|
||||
|
||||
assert!(missing_handle_params(&path, "show", &complete).is_empty());
|
||||
assert_eq!(missing_handle_params(&path, "show", &missing), vec!["mode"]);
|
||||
assert!(missing_handle_params(&path, "unknown", &missing).is_empty());
|
||||
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user