diff options
Diffstat (limited to 'test/clojure/test_clojure')
-rw-r--r-- | test/clojure/test_clojure/pprint/test_helper.clj | 9 | ||||
-rw-r--r-- | test/clojure/test_clojure/pprint/test_pretty.clj | 49 |
2 files changed, 56 insertions, 2 deletions
diff --git a/test/clojure/test_clojure/pprint/test_helper.clj b/test/clojure/test_clojure/pprint/test_helper.clj index 3cc31506..b59be6bb 100644 --- a/test/clojure/test_clojure/pprint/test_helper.clj +++ b/test/clojure/test_clojure/pprint/test_helper.clj @@ -15,8 +15,13 @@ ;; This is just a macro to make my tests a little cleaner (ns clojure.test-clojure.pprint.test-helper - (:use [clojure.test :only (deftest are run-tests)])) + (:use [clojure.test :only (deftest is)])) +(defn- back-match [x y] (re-matches y x)) (defmacro simple-tests [name & test-pairs] - `(deftest ~name (are [x y] (= x y) ~@test-pairs))) + `(deftest ~name + ~@(for [[x y] (partition 2 test-pairs)] + (if (instance? java.util.regex.Pattern y) + `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y)) + `(is (= ~x ~y)))))) diff --git a/test/clojure/test_clojure/pprint/test_pretty.clj b/test/clojure/test_clojure/pprint/test_pretty.clj index 5615da44..74513fe1 100644 --- a/test/clojure/test_clojure/pprint/test_pretty.clj +++ b/test/clojure/test_clojure/pprint/test_pretty.clj @@ -192,3 +192,52 @@ Usage: *hello* :else (multi-defn stuff (or doc-str attr-map))))) (pprint-simple-code-list writer alis))) ") + + +(defn tst-pprint + "A helper function to pprint to a string with a restricted right margin" + [right-margin obj] + (binding [*print-right-margin* right-margin + *print-pretty* true] + (write obj :stream nil))) + +;;; A bunch of predefined data to print +(def future-filled (future-call (fn [] 100))) +@future-filled +(def future-unfilled (future-call (fn [] (.acquire (java.util.concurrent.Semaphore. 0))))) +(def promise-filled (promise)) +(deliver promise-filled '(first second third)) +(def promise-unfilled (promise)) +(def basic-agent (agent '(first second third))) +(def basic-atom (atom '(first second third))) +(def basic-ref (ref '(first second third))) +(def delay-forced (delay '(first second third))) +(force delay-forced) +(def delay-unforced (delay '(first second third))) +(defrecord pprint-test-rec [a b c]) + + +(simple-tests pprint-datastructures-tests + (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \n 100>" + (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \n :pending>" + (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \n \(first\n second\n third\)>" + ;; This hangs currently, cause we can't figure out whether a promise is filled + ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \n :pending>" + (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \n \(first\n second\n third\)>" + (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \n \(first\n second\n third\)>" + (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \n \(first\n second\n third\)>" + (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \n \(first\n second\n third\)>" + ;; Currently no way not to force the delay + ;;(tst-pprint 20 delay-unforced) #"#<Delay@[0-9a-f]+: \n :pending>" + (tst-pprint 20 (pprint-test-rec. 'first 'second 'third)) "{:a first,\n :b second,\n :c third}" + + ;; basic java arrays: fails owing to assembla ticket #346 + ;;(tst-pprint 10 (int-array (range 7))) "[0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6]" + (tst-pprint 15 (reduce conj clojure.lang.PersistentQueue/EMPTY (range 10))) + "<-(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9)-<" + ) + + + + + |