mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 23:35:07 +00:00
Add tests for calling methods on self
This commit is contained in:
parent
ecae242714
commit
0330699a33
42
testing/tests/methods.rs
Normal file
42
testing/tests/methods.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate askama;
|
||||||
|
|
||||||
|
use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{{ self.get_s() }}", ext = "txt")]
|
||||||
|
struct MethodTemplate<'a> {
|
||||||
|
s: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> MethodTemplate<'a> {
|
||||||
|
fn get_s(&self) -> &str {
|
||||||
|
self.s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{{ self.get_s() }} {{ t.get_s() }}", ext = "txt")]
|
||||||
|
struct NestedMethodTemplate<'a> {
|
||||||
|
t: MethodTemplate<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NestedMethodTemplate<'a> {
|
||||||
|
fn get_s(&self) -> &str {
|
||||||
|
"bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_method() {
|
||||||
|
let t = MethodTemplate { s: "foo" };
|
||||||
|
assert_eq!(t.render().unwrap(), "foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nested() {
|
||||||
|
let t = NestedMethodTemplate {
|
||||||
|
t: MethodTemplate { s: "foo" },
|
||||||
|
};
|
||||||
|
assert_eq!(t.render().unwrap(), "bar foo");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user