fix key validation logic (#3936)
This commit is contained in:
1 parent
5e9a505465
commit
16cae8abaf
2 files changed
+29
-1
No files matched your search
@@ -236,11 +236,13 @@ impl TemplateBody {
|
|||||||
|
|
||||||
// Assign paths to all nodes in the template
|
// Assign paths to all nodes in the template
|
||||||
body.assign_paths_inner(&nodes);
|
body.assign_paths_inner(&nodes);
|
||||||
body.validate_key();
|
|
||||||
|
|
||||||
// And then save the roots
|
// And then save the roots
|
||||||
body.roots = nodes;
|
body.roots = nodes;
|
||||||
|
|
||||||
|
// Finally, validate the key
|
||||||
|
body.validate_key();
|
||||||
|
|
||||||
body
|
body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,3 +141,29 @@ fn complex_kitchen_sink() {
|
|||||||
|
|
||||||
let _cb: CallBody = syn::parse2(item).unwrap();
|
let _cb: CallBody = syn::parse2(item).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn key_must_be_formatted() {
|
||||||
|
let item = quote::quote! {
|
||||||
|
div {
|
||||||
|
key: value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let parsed = syn::parse2::<CallBody>(item).unwrap();
|
||||||
|
println!("{:?}", parsed.body.diagnostics);
|
||||||
|
assert!(!parsed.body.diagnostics.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn key_cannot_be_static() {
|
||||||
|
let item = quote::quote! {
|
||||||
|
div {
|
||||||
|
key: "hello world"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let parsed = syn::parse2::<CallBody>(item).unwrap();
|
||||||
|
println!("{:?}", parsed.body.diagnostics);
|
||||||
|
assert!(!parsed.body.diagnostics.is_empty());
|
||||||
|
}
|
||||||
Reference in new issue
Block a user