From 2e8573125566efa772b9a3a9ad4846643257b74b Mon Sep 17 00:00:00 2001 From: KirillSemyonkin Date: Sun, 5 Nov 2023 19:42:51 +0300 Subject: [PATCH] Add tests --- .../tests/html_macro/dyn-prop-fail.rs | 67 +++++++++++++++++++ .../tests/html_macro/dyn-prop-fail.stderr | 33 +++++++++ .../tests/html_macro/dyn-prop-pass.rs | 53 +++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 packages/yew-macro/tests/html_macro/dyn-prop-fail.rs create mode 100644 packages/yew-macro/tests/html_macro/dyn-prop-fail.stderr create mode 100644 packages/yew-macro/tests/html_macro/dyn-prop-pass.rs diff --git a/packages/yew-macro/tests/html_macro/dyn-prop-fail.rs b/packages/yew-macro/tests/html_macro/dyn-prop-fail.rs new file mode 100644 index 00000000000..d966d7f20b2 --- /dev/null +++ b/packages/yew-macro/tests/html_macro/dyn-prop-fail.rs @@ -0,0 +1,67 @@ +#![no_implicit_prelude] + +// Shadow primitives +#[allow(non_camel_case_types)] +pub struct bool; +#[allow(non_camel_case_types)] +pub struct char; +#[allow(non_camel_case_types)] +pub struct f32; +#[allow(non_camel_case_types)] +pub struct f64; +#[allow(non_camel_case_types)] +pub struct i128; +#[allow(non_camel_case_types)] +pub struct i16; +#[allow(non_camel_case_types)] +pub struct i32; +#[allow(non_camel_case_types)] +pub struct i64; +#[allow(non_camel_case_types)] +pub struct i8; +#[allow(non_camel_case_types)] +pub struct isize; +#[allow(non_camel_case_types)] +pub struct str; +#[allow(non_camel_case_types)] +pub struct u128; +#[allow(non_camel_case_types)] +pub struct u16; +#[allow(non_camel_case_types)] +pub struct u32; +#[allow(non_camel_case_types)] +pub struct u64; +#[allow(non_camel_case_types)] +pub struct u8; +#[allow(non_camel_case_types)] +pub struct usize; + +#[derive(::yew::Properties, ::std::cmp::PartialEq)] +pub struct SimpleProps { + pub test: ::std::string::String, +} + +pub struct Simple; +impl ::yew::Component for Simple { + type Message = (); + type Properties = SimpleProps; + + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() + } + + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() + } +} + +pub struct Fail; + +fn main() { + _ = ::yew::html! { }; + + let dyn_prop = || Fail; + _ = ::yew::html! { }; + + _ = ::yew::html! { } +} diff --git a/packages/yew-macro/tests/html_macro/dyn-prop-fail.stderr b/packages/yew-macro/tests/html_macro/dyn-prop-fail.stderr new file mode 100644 index 00000000000..f2d25f93c26 --- /dev/null +++ b/packages/yew-macro/tests/html_macro/dyn-prop-fail.stderr @@ -0,0 +1,33 @@ +error: expected a valid Rust identifier + --> tests/html_macro/dyn-prop-fail.rs:66:34 + | +66 | _ = ::yew::html! { } + | ^^^^^^ + +error[E0277]: the trait bound `implicit_clone::unsync::IString: From` is not satisfied + --> tests/html_macro/dyn-prop-fail.rs:61:9 + | +61 | _ = ::yew::html! { }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From` is not implemented for `implicit_clone::unsync::IString` + | + = help: the following other types implement trait `From`: + > + >> + >> + > + = note: required because of the requirements on the impl of `Into` for `Fail` + = note: this error originates in the macro `::yew::html` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `implicit_clone::unsync::IString: From` is not satisfied + --> tests/html_macro/dyn-prop-fail.rs:64:9 + | +64 | _ = ::yew::html! { }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From` is not implemented for `implicit_clone::unsync::IString` + | + = help: the following other types implement trait `From`: + > + >> + >> + > + = note: required because of the requirements on the impl of `Into` for `Fail` + = note: this error originates in the macro `::yew::html` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/packages/yew-macro/tests/html_macro/dyn-prop-pass.rs b/packages/yew-macro/tests/html_macro/dyn-prop-pass.rs new file mode 100644 index 00000000000..61d407a32e2 --- /dev/null +++ b/packages/yew-macro/tests/html_macro/dyn-prop-pass.rs @@ -0,0 +1,53 @@ +#![no_implicit_prelude] + +// Shadow primitives +#[allow(non_camel_case_types)] +pub struct bool; +#[allow(non_camel_case_types)] +pub struct char; +#[allow(non_camel_case_types)] +pub struct f32; +#[allow(non_camel_case_types)] +pub struct f64; +#[allow(non_camel_case_types)] +pub struct i128; +#[allow(non_camel_case_types)] +pub struct i16; +#[allow(non_camel_case_types)] +pub struct i32; +#[allow(non_camel_case_types)] +pub struct i64; +#[allow(non_camel_case_types)] +pub struct i8; +#[allow(non_camel_case_types)] +pub struct isize; +#[allow(non_camel_case_types)] +pub struct str; +#[allow(non_camel_case_types)] +pub struct u128; +#[allow(non_camel_case_types)] +pub struct u16; +#[allow(non_camel_case_types)] +pub struct u32; +#[allow(non_camel_case_types)] +pub struct u64; +#[allow(non_camel_case_types)] +pub struct u8; +#[allow(non_camel_case_types)] +pub struct usize; + +fn main() { + // basic example from https://htmx.org/attributes/hx-on/ + + // repeating attrs is not valid HTMX nor HTML, + // but valid html! (any checks can happen only during runtime) + + // literal + _ = ::yew::html! { }; + _ = ::yew::html! { }; + + // expr + let dyn_prop = || ::std::string::ToString::to_string("hx-on:click"); + _ = ::yew::html! { }; + _ = ::yew::html! { }; +}