mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
58 lines
1.1 KiB
Rust
58 lines
1.1 KiB
Rust
#![allow(clippy::useless_let_if_seq)]
|
|
|
|
use askama::Template;
|
|
|
|
#[derive(Template)]
|
|
#[template(source = "{% let v = s %}{{ v }}", ext = "txt")]
|
|
struct LetTemplate<'a> {
|
|
s: &'a str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_let() {
|
|
let t = LetTemplate { s: "foo" };
|
|
assert_eq!(t.render().unwrap(), "foo");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "let.html")]
|
|
struct LetTupleTemplate<'a> {
|
|
s: &'a str,
|
|
t: (&'a str, &'a str),
|
|
}
|
|
|
|
#[test]
|
|
fn test_let_tuple() {
|
|
let t = LetTupleTemplate {
|
|
s: "foo",
|
|
t: ("bar", "bazz"),
|
|
};
|
|
assert_eq!(t.render().unwrap(), "foo\nbarbazz");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "let-decl.html")]
|
|
struct LetDeclTemplate<'a> {
|
|
cond: bool,
|
|
s: &'a str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_let_decl() {
|
|
let t = LetDeclTemplate {
|
|
cond: false,
|
|
s: "bar",
|
|
};
|
|
assert_eq!(t.render().unwrap(), "bar");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(source = "{% for v in self.0 %}{{ v }}{% endfor %}", ext = "txt")]
|
|
struct SelfIterTemplate(Vec<usize>);
|
|
|
|
#[test]
|
|
fn test_self_iter() {
|
|
let t = SelfIterTemplate(vec![1, 2, 3]);
|
|
assert_eq!(t.render().unwrap(), "123");
|
|
}
|