mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 06:21:13 +00:00
Add regression test for *
and &
in expressions
This commit is contained in:
parent
e9fc4a6db3
commit
e5a3e1c763
62
testing/tests/ref_deref.rs
Normal file
62
testing/tests/ref_deref.rs
Normal file
@ -0,0 +1,62 @@
|
||||
use rinja::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
source = r#"
|
||||
{%- if *title == "something" -%}
|
||||
something1
|
||||
{%- elif title == &"another" -%}
|
||||
another2
|
||||
{%- elif &*title == &&*"yep" -%}
|
||||
yep3
|
||||
{%- else -%}
|
||||
{{title}}
|
||||
{%- endif -%}
|
||||
"#,
|
||||
ext = "html"
|
||||
)]
|
||||
struct RefDeref {
|
||||
title: &'static &'static str,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ref_deref() {
|
||||
let x = RefDeref {
|
||||
title: &"something",
|
||||
};
|
||||
assert_eq!(x.render().unwrap(), "something1");
|
||||
|
||||
let x = RefDeref { title: &"another" };
|
||||
assert_eq!(x.render().unwrap(), "another2");
|
||||
|
||||
let x = RefDeref { title: &"yep" };
|
||||
assert_eq!(x.render().unwrap(), "yep3");
|
||||
|
||||
let x = RefDeref { title: &"bla" };
|
||||
assert_eq!(x.render().unwrap(), "bla");
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
source = r#"
|
||||
{%- let x = *title -%}
|
||||
{%- if x == "another" -%}
|
||||
another2
|
||||
{%- else -%}
|
||||
{{x}}
|
||||
{%- endif -%}
|
||||
"#,
|
||||
ext = "html"
|
||||
)]
|
||||
struct RefDerefAssignment {
|
||||
title: &'static &'static str,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ref_deref_assign() {
|
||||
let x = RefDerefAssignment { title: &"another" };
|
||||
assert_eq!(x.render().unwrap(), "another2");
|
||||
|
||||
let x = RefDerefAssignment { title: &"two" };
|
||||
assert_eq!(x.render().unwrap(), "two");
|
||||
}
|
8
testing/tests/ui/ref_deref.rs
Normal file
8
testing/tests/ui/ref_deref.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use rinja::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(source = "{% let *x = 2 %}", ext = "html")]
|
||||
struct WrongRefDeref;
|
||||
|
||||
fn main() {
|
||||
}
|
8
testing/tests/ui/ref_deref.stderr
Normal file
8
testing/tests/ui/ref_deref.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: failed to parse template source at row 1, column 7 near:
|
||||
"*x = 2 %}"
|
||||
--> tests/ui/ref_deref.rs:3:10
|
||||
|
|
||||
3 | #[derive(Template)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
Loading…
x
Reference in New Issue
Block a user