-
-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added view macro tests to leptos_macro
- Loading branch information
Showing
43 changed files
with
1,416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use leptos::*; | ||
|
||
struct A; | ||
|
||
fn main() { | ||
view! { | ||
<>{A}</> | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0277]: expected a `Fn()` closure, found `A` | ||
--> tests/ui/view/block_in_fragment.rs:7:11 | ||
| | ||
6 | / view! { | ||
7 | | <>{A}</> | ||
| | ^-^ | ||
| | || | ||
| | |this tail expression is of type `A` | ||
| | expected an `Fn()` closure, found `A` | ||
8 | | }; | ||
| |_____- required by a bound introduced by this call | ||
| | ||
= help: the trait `std::ops::Fn<()>` is not implemented for `A` | ||
= note: wrap the `A` in a closure with no arguments: `|| { /* code */ }` | ||
= help: the following other types implement trait `IntoView`: | ||
bool | ||
char | ||
isize | ||
i8 | ||
i16 | ||
i32 | ||
i64 | ||
i128 | ||
and $N others | ||
= note: required for `A` to implement `IntoView` | ||
help: you might have meant to create the closure instead of a block | ||
| | ||
7 | <>|_| {A}</> | ||
| +++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use leptos::*; | ||
|
||
#[slot] | ||
struct Then { | ||
children: Children, | ||
} | ||
|
||
#[component] | ||
fn Component(children: Children) -> impl IntoView { | ||
_ = children; | ||
} | ||
|
||
#[component] | ||
fn Slot(then: Then) -> impl IntoView { | ||
_ = then; | ||
} | ||
|
||
struct A; | ||
|
||
fn main() { | ||
let a = A; | ||
|
||
view! { | ||
<Component clone:a> | ||
<p /> | ||
</Component> | ||
}; | ||
|
||
view! { | ||
<Slot> | ||
<Then slot clone:a> | ||
<p/> | ||
</Then> | ||
</Slot> | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0277]: the trait bound `A: Clone` is not satisfied | ||
--> tests/ui/view/children_clone.rs:24:20 | ||
| | ||
23 | / view! { | ||
24 | | <Component clone:a> | ||
| | ^^^^^^^ the trait `Clone` is not implemented for `A` | ||
25 | | <p /> | ||
26 | | </Component> | ||
27 | | }; | ||
| |_____- required by a bound introduced by this call | ||
| | ||
help: consider annotating `A` with `#[derive(Clone)]` | ||
| | ||
18 + #[derive(Clone)] | ||
19 | struct A; | ||
| | ||
|
||
error[E0277]: the trait bound `A: Clone` is not satisfied | ||
--> tests/ui/view/children_clone.rs:31:24 | ||
| | ||
29 | / view! { | ||
30 | | <Slot> | ||
31 | | <Then slot clone:a> | ||
| | ^^^^^^^ the trait `Clone` is not implemented for `A` | ||
32 | | <p/> | ||
33 | | </Then> | ||
34 | | </Slot> | ||
35 | | }; | ||
| |_____- required by a bound introduced by this call | ||
| | ||
help: consider annotating `A` with `#[derive(Clone)]` | ||
| | ||
18 + #[derive(Clone)] | ||
19 | struct A; | ||
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
fn Outer(children: ChildrenFn) -> impl IntoView { | ||
_ = children; | ||
} | ||
|
||
#[component] | ||
fn Inner(children: ChildrenFn) -> impl IntoView { | ||
_ = children; | ||
} | ||
|
||
#[component] | ||
fn Inmost(name: String) -> impl IntoView { | ||
_ = name; | ||
} | ||
|
||
fn main() { | ||
let name = "Alice".to_string(); | ||
|
||
view! { | ||
<Outer> | ||
<Inner> | ||
<Inmost name=name.clone()/> | ||
</Inner> | ||
</Outer> | ||
}; | ||
} |
13 changes: 13 additions & 0 deletions
13
leptos_macro/tests/ui/view/children_projection_error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce` | ||
--> tests/ui/view/children_projection_error.rs:23:13 | ||
| | ||
23 | / <Inner> | ||
24 | | <Inmost name=name.clone()/> | ||
| | ---- closure is `FnOnce` because it moves the variable `name` out of its environment | ||
25 | | </Inner> | ||
| | ^ | ||
| | | | ||
| |____________________this closure implements `FnOnce`, not `Fn` | ||
| the requirement to implement `Fn` derives from here | ||
| | ||
= note: required for `Rc<dyn std::ops::Fn() -> Fragment>` to implement `ToChildren<{closure@$DIR/tests/ui/view/children_projection_error.rs:23:13: 25:21}>` |
35 changes: 35 additions & 0 deletions
35
leptos_macro/tests/ui/view/children_projection_error_slot_version.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
fn Root(outer: Outer) -> impl IntoView { | ||
_ = outer; | ||
} | ||
|
||
#[slot] | ||
struct Outer { | ||
children: ChildrenFn, | ||
} | ||
|
||
#[component] | ||
fn Inner(children: ChildrenFn) -> impl IntoView { | ||
_ = children; | ||
} | ||
|
||
#[component] | ||
fn Inmost(name: String) -> impl IntoView { | ||
_ = name; | ||
} | ||
|
||
fn main() { | ||
let name = "Alice".to_string(); | ||
|
||
view! { | ||
<Root> | ||
<Outer slot> | ||
<Inner> | ||
<Inmost name=name.clone() /> | ||
</Inner> | ||
</Outer> | ||
</Root> | ||
}; | ||
} |
13 changes: 13 additions & 0 deletions
13
leptos_macro/tests/ui/view/children_projection_error_slot_version.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce` | ||
--> tests/ui/view/children_projection_error_slot_version.rs:29:17 | ||
| | ||
29 | / <Inner> | ||
30 | | <Inmost name=name.clone() /> | ||
| | ---- closure is `FnOnce` because it moves the variable `name` out of its environment | ||
31 | | </Inner> | ||
| | ^ | ||
| | | | ||
| |________________________this closure implements `FnOnce`, not `Fn` | ||
| the requirement to implement `Fn` derives from here | ||
| | ||
= note: required for `Rc<dyn std::ops::Fn() -> Fragment>` to implement `ToChildren<{closure@$DIR/tests/ui/view/children_projection_error_slot_version.rs:29:17: 31:25}>` |
12 changes: 12 additions & 0 deletions
12
leptos_macro/tests/ui/view/component_with_props_without_macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use leptos::*; | ||
|
||
#[allow(unused, non_snake_case)] | ||
fn Component(prop: i32) -> impl IntoView { | ||
_ = prop; | ||
} | ||
|
||
fn main() { | ||
view! { | ||
<Component /> | ||
}; | ||
} |
28 changes: 28 additions & 0 deletions
28
leptos_macro/tests/ui/view/component_with_props_without_macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error[E0277]: the trait bound `fn(i32) -> impl leptos::IntoView {Component}: leptos::Component<_>` is not satisfied | ||
--> tests/ui/view/component_with_props_without_macro.rs:10:10 | ||
| | ||
10 | <Component /> | ||
| ^^^^^^^^^ the trait `leptos::Component<_>` is not implemented for fn item `fn(i32) -> impl leptos::IntoView {Component}` | ||
| | ||
note: required by a bound in `component_props_builder` | ||
--> $WORKSPACE/leptos/src/lib.rs | ||
| | ||
| pub fn component_props_builder<P: PropsOrNoPropsBuilder>( | ||
| ----------------------- required by a bound in this function | ||
| _f: &impl Component<P>, | ||
| ^^^^^^^^^^^^ required by this bound in `component_props_builder` | ||
|
||
error[E0277]: the trait bound `&fn(i32) -> impl leptos::IntoView {Component}: ComponentConstructor<_>` is not satisfied | ||
--> tests/ui/view/component_with_props_without_macro.rs:10:10 | ||
| | ||
10 | <Component /> | ||
| -^^^^^^^^^--- | ||
| || | ||
| |the trait `ComponentConstructor<_>` is not implemented for `&fn(i32) -> impl leptos::IntoView {Component}` | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `component_view` | ||
--> $WORKSPACE/leptos/src/lib.rs | ||
| | ||
| pub fn component_view<P>(f: impl ComponentConstructor<P>, props: P) -> View { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `component_view` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
fn Component() -> impl IntoView {} | ||
fn highlight(el: HtmlElement<html::AnyElement>, prop: i32) { | ||
_ = prop; | ||
} | ||
|
||
fn main() { | ||
let data = "Hello World!"; | ||
|
||
view! { | ||
<Component use:highlight /> | ||
}; | ||
|
||
view! { | ||
<Component use:highlight="asd" /> | ||
}; | ||
|
||
view! { | ||
<Component use:highlight=data /> | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error[E0277]: the trait bound `i32: From<()>` is not satisfied | ||
--> tests/ui/view/directives.rs:13:20 | ||
| | ||
13 | <Component use:highlight /> | ||
| ^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `i32` | ||
| | ||
= help: the following other types implement trait `From<T>`: | ||
<i32 as From<bool>> | ||
<i32 as From<i8>> | ||
<i32 as From<i16>> | ||
<i32 as From<u8>> | ||
<i32 as From<u16>> | ||
<i32 as From<NonZeroI32>> | ||
= note: required for `()` to implement `Into<i32>` | ||
|
||
error[E0277]: the trait bound `i32: From<&str>` is not satisfied | ||
--> tests/ui/view/directives.rs:17:34 | ||
| | ||
16 | / view! { | ||
17 | | <Component use:highlight="asd" /> | ||
| | ^^^^^ the trait `From<&str>` is not implemented for `i32` | ||
18 | | }; | ||
| |_____- required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `From<T>`: | ||
<i32 as From<bool>> | ||
<i32 as From<i8>> | ||
<i32 as From<i16>> | ||
<i32 as From<u8>> | ||
<i32 as From<u16>> | ||
<i32 as From<NonZeroI32>> | ||
= note: required for `&str` to implement `Into<i32>` | ||
|
||
error[E0277]: the trait bound `i32: From<&str>` is not satisfied | ||
--> tests/ui/view/directives.rs:21:34 | ||
| | ||
20 | / view! { | ||
21 | | <Component use:highlight=data /> | ||
| | ^^^^ the trait `From<&str>` is not implemented for `i32` | ||
22 | | }; | ||
| |_____- required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `From<T>`: | ||
<i32 as From<bool>> | ||
<i32 as From<i8>> | ||
<i32 as From<i16>> | ||
<i32 as From<u8>> | ||
<i32 as From<u16>> | ||
<i32 as From<NonZeroI32>> | ||
= note: required for `&str` to implement `Into<i32>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
fn Component() -> impl IntoView {} | ||
|
||
fn main() { | ||
view! { | ||
<Component on:click=|| {} /> | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments | ||
--> tests/ui/view/events.rs:8:20 | ||
| | ||
8 | <Component on:click=|| {} /> | ||
| ^^^^^^^^ -- takes 0 arguments | ||
| | | ||
| expected closure that takes 1 argument | ||
| | ||
help: consider changing the closure to take and ignore the expected argument | ||
| | ||
8 | <Component on:click=|_| {} /> | ||
| ~~~ |
14 changes: 14 additions & 0 deletions
14
leptos_macro/tests/ui/view/expected_children_got_let_bind.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
fn Component(children: Children) -> impl IntoView { | ||
_ = children; | ||
} | ||
|
||
fn main() { | ||
view! { | ||
<Component let:a> | ||
<p /> | ||
</Component> | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
leptos_macro/tests/ui/view/expected_children_got_let_bind.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error[E0308]: mismatched types | ||
--> tests/ui/view/expected_children_got_let_bind.rs:11:13 | ||
| | ||
11 | <p /> | ||
| ^^^^^ expected `Box<dyn FnOnce() -> Fragment>`, found closure | ||
| | ||
= note: expected struct `Box<(dyn FnOnce() -> Fragment + 'static)>` | ||
found closure `{closure@$DIR/tests/ui/view/expected_children_got_let_bind.rs:11:13: 11:18}` |
21 changes: 21 additions & 0 deletions
21
leptos_macro/tests/ui/view/expected_children_got_let_bind_slot_version.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use leptos::*; | ||
|
||
#[slot] | ||
struct Then { | ||
children: Children, | ||
} | ||
|
||
#[component] | ||
fn Component(then: Then) -> impl IntoView { | ||
_ = then; | ||
} | ||
|
||
fn main() { | ||
view! { | ||
<Component> | ||
<Then slot let:a> | ||
<p /> | ||
</Then> | ||
</Component> | ||
}; | ||
} |
Oops, something went wrong.