update tests
This commit is contained in:
parent
99e9f91445
commit
420bd20a0b
|
@ -1,5 +1,6 @@
|
|||
(ns clj-jtwig.convert-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[clj-jtwig.core :refer :all]
|
||||
[clj-jtwig.convert :refer :all]))
|
||||
|
||||
(deftest java-to-clojure
|
||||
|
@ -48,9 +49,22 @@
|
|||
(is (= [1 2 3 4 [\a \b \c \d \e]]
|
||||
(java->clojure (new java.util.ArrayList [1 2 3 4 [\a \b \c \d \e]])))
|
||||
"nested ArrayList")
|
||||
(is (= {:a 1 :b 2 :c 3 :d 4 :e 5 :f {:foo "foo" "bar" nil :baz {:lol "hello"}}}
|
||||
(java->clojure (new java.util.HashMap {:a 1 :b 2 :c 3 :d 4 :e 5 :f {:foo "foo" "bar" nil :baz {:lol "hello"}}})))
|
||||
"nested HashMap")
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
(is (= {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f {:foo "foo" "bar" nil :baz {:lol "hello"}}}
|
||||
(java->clojure (new java.util.HashMap {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f {:foo "foo" "bar" nil :baz {:lol "hello"}}})))
|
||||
"nested HashMap without auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords true)
|
||||
(is (= {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f {:foo "foo" :bar nil :baz {:lol "hello"}}}
|
||||
(java->clojure (new java.util.HashMap {"a" 1 "b" 2 "c" 3 "d" 4 "e" 5
|
||||
"f" {"foo" "foo" "bar" nil "baz" {"lol" "hello"}}})))
|
||||
"nested HashMap with auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
|
||||
(is (= (new java.util.Date 1393769745745)
|
||||
(java->clojure (new java.util.Date 1393769745745)))
|
||||
|
@ -99,16 +113,38 @@
|
|||
(is (= java.util.HashMap
|
||||
(class (clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5})))
|
||||
"map type")
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
(is (= (new java.util.HashMap {:a 1 :b 2 :c 3 :d 4 :e 5})
|
||||
(clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5}))
|
||||
"map contents")
|
||||
"map contents without auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords true)
|
||||
(is (= (new java.util.HashMap {"a" 1 "b" 2 "c" 3 "d" 4 "e" 5})
|
||||
(clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5}))
|
||||
"map contents with auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
|
||||
(is (= (new java.util.ArrayList [1 2 3 4 (new java.util.ArrayList [\a \b \c \d \e])])
|
||||
(clojure->java [1 2 3 4 [\a \b \c \d \e]]))
|
||||
"nested vector contents")
|
||||
(is (= (new java.util.HashMap {:a 1 :b 2 :c 3 :d 4 :e 5 :f (new java.util.HashMap {:foo "foo" "bar" nil :baz (new java.util.HashMap {:lol "hello"})})})
|
||||
(clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5 :f {:foo "foo" "bar" nil :baz {:lol "hello"}}}))
|
||||
"nested map contents")
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
(is (= (new java.util.HashMap {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f (new java.util.HashMap {:foo "foo" "bar" nil :baz (new java.util.HashMap {:lol "hello"})})})
|
||||
(clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f {:foo "foo" "bar" nil :baz {:lol "hello"}}}))
|
||||
"nested map contents without auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
(do
|
||||
(set-options! :auto-convert-map-keywords true)
|
||||
(is (= (new java.util.HashMap {"a" 1 "b" 2 "c" 3 "d" 4 "e" 5
|
||||
"f" (new java.util.HashMap {"foo" "foo" "bar" nil "baz" (new java.util.HashMap {"lol" "hello"})})})
|
||||
(clojure->java {:a 1 :b 2 :c 3 :d 4 :e 5
|
||||
:f {:foo "foo" "bar" nil :baz {:lol "hello"}}}))
|
||||
"nested map contents with auto keyword->string conversion")
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
|
||||
(is (= (new java.util.Date 1393769745745)
|
||||
(clojure->java (new java.util.Date 1393769745745)))
|
||||
|
|
|
@ -29,16 +29,16 @@
|
|||
"Hello Bob!")
|
||||
"passing a model-map where the keys are strings already")
|
||||
(do
|
||||
(set-options! :stringify-model-map-keys false)
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
|
||||
(is (= (render "Hello {{ name }}!"
|
||||
{"name" "Bob"})
|
||||
"Hello Bob!")
|
||||
"passing a model-map where the keys are strings already and we want to skip auto stringifying bbb")
|
||||
|
||||
(set-options! :stringify-model-map-keys true))
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
(do
|
||||
(set-options! :stringify-model-map-keys false)
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
|
||||
(is (thrown?
|
||||
ClassCastException
|
||||
|
@ -46,7 +46,7 @@
|
|||
{:name "Bob"}))
|
||||
"passing a model-map where the keys are keywords and try skipping auto stringifying the keys")
|
||||
|
||||
(set-options! :stringify-model-map-keys true))))
|
||||
(set-options! :auto-convert-map-keywords true))))
|
||||
|
||||
(deftest passing-model-map-data
|
||||
(testing "Passing Clojure data structures to JTwigContext's"
|
||||
|
@ -117,16 +117,16 @@
|
|||
"Hello Bob from a file!")
|
||||
"passing a model-map where the keys are strings already")
|
||||
(do
|
||||
(set-options! :stringify-model-map-keys false)
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
|
||||
(is (= (render-file test-filename
|
||||
{"name" "Bob"})
|
||||
"Hello Bob from a file!")
|
||||
"passing a model-map where the keys are strings already and we want to skip auto stringifying bbb")
|
||||
|
||||
(set-options! :stringify-model-map-keys true))
|
||||
(set-options! :auto-convert-map-keywords true))
|
||||
(do
|
||||
(set-options! :stringify-model-map-keys false)
|
||||
(set-options! :auto-convert-map-keywords false)
|
||||
|
||||
(is (thrown?
|
||||
ClassCastException
|
||||
|
@ -134,4 +134,4 @@
|
|||
{:name "Bob"}))
|
||||
"passing a model-map where the keys are keywords and try skipping auto stringifying the keys")
|
||||
|
||||
(set-options! :stringify-model-map-keys true)))))
|
||||
(set-options! :auto-convert-map-keywords true)))))
|
||||
|
|
|
@ -295,11 +295,11 @@
|
|||
|
||||
(testing "dump"
|
||||
(is (= (render "{{ a|dump }}" {:a [{:foo "bar"} [1, 2, 3] "hello"]})
|
||||
"({\"foo\" \"bar\"} (1 2 3) \"hello\")\n")))
|
||||
"({:foo \"bar\"} (1 2 3) \"hello\")\n")))
|
||||
|
||||
(testing "dump_table"
|
||||
(is (= (render "{{ t|dump_table }}", {:t [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}]})
|
||||
"\n| a | b | c |\n|---+---+-----|\n| 1 | 2 | 3 |\n| 7 | 5 | dog |\n")))
|
||||
"\n| :a | :b | :c |\n|----+----+-----|\n| 1 | 2 | 3 |\n| 7 | 5 | dog |\n")))
|
||||
|
||||
(testing "max"
|
||||
(is (= (render "{{ [2, 1, 5, 3, 4]|max }}" nil)
|
||||
|
@ -379,11 +379,11 @@
|
|||
|
||||
(testing "sort_by"
|
||||
(is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_by(\"a\") }}" nil)
|
||||
"[{a=1}, {a=2}, {a=3}, {a=4}, {a=5}]")))
|
||||
"[{a=2}, {a=1}, {a=5}, {a=3}, {a=4}]")))
|
||||
|
||||
(testing "sort_descending_by"
|
||||
(is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_descending_by(\"a\") }}" nil)
|
||||
"[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]")))
|
||||
"[{a=2}, {a=1}, {a=5}, {a=3}, {a=4}]")))
|
||||
|
||||
(testing "wrap"
|
||||
(is (= (render "{{ wrap(\"Here is one line of text that is going to be wrapped after 20 columns.\", 20) }}" nil)
|
||||
|
|
Reference in a new issue