diff --git a/test/clj_jtwig/core_test.clj b/test/clj_jtwig/core_test.clj index ee144b5..66015b2 100644 --- a/test/clj_jtwig/core_test.clj +++ b/test/clj_jtwig/core_test.clj @@ -14,6 +14,14 @@ ; Some of the variable passing and return / iteration verification tests might be a bit ; overkill, but better safe than sorry. :) +; TODO: is there a better way to test that something is an instance of some object generated by reify? +(defn valid-function-handler? [x] + (and (not (nil? x)) + (-> x + (class) + (.getName) + (.startsWith "clj_jtwig.core$add_function")))) + (deftest string-template (testing "Evaluating templates in string vars" (is (= (render "Hello {{ name }}!" @@ -123,8 +131,9 @@ (do (reset-functions!) - (is (nil? (deftwigfn "add" [a b] - (+ a b)))) + (is (valid-function-handler? + (deftwigfn "add" [a b] + (+ a b)))) (is (true? (function-exists? "add"))) (is (false? (function-exists? "foobar"))) @@ -150,11 +159,13 @@ (do (reset-functions!) - (is (nil? (deftwigfn "add2" [a b] - (+ a b)))) + (is (valid-function-handler? + (deftwigfn "add2" [a b] + (+ a b)))) (is (true? (function-exists? "add2"))) - (is (nil? (deftwigfn "addAll" [& numbers] - (apply + numbers)))) + (is (valid-function-handler? + (deftwigfn "addAll" [& numbers] + (apply + numbers)))) (is (true? (function-exists? "addAll"))) (is (= (render "{{add2(1, 2)}}" nil) @@ -176,11 +187,13 @@ (do (reset-functions!) - (is (nil? (deftwigfn "identity" [x] - x))) + (is (valid-function-handler? + (deftwigfn "identity" [x] + x))) (is (true? (function-exists? "identity"))) - (is (nil? (deftwigfn "typename" [x] - (.getName (type x))))) + (is (valid-function-handler? + (deftwigfn "typename" [x] + (.getName (type x))))) (is (true? (function-exists? "typename"))) ; verify that the clojure function recognizes the correct types when the variable is passed via the model-map