feat(derive): scope component handler checks
Allow #[slhx::component("name")] to validate only the generated handles for that hemplate component, so component modules can be checked independently without implementing unrelated handles.
req: component/003
req: component/005
This commit is contained in:
@@ -56,6 +56,60 @@ mod todos {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn component_macro_can_validate_one_generated_component() {
|
||||
// req: component/003 req: component/005 req: test/003
|
||||
let fixture = Fixture::new("slhx-derive-component-scoped-pass");
|
||||
fixture.write(
|
||||
"Cargo.toml",
|
||||
&format!(
|
||||
r#"[package]
|
||||
name = "slhx-derive-component-scoped-pass"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
slhx = {{ path = {:?} }}
|
||||
"#,
|
||||
repo_path("slhx")
|
||||
),
|
||||
);
|
||||
fixture.write(
|
||||
"build.rs",
|
||||
r#"fn main() {
|
||||
let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
||||
std::fs::write(
|
||||
out.join("slhx.syms"),
|
||||
"slhx-syms-v1\nhandle\ttemplates/todos.heml::create\tcreate\t1\nhandle\ttemplates/admin.heml::delete\tdelete\t2\n",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
fixture.write(
|
||||
"src/lib.rs",
|
||||
r#"#[slhx::component("todos")]
|
||||
mod todos {
|
||||
#[slhx::handler]
|
||||
fn create() -> impl slhx::IntoEffect {
|
||||
slhx::event("created", "")
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
let output = check_fixture(&fixture);
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"fixture failed to compile:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handler_macro_reports_unknown_handle_and_bad_shape() {
|
||||
// req: derive_handler/001 req: test/003
|
||||
|
||||
Reference in New Issue
Block a user