Add some compile error test
This commit is contained in:
parent
7665690982
commit
d7c3b8fa0b
|
@ -0,0 +1 @@
|
|||
out/
|
|
@ -0,0 +1,13 @@
|
|||
use sailfish::TemplateOnce;
|
||||
use sailfish_macros::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "foo.stpl", escape=true)]
|
||||
#[template(escape = false)]
|
||||
struct InvalidOptionValue {
|
||||
name: String
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", InvalidOptionValue { name: "Hanako".to_owned() }.render_once().unwrap());
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
error: keyword argument repeated.
|
||||
--> $DIR/repeated_arguments.rs:6:21
|
||||
|
|
||||
6 | #[template(escape = false)]
|
||||
| ^^^^^
|
||||
|
||||
error[E0599]: no method named `render_once` found for struct `InvalidOptionValue` in the current scope
|
||||
--> $DIR/repeated_arguments.rs:12:69
|
||||
|
|
||||
7 | struct InvalidOptionValue {
|
||||
| ------------------------- method `render_once` not found for this
|
||||
...
|
||||
12 | println!("{}", InvalidOptionValue { name: "Hanako".to_owned() }.render_once().unwrap());
|
||||
| ^^^^^^^^^^^ method not found in `InvalidOptionValue`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following trait defines an item `render_once`, perhaps you need to implement it:
|
||||
candidate #1: `sailfish::TemplateOnce`
|
||||
|
||||
warning: unused import: `sailfish::TemplateOnce`
|
||||
--> $DIR/repeated_arguments.rs:1:5
|
||||
|
|
||||
1 | use sailfish::TemplateOnce;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
|
@ -0,0 +1,3 @@
|
|||
<% for player in &players %>
|
||||
<div><%= player.name %>: <%= player.score %></div>
|
||||
<% } %>
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<%= content
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "<%= name %>",
|
||||
"content": <% =content %>
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use sailfish::TemplateOnce;
|
||||
use sailfish_macros::TemplateOnce;
|
||||
|
||||
struct Player<'a> {
|
||||
name: &'a str,
|
||||
score: u32,
|
||||
}
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "unbalanced_brace.stpl")]
|
||||
struct UnbalancedBrace {
|
||||
players: Vec<Player>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
UnclosedDelimiter {
|
||||
players: vec![Player { name: "Hanako", score: 97 }]
|
||||
}
|
||||
.render_once()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
error: Failed to compile template.
|
||||
Caused by: Rust Syntax Error: LexError
|
||||
|
||||
file: unbalanced_brace.stpl
|
||||
|
||||
--> $DIR/unbalanced_brace.rs:9:10
|
||||
|
|
||||
9 | #[derive(TemplateOnce)]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0422]: cannot find struct, variant or union type `UnclosedDelimiter` in this scope
|
||||
--> $DIR/unbalanced_brace.rs:18:9
|
||||
|
|
||||
18 | UnclosedDelimiter {
|
||||
| ^^^^^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/unbalanced_brace.rs:12:18
|
||||
|
|
||||
12 | players: Vec<Player>,
|
||||
| ^^^^^^ expected named lifetime parameter
|
||||
|
|
||||
help: consider introducing a named lifetime parameter
|
||||
|
|
||||
11 | struct UnbalancedBrace<'a> {
|
||||
12 | players: Vec<Player<'a>>,
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
use sailfish::TemplateOnce;
|
||||
use sailfish_macros::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "unclosed_delimiter.stpl")]
|
||||
struct UnclosedDelimiter {
|
||||
content: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
UnclosedDelimiter {
|
||||
content: String::from("Hello, world!")
|
||||
}
|
||||
.render_once()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
error: Failed to compile template.
|
||||
Caused by: Parse error: Unterminated code block
|
||||
|
||||
file: unclosed_delimiter.stpl
|
||||
position: line 3, column 5
|
||||
|
||||
|
|
||||
3 | <%= content
|
||||
| ^
|
||||
|
||||
--> $DIR/unclosed_delimter.rs:4:10
|
||||
|
|
||||
4 | #[derive(TemplateOnce)]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0599]: no method named `render_once` found for struct `UnclosedDelimiter` in the current scope
|
||||
--> $DIR/unclosed_delimter.rs:16:10
|
||||
|
|
||||
6 | struct UnclosedDelimiter {
|
||||
| ------------------------ method `render_once` not found for this
|
||||
...
|
||||
16 | .render_once()
|
||||
| ^^^^^^^^^^^ method not found in `UnclosedDelimiter`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following trait defines an item `render_once`, perhaps you need to implement it:
|
||||
candidate #1: `sailfish::TemplateOnce`
|
||||
|
||||
warning: unused import: `sailfish::TemplateOnce`
|
||||
--> $DIR/unclosed_delimter.rs:1:5
|
||||
|
|
||||
1 | use sailfish::TemplateOnce;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
|
@ -0,0 +1,32 @@
|
|||
use sailfish::TemplateOnce;
|
||||
use sailfish_macros::TemplateOnce;
|
||||
|
||||
struct Content<'a> {
|
||||
id: u32,
|
||||
address: &'a str,
|
||||
phone_number: &'a str,
|
||||
}
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "unexpected_token.stpl")]
|
||||
#[template(escape = false)]
|
||||
struct UnexpectedToken<'a> {
|
||||
name: &'a str,
|
||||
content: Content<'a>
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
UnclosedToken {
|
||||
name: "Taro",
|
||||
content: Content {
|
||||
id: 1,
|
||||
address: "oooo-xxxx",
|
||||
phone_number: "000-000-0000"
|
||||
}
|
||||
}
|
||||
.render_once()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
error: Failed to compile template.
|
||||
Caused by: Rust Syntax Error: expected expression
|
||||
|
||||
file: unexpected_token.stpl
|
||||
position: line 3, column 17
|
||||
|
||||
|
|
||||
3 | "content": <% =content %>
|
||||
| ^
|
||||
|
||||
--> $DIR/unexpected_token.rs:10:10
|
||||
|
|
||||
10 | #[derive(TemplateOnce)]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0422]: cannot find struct, variant or union type `UnclosedToken` in this scope
|
||||
--> $DIR/unexpected_token.rs:21:9
|
||||
|
|
||||
21 | UnclosedToken {
|
||||
| ^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
warning: unused import: `sailfish::TemplateOnce`
|
||||
--> $DIR/unexpected_token.rs:1:5
|
||||
|
|
||||
1 | use sailfish::TemplateOnce;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
Loading…
Reference in New Issue