#[macro_use] extern crate plaster; #[macro_use] extern crate wasm_bindgen_test; wasm_bindgen_test_configure!(run_in_browser); use plaster::prelude::*; use plaster::virtual_dom::VNode; struct Comp; impl Component for Comp { type Message = (); type Properties = (); fn create(_: Self::Properties, _: ComponentLink) -> Self { Comp } fn update(&mut self, _: Self::Message) -> ShouldRender { unimplemented!(); } } impl Renderable for Comp { fn view(&self) -> Html { unimplemented!(); } } #[wasm_bindgen_test] fn it_compares_tags() { let a: VNode = html! {
}; let b: VNode = html! {
}; let c: VNode = html! {

}; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_text() { let a: VNode = html! {
{ "correct" }
}; let b: VNode = html! {
{ "correct" }
}; let c: VNode = html! {
{ "incorrect" }
}; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_attributes() { let a: VNode = html! {
}; let b: VNode = html! {
}; let c: VNode = html! {
}; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_children() { let a: VNode = html! {

}; let b: VNode = html! {

}; let c: VNode = html! {
}; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_classes() { let a: VNode = html! {
}; let b: VNode = html! {
}; let c: VNode = html! {
}; let d: VNode = html! {
}; assert_eq!(a, b); assert_ne!(a, c); assert_eq!(c, d); } #[test] fn classes_from_local_variables() { let a: VNode = html! {
}; let class_2 = "class-2"; let b: VNode = html! {
}; let class_2_fmt = format!("class-{}", 2); let c: VNode = html! {
}; assert_eq!(a, b); assert_eq!(a, c); } #[test] fn supports_multiple_classes_string() { let a: VNode = html! {
}; let b: VNode = html! {
}; assert_eq!(a, b); if let VNode::VTag(vtag) = a { println!("{:?}", vtag.classes); assert!(vtag.classes.contains("class-1")); assert!(vtag.classes.contains("class-2")); assert!(vtag.classes.contains("class-3")); } else { panic!("vtag expected"); } } #[test] fn it_compares_values() { let a: VNode = html! { }; let b: VNode = html! { }; let c: VNode = html! { }; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_kinds() { let a: VNode = html! { }; let b: VNode = html! { }; let c: VNode = html! { }; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_compares_checked() { let a: VNode = html! { }; let b: VNode = html! { }; let c: VNode = html! { }; assert_eq!(a, b); assert_ne!(a, c); } #[test] fn it_allows_aria_attributes() { let a: VNode = html! {

}; if let VNode::VTag(vtag) = a { assert!(vtag.attributes.contains_key("aria-controls")); assert_eq!( vtag.attributes.get("aria-controls"), Some(&"it-works".into()) ); } else { panic!("vtag expected"); } }