diff options
Diffstat (limited to '')
-rw-r--r-- | testing/tests/methods.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/testing/tests/methods.rs b/testing/tests/methods.rs index f33441d..5ed5fd1 100644 --- a/testing/tests/methods.rs +++ b/testing/tests/methods.rs @@ -5,38 +5,39 @@ use askama::Template; #[derive(Template)] #[template(source = "{{ self.get_s() }}", ext = "txt")] -struct MethodTemplate<'a> { +struct SelfMethodTemplate<'a> { s: &'a str, } -impl<'a> MethodTemplate<'a> { +impl<'a> SelfMethodTemplate<'a> { fn get_s(&self) -> &str { self.s } } +#[test] +fn test_self_method() { + let t = SelfMethodTemplate { s: "foo" }; + assert_eq!(t.render().unwrap(), "foo"); +} + + #[derive(Template)] #[template(source = "{{ self.get_s() }} {{ t.get_s() }}", ext = "txt")] -struct NestedMethodTemplate<'a> { - t: MethodTemplate<'a>, +struct NestedSelfMethodTemplate<'a> { + t: SelfMethodTemplate<'a>, } -impl<'a> NestedMethodTemplate<'a> { +impl<'a> NestedSelfMethodTemplate<'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" }, + let t = NestedSelfMethodTemplate { + t: SelfMethodTemplate { s: "foo" }, }; assert_eq!(t.render().unwrap(), "bar foo"); } |