use crate::assert_html_eq; use lfml::Spread; #[test] fn basic() { #[derive(Spread)] #[prefix = "hx"] struct HxGet<'a> { get: &'a str, target: &'a str, swap: &'a str, } let x = HxGet { get: "/a", target: ".main", swap: "outerHTML", }; assert_html_eq!({ a@(x) { "A" } } => "A"); assert_html_eq!({ div@( HxGet { get: "/a", target: ".main", swap: "outerHTML", } ) { "A" } } => "
A
"); } #[test] fn restrict_attribute() { #[derive(Spread)] #[prefix = "hx"] #[tags(only(a, b, c))] struct HxGet<'a> { get: &'a str, target: &'a str, swap: &'a str, } let x = HxGet { get: "/a", target: ".main", swap: "outerHTML", }; assert_html_eq!({ a@(x) { "A" } } => "A"); assert_html_eq!({ b@( HxGet { get: "/a", target: ".main", swap: "outerHTML", } ) { "A" } } => "A"); assert_html_eq!({ c@(x) { "A" } } => "A"); } #[test] fn multiple_structs_on_valid_tag() { #[derive(Spread)] #[tags(only(a))] struct Foo<'a> { target: &'a str, } #[derive(Spread)] #[tags(only(a))] struct Bar<'a> { get: &'a str, } let x = Bar { get: "/" }; assert_html_eq!({ a @(Foo { target: ".main" }) @(x) { "A" } } => "A"); } #[test] fn option_type_with_toggle_syntax() { #[derive(Spread)] #[tags(include(a))] struct Foo<'a> { target: &'a str, } let x = Some(Foo { target: ".main" }); assert_html_eq!({ a @[x] { "A" } } => "A"); let x: Option> = None; assert_html_eq!({ a @[x] { "A" } } => "A"); }