aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/simple.rs
diff options
context:
space:
mode:
authorLibravatar Nathan Lapel <nathanlapel@gmail.com>2020-03-15 11:46:31 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-03-18 22:33:51 +0100
commit520c5d7d5f09c0b205e6e1c471483730380c5e33 (patch)
tree23b9c9560ebc78d74ddee2a71d48b3025659644e /testing/tests/simple.rs
parentcff49453a851029f87b35512f5234a999fea3e6c (diff)
downloadaskama-520c5d7d5f09c0b205e6e1c471483730380c5e33.tar.gz
askama-520c5d7d5f09c0b205e6e1c471483730380c5e33.tar.bz2
askama-520c5d7d5f09c0b205e6e1c471483730380c5e33.zip
Support function calls
Diffstat (limited to 'testing/tests/simple.rs')
-rw-r--r--testing/tests/simple.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs
index 3544599..3e156b4 100644
--- a/testing/tests/simple.rs
+++ b/testing/tests/simple.rs
@@ -263,6 +263,43 @@ fn test_slice_literal() {
}
#[derive(Template)]
+#[template(source = "Hello, {{ world(\"123\", 4) }}!", ext = "txt")]
+struct FunctionRefTemplate {
+ world: fn(s: &str, v: u8) -> String,
+}
+
+#[test]
+fn test_func_ref_call() {
+ let t = FunctionRefTemplate {
+ world: |s, r| format!("world({}, {})", s, r),
+ };
+ assert_eq!(t.render().unwrap(), "Hello, world(123, 4)!");
+}
+
+fn world2(s: &str, v: u8) -> String {
+ format!("world{}{}", v, s)
+}
+
+#[derive(Template)]
+#[template(source = "Hello, {{ self::world2(\"123\", 4) }}!", ext = "txt")]
+struct PathFunctionTemplate;
+
+#[test]
+fn test_path_func_call() {
+ assert_eq!(PathFunctionTemplate.render().unwrap(), "Hello, world4123!");
+}
+
+#[derive(Template)]
+#[template(source = "Hello, {{ Self::world3(self, \"123\", 4) }}!", ext = "txt")]
+struct FunctionTemplate;
+
+impl FunctionTemplate {
+ fn world3(&self, s: &str, v: u8) -> String {
+ format!("world{}{}", s, v)
+ }
+}
+
+#[derive(Template)]
#[template(source = " {# foo -#} ", ext = "txt")]
struct CommentTemplate {}