test: harden checked boundary coverage

Use DOM-aware rendered-text inspection for the v0 shell marker check and extend unkeyed h-for validation coverage from slots to handles.

req: test/005

req: scope/001
This commit is contained in:
slhx agent
2026-05-25 23:15:54 +02:00
parent e5c7872fa6
commit 355fc99888
2 changed files with 28 additions and 15 deletions
+4 -1
View File
@@ -248,7 +248,10 @@ mod tests {
); );
assert_eq!(document.select(&selector("script[src=\"/slhx.js\"]")).count(), 1); assert_eq!(document.select(&selector("script[src=\"/slhx.js\"]")).count(), 1);
assert_eq!(document.select(&selector("main[data-slhx-root=\"docs\"]")).count(), 1); assert_eq!(document.select(&selector("main[data-slhx-root=\"docs\"]")).count(), 1);
assert!(!html.contains("{+=")); assert!(
document.root_element().text().all(|text| !text.contains("{+=")),
"hemplate insertion markers must not leak into rendered text"
);
} }
// req: html_safety/002 req: view/001 req: test/005 // req: html_safety/002 req: view/001 req: test/005
+24 -14
View File
@@ -1127,22 +1127,32 @@ fn main() {{
#[test] #[test]
fn rejects_slhx_resources_inside_unkeyed_for() { fn rejects_slhx_resources_inside_unkeyed_for() {
let base = test_dir("slhx-build-unkeyed-for-test"); // req: scope/001
let templates = base.join("templates"); for (case, template, resource) in [
let out = base.join("out"); (
let _ = std::fs::remove_dir_all(&base); "slot",
std::fs::create_dir_all(&templates).unwrap(); r#"<template h-for="todo in &self.todos"><li data-slhx-slot="todo_row">{+ todo.title +}</li></template>"#,
std::fs::write( "data-slhx-slot=\"todo_row\"",
templates.join("todo.heml"), ),
r#"<template h-for="todo in &self.todos"><li data-slhx-slot="todo_row">{+ todo.title +}</li></template>"#, (
) "handle",
.unwrap(); r#"<template h-for="todo in &self.todos"><button data-slhx-handle="delete">Delete</button></template>"#,
"data-slhx-handle=\"delete\"",
),
] {
let base = test_dir(&format!("slhx-build-unkeyed-for-{case}-test"));
let templates = base.join("templates");
let out = base.join("out");
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(&templates).unwrap();
std::fs::write(templates.join("todo.heml"), template).unwrap();
let err = app().template_dir(&templates).out_dir(&out).run().unwrap_err(); let err = app().template_dir(&templates).out_dir(&out).run().unwrap_err();
assert!(err.to_string().contains("inside an h-for without h-key")); assert!(err.to_string().contains("inside an h-for without h-key"));
assert!(err.to_string().contains("data-slhx-slot=\"todo_row\"")); assert!(err.to_string().contains(resource));
let _ = std::fs::remove_dir_all(&base); let _ = std::fs::remove_dir_all(&base);
}
} }
#[test] #[test]