diff options
author | Mika Lehtinen <smibu90@gmail.com> | 2018-05-20 21:50:59 +0300 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-05-27 09:44:53 +0200 |
commit | 0330699a337f4bd86854eaafccc7128117f10b14 (patch) | |
tree | de076dd7e2208b39a07b3006fc01517983521ace /testing | |
parent | ecae242714875524c421945cbaf0ce948dc5754a (diff) | |
download | askama-0330699a337f4bd86854eaafccc7128117f10b14.tar.gz askama-0330699a337f4bd86854eaafccc7128117f10b14.tar.bz2 askama-0330699a337f4bd86854eaafccc7128117f10b14.zip |
Add tests for calling methods on self
Diffstat (limited to '')
-rw-r--r-- | testing/tests/methods.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/testing/tests/methods.rs b/testing/tests/methods.rs new file mode 100644 index 0000000..f33441d --- /dev/null +++ b/testing/tests/methods.rs @@ -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"); +} |