From 9cd705f858d38e4a37753fd2b1bb75077b4a0b15 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 1 Mar 2014 14:43:40 -0500 Subject: [PATCH] add tests for rendering from a file --- test/clj_jtwig/core_test.clj | 34 ++++++++++++++++++++++++++ test/templates/file-template-test.twig | 1 + 2 files changed, 35 insertions(+) create mode 100644 test/templates/file-template-test.twig diff --git a/test/clj_jtwig/core_test.clj b/test/clj_jtwig/core_test.clj index 1aaba60..8310533 100644 --- a/test/clj_jtwig/core_test.clj +++ b/test/clj_jtwig/core_test.clj @@ -1,4 +1,5 @@ (ns clj-jtwig.core-test + (:import (java.io FileNotFoundException)) (:require [clojure.test :refer :all] [clj-jtwig.core :refer :all])) @@ -79,3 +80,36 @@ :v [10 100 1000]}}) "abc, 1337, 10 100 1000 ") "passing a map with primitives / nested maps / sequences"))) + +(deftest file-templates + (testing "Evaluating templates from files" + (let [test-filename "test/templates/file-template-test.twig" + invalid-filename "test/templates/nonexistant.twig"] + (is (= (render-file test-filename + {:name "Bob"}) + "Hello Bob from a file!") + "passing a model-map") + (is (thrown? + FileNotFoundException + (render-file invalid-filename + {:name "Bob"})) + "trying to render a file that doesn't exist") + (is (= (render-file test-filename + nil) + "Hello null from a file!") + "not passing a model-map") + (is (= (render-file test-filename + {"name" "Bob"}) + "Hello Bob from a file!") + "passing a model-map where the keys are strings already") + (is (= (render-file test-filename + {"name" "Bob"} + {:skip-model-map-stringify? true}) + "Hello Bob from a file!") + "passing a model-map where the keys are strings already and we want to skip auto stringifying bbb") + (is (thrown? + ClassCastException + (render-file test-filename + {:name "Bob"} + {:skip-model-map-stringify? true})) + "passing a model-map where the keys are keywords and try skipping auto stringifying the keys")))) \ No newline at end of file diff --git a/test/templates/file-template-test.twig b/test/templates/file-template-test.twig new file mode 100644 index 0000000..0dd95e8 --- /dev/null +++ b/test/templates/file-template-test.twig @@ -0,0 +1 @@ +Hello {{name}} from a file! \ No newline at end of file