yew/tests/macro/html-component-fail.rs
Justin Starry 70862a46a1
Revert "Improve nested html! expansion by unwrapping VNodes (#820)" (#842)
This reverts commit a900fbee496d1140b424bcb2f1c91402d20eca2b.
2020-01-04 13:35:50 -05:00

102 lines
2.9 KiB
Rust

#![recursion_limit = "128"]
use std::marker::PhantomData;
use yew::prelude::*;
use yew::virtual_dom::{VChild, VComp, VNode};
#[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(_: Self::Properties, _: ComponentLink<Self>) -> Self { unimplemented!() }
fn update(&mut self, _: Self::Message) -> ShouldRender { unimplemented!() }
fn view(&self) -> Html { unimplemented!() }
}
impl From<VChild<Child>> for ChildProperties {
fn from(comp: VChild<Child>) -> Self {
comp.props
}
}
impl Into<VNode> for ChildProperties {
fn into(self) -> VNode {
VComp::new::<Child>(self, NodeRef::default()).into()
}
}
#[derive(Clone, Properties)]
pub struct ChildContainerProperties {
#[props(required)]
pub children: ChildrenWithProps<Child>,
}
pub struct ChildContainer;
impl Component for ChildContainer {
type Message = ();
type Properties = ChildContainerProperties;
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { unimplemented!() }
fn update(&mut self, _: Self::Message) -> ShouldRender { unimplemented!() }
fn view(&self) -> Html { unimplemented!() }
}
pub struct Generic<G> {
marker: PhantomData<G>,
}
impl Component for Generic<String> {
type Message = ();
type Properties = ();
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { unimplemented!() }
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 /> };
html! { <ChildContainer></ChildContainer> };
html! { <ChildContainer>{ "Not allowed" }</ChildContainer> };
html! { <ChildContainer><></></ChildContainer> };
html! { <ChildContainer><Child int=1 /><other /></ChildContainer> };
html! { <Generic<String>></Generic> };
html! { <Generic<String>></Generic<Vec<String>>> };
}
fn main() {}