Skip to content

Commit

Permalink
Add regression test for .. pattern in structs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez authored and Kijewski committed Jun 28, 2024
1 parent e94525f commit 6ee3765
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
26 changes: 26 additions & 0 deletions testing/tests/let_destructoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,29 @@ fn test_let_destruct_with_path_and_with_keyword() {
};
assert_eq!(t.render().unwrap(), "hello");
}

#[derive(Template)]
#[template(
source = "
{%- if let RestPattern2 { a, b } = x -%}hello {{ a }}{%- endif -%}
{%- if let RestPattern2 { a, b, } = x -%}hello {{ b }}{%- endif -%}
{%- if let RestPattern2 { a, .. } = x -%}hello {{ a }}{%- endif -%}
",
ext = "html"
)]
struct RestPattern {
x: RestPattern2,
}

struct RestPattern2 {
a: u32,
b: u32,
}

#[test]
fn test_has_rest_pattern() {
let t = RestPattern {
x: RestPattern2 { a: 0, b: 1 },
};
assert_eq!(t.render().unwrap(), "hello 0hello 1hello 0");
}
40 changes: 40 additions & 0 deletions testing/tests/ui/let_destructuring_has_rest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use rinja::Template;

struct X {
a: u32,
b: u32,
}

#[derive(Template)]
#[template(source = "
{%- if let X { a, .. } = x -%}hello {{ a }}{%- endif -%}
", ext = "html")]
struct T1 {
x: X,
}

#[derive(Template)]
#[template(source = "
{%- if let X { a, .., } = x -%}hello {{ a }}{%- endif -%}
", ext = "html")]
struct T2 {
x: X,
}

#[derive(Template)]
#[template(source = "
{%- if let X { a .. } = x -%}hello {{ a }}{%- endif -%}
", ext = "html")]
struct T3 {
x: X,
}

#[derive(Template)]
#[template(source = "
{%- if let X { .. } = x -%}hello {{ a }}{%- endif -%}
", ext = "html")]
struct T4 {
x: X,
}

fn main() {}
26 changes: 26 additions & 0 deletions testing/tests/ui/let_destructuring_has_rest.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: unexpected `,` character after `..`
failed to parse template source at row 2, column 20 near:
", } = x -%}hello {{ a }}{%- endif -%}\n"
--> tests/ui/let_destructuring_has_rest.rs:16:10
|
16 | #[derive(Template)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error: failed to parse template source at row 2, column 17 near:
".. } = x -%}hello {{ a }}{%- endif -%}\n"
--> tests/ui/let_destructuring_has_rest.rs:24:10
|
24 | #[derive(Template)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0609]: no field `a` on type `&T4`
--> tests/ui/let_destructuring_has_rest.rs:32:10
|
32 | #[derive(Template)]
| ^^^^^^^^ unknown field
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 6ee3765

Please sign in to comment.