yew/tests/macro/html-component-fail.rs
2019-12-28 20:53:29 -06:00

86 lines
2.3 KiB
Rust

#![recursion_limit = "128"]
use yew::prelude::*;
#[derive(Clone, Properties, PartialEq)]
pub struct ChildProperties {
pub string: String,
#[props(required)]
pub int: i32,
}
pub struct Child;
impl Component for Child {
type Message = ();
type Properties = ChildProperties;
fn create(props: Self::Properties, _: ComponentLink<Self>) -> Self {
Child
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
fn view(&self) -> Html {
unimplemented!()
}
}
#[derive(Clone, Properties)]
pub struct ChildContainerProperties {
pub children: ChildrenWithProps<Child>,
}
pub struct ChildContainer;
impl Component for ChildContainer {
type Message = ();
type Properties = ChildContainerProperties;
fn create(props: Self::Properties, _: ComponentLink<Self>) -> Self {
ChildContainer
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
fn view(&self) -> Html {
unimplemented!()
}
}
fn compile_fail() {
html! { <Child> };
html! { <Child:: /> };
html! { <Child with /> };
html! { <Child props /> };
html! { <Child with props > };
html! { <Child with props ref=() ref=() /> };
html! { <Child ref=() with props /> };
html! { <Child with blah /> };
html! { <Child with props () /> };
html! { <Child type=0 /> };
html! { <Child invalid-prop-name=0 /> };
html! { <Child unknown="unknown" /> };
html! { <Child string= /> };
html! { <Child int=1 string={} /> };
html! { <Child int=1 string=3 /> };
html! { <Child int=1 string={3} /> };
html! { <Child int=1 ref=() /> };
html! { <Child int=1 ref=() ref=() /> };
html! { <Child int=0u32 /> };
html! { <Child string="abc" /> };
html! { </Child> };
html! { <Child><Child></Child> };
html! { <Child></Child><Child></Child> };
html! { <Child>{ "Not allowed" }</Child> };
html! { <ChildContainer>{ "Not allowed" }</ChildContainer> };
html! { <ChildContainer><></></ChildContainer> };
html! { <ChildContainer><ChildContainer /></ChildContainer> };
html! { <ChildContainer><ChildContainer /></ChildContainer> };
html! { <ChildContainer><Child int=1 /><other /></ChildContainer> };
}
fn main() {}