Skip to content

Commit

Permalink
Improve test for type escaping and print fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed Mar 7, 2015
1 parent a154ccb commit bd3c015
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions test/puget/printer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,33 @@
(is (= "#frobble/biznar\n[:foo :bar :baz]" (pprint-str tv)))))


(deftype ComplexValue []
Object
(toString [_] "to-string"))

(defmethod print-method ComplexValue
[this w]
(.write w "{{ complex value print }}"))

(data/extend-tagged-str ComplexValue 'complex/val)


(deftest default-formatting
(testing "Unknown values"
(let [usd (java.util.Currency/getInstance "USD")]
(should-fail-when-strict usd)
(is (re-seq #"#<java\.util\.Currency@[0-9a-f]+ USD>" (pprint-str usd)))
(with-options {:print-fallback :print
:escape-types #{'puget.printer_test.TestRecord}}
(is (= "#<Currency USD>" (pprint-str usd)))))))
(with-options {:print-fallback :print}
(is (= "#<Currency USD>" (pprint-str usd))))))
(testing "Escaped types"
(let [cv (ComplexValue.)]
(with-options {:escape-types nil}
(is (= "#complex/val \"to-string\"" (pprint-str cv))))
(with-options {:escape-types #{'puget.printer_test.ComplexValue}}
(is (re-seq #"#<puget\.printer_test\.ComplexValue@[0-9a-f]+ to-string>" (pprint-str cv))))
(with-options {:escape-types #{'puget.printer_test.ComplexValue}
:print-fallback :print}
(is (= "{{ complex value print }}" (pprint-str cv)))))))


(deftest metadata-printing
Expand Down

0 comments on commit bd3c015

Please sign in to comment.