From 0624425e614621438478866cb8a89cfc10e9f4f4 Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 4 Mar 2014 14:41:46 -0500 Subject: [PATCH] add tests for template function aliases --- test/clj_jtwig/functions_test.clj | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index 09be3ba..a7a9152 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -39,6 +39,31 @@ (reset-functions!))) + (testing "Custom template function aliases" + (do + (reset-functions!) + + (is (valid-function-handler? + (defaliasedtwigfn "add" [a b] + ["plus" "myAddFn"] + (+ a b)))) + + (is (true? (function-exists? "add"))) + (is (true? (function-exists? "plus"))) + (is (true? (function-exists? "myAddFn"))) + + (is (= (render "{{add(1, 2)}}" nil) + "3") + "calling a custom function by name") + (is (= (render "{{plus(1, 2)}}" nil) + "3") + "calling a custom function by alias") + (is (= (render "{{myAddFn(1, 2)}}" nil) + "3") + "calling a custom function by another alias") + + (reset-functions!))) + (testing "Fixed and variable number of template function arguments" (do (reset-functions!)