From 2f4b334e89c142db72bb411b715a96a59eda845a Mon Sep 17 00:00:00 2001 From: Luke Chu <37006668+lukechu10@users.noreply.github.com> Date: Wed, 4 Aug 2021 16:19:40 -0700 Subject: [PATCH 1/2] Add ui checks for component --- .../tests/component/component-fail.rs | 9 +++++++++ .../tests/component/component-fail.stderr | 5 +++++ .../tests/component/component-pass.rs | 8 ++++++++ packages/sycamore-macro/tests/template_macro.rs | 8 -------- packages/sycamore-macro/tests/ui.rs | 17 +++++++++++++++++ .../tests/{router_macros.rs => ui.rs} | 0 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 packages/sycamore-macro/tests/component/component-fail.rs create mode 100644 packages/sycamore-macro/tests/component/component-fail.stderr create mode 100644 packages/sycamore-macro/tests/component/component-pass.rs delete mode 100644 packages/sycamore-macro/tests/template_macro.rs create mode 100644 packages/sycamore-macro/tests/ui.rs rename packages/sycamore-router-macro/tests/{router_macros.rs => ui.rs} (100%) diff --git a/packages/sycamore-macro/tests/component/component-fail.rs b/packages/sycamore-macro/tests/component/component-fail.rs new file mode 100644 index 000000000..1588d5d3d --- /dev/null +++ b/packages/sycamore-macro/tests/component/component-fail.rs @@ -0,0 +1,9 @@ +use sycamore::prelude::*; + +/// Missing return type. +#[component(Comp1)] +fn comp1() { + todo!(); +} + +fn main() {} diff --git a/packages/sycamore-macro/tests/component/component-fail.stderr b/packages/sycamore-macro/tests/component/component-fail.stderr new file mode 100644 index 000000000..c82b9c9c7 --- /dev/null +++ b/packages/sycamore-macro/tests/component/component-fail.stderr @@ -0,0 +1,5 @@ +error: function must return `sycamore::template::Template` + --> $DIR/component-fail.rs:5:1 + | +5 | fn comp1() { + | ^^^^^^^^^^ diff --git a/packages/sycamore-macro/tests/component/component-pass.rs b/packages/sycamore-macro/tests/component/component-pass.rs new file mode 100644 index 000000000..a49be799a --- /dev/null +++ b/packages/sycamore-macro/tests/component/component-pass.rs @@ -0,0 +1,8 @@ +use sycamore::prelude::*; + +#[component(Comp1)] +fn comp1() -> Template { + todo!(); +} + +fn main() {} diff --git a/packages/sycamore-macro/tests/template_macro.rs b/packages/sycamore-macro/tests/template_macro.rs deleted file mode 100644 index e2c615cf5..000000000 --- a/packages/sycamore-macro/tests/template_macro.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[test] -fn ui() { - let t = trybuild::TestCases::new(); - t.pass("tests/template/*-pass.rs"); - if std::env::var("RUN_UI_TESTS").is_ok() { - t.compile_fail("tests/template/*-fail.rs"); - } -} diff --git a/packages/sycamore-macro/tests/ui.rs b/packages/sycamore-macro/tests/ui.rs new file mode 100644 index 000000000..1a9cf3130 --- /dev/null +++ b/packages/sycamore-macro/tests/ui.rs @@ -0,0 +1,17 @@ +#[test] +fn template_ui() { + let t = trybuild::TestCases::new(); + t.pass("tests/template/*-pass.rs"); + if std::env::var("RUN_UI_TESTS").is_ok() { + t.compile_fail("tests/template/*-fail.rs"); + } +} + +#[test] +fn component_ui() { + let t = trybuild::TestCases::new(); + t.pass("tests/component/*-pass.rs"); + if std::env::var("RUN_UI_TESTS").is_ok() { + t.compile_fail("tests/component/*-fail.rs"); + } +} diff --git a/packages/sycamore-router-macro/tests/router_macros.rs b/packages/sycamore-router-macro/tests/ui.rs similarity index 100% rename from packages/sycamore-router-macro/tests/router_macros.rs rename to packages/sycamore-router-macro/tests/ui.rs From 710d85c3ee1a27dd384ba0602248b73808a02cee Mon Sep 17 00:00:00 2001 From: Luke Chu <37006668+lukechu10@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:24:37 -0700 Subject: [PATCH 2/2] Add more ui test cases --- packages/sycamore-macro/src/component/mod.rs | 2 +- .../tests/component/component-fail.rs | 46 +++++++++++++++ .../tests/component/component-fail.stderr | 58 +++++++++++++++++++ .../tests/component/component-pass.rs | 5 ++ 4 files changed, 110 insertions(+), 1 deletion(-) diff --git a/packages/sycamore-macro/src/component/mod.rs b/packages/sycamore-macro/src/component/mod.rs index 4bba1a91f..d80084d3b 100644 --- a/packages/sycamore-macro/src/component/mod.rs +++ b/packages/sycamore-macro/src/component/mod.rs @@ -150,7 +150,7 @@ impl Parse for ComponentFunction { } item => Err(syn::Error::new_spanned( item, - "`function_component` attribute can only be applied to functions", + "`component` attribute can only be applied to functions", )), } } diff --git a/packages/sycamore-macro/tests/component/component-fail.rs b/packages/sycamore-macro/tests/component/component-fail.rs index 1588d5d3d..42569e12f 100644 --- a/packages/sycamore-macro/tests/component/component-fail.rs +++ b/packages/sycamore-macro/tests/component/component-fail.rs @@ -6,4 +6,50 @@ fn comp1() { todo!(); } +/// Missing component name. +#[component] +fn comp2() -> Template { + todo!(); +} + +/// Missing generic param. +#[component(Comp3)] +fn comp3() -> Template { + todo!(); +} + +#[component(Comp4)] +async fn comp4() -> Template { + todo!(); +} + +#[component(Comp5)] +const fn comp5() -> Template { + todo!(); +} + +#[component(Comp6)] +extern fn comp6() -> Template { + todo!(); +} + +#[component(Comp7)] +fn comp7(self) -> Template { + todo!(); +} + +#[component(Comp8)] +fn comp8(one: (), two: ()) -> Template { + todo!(); +} + +#[component(Comp9)] +struct AStruct; + +#[allow(non_snake_case)] +#[component(Comp10)] +fn Comp10() -> Template { + todo!(); +} + fn main() {} diff --git a/packages/sycamore-macro/tests/component/component-fail.stderr b/packages/sycamore-macro/tests/component/component-fail.stderr index c82b9c9c7..b5768530c 100644 --- a/packages/sycamore-macro/tests/component/component-fail.stderr +++ b/packages/sycamore-macro/tests/component/component-fail.stderr @@ -3,3 +3,61 @@ error: function must return `sycamore::template::Template` | 5 | fn comp1() { | ^^^^^^^^^^ + +error: unexpected end of input, expected an identifier for the component + --> $DIR/component-fail.rs:10:1 + | +10 | #[component] + | ^^^^^^^^^^^^ + | + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected a single type param + --> $DIR/component-fail.rs:16:1 + | +16 | #[component(Comp3)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: async functions can't be components + --> $DIR/component-fail.rs:22:1 + | +22 | async fn comp4() -> Template { + | ^^^^^ + +error: const functions can't be components + --> $DIR/component-fail.rs:27:1 + | +27 | const fn comp5() -> Template { + | ^^^^^ + +error: extern functions can't be components + --> $DIR/component-fail.rs:32:1 + | +32 | extern fn comp6() -> Template { + | ^^^^^^ + +error: function components can't accept a receiver + --> $DIR/component-fail.rs:37:10 + | +37 | fn comp7(self) -> Template { + | ^^^^ + +error: function should accept at most one parameter for the prop + --> $DIR/component-fail.rs:42:19 + | +42 | fn comp8(one: (), two: ()) -> Template { + | ^^^^^^^ + +error: `component` attribute can only be applied to functions + --> $DIR/component-fail.rs:47:1 + | +47 | struct AStruct; + | ^^^^^^^^^^^^^^^ + +error: the component must not have the same name as the function + --> $DIR/component-fail.rs:50:13 + | +50 | #[component(Comp10)] + | ^^^^^^ diff --git a/packages/sycamore-macro/tests/component/component-pass.rs b/packages/sycamore-macro/tests/component/component-pass.rs index a49be799a..148e7b3ac 100644 --- a/packages/sycamore-macro/tests/component/component-pass.rs +++ b/packages/sycamore-macro/tests/component/component-pass.rs @@ -5,4 +5,9 @@ fn comp1() -> Template { todo!(); } +#[component(Comp2)] +fn comp2(props: ()) -> Template { + todo!(); +} + fn main() {}