diff --git a/src/pjstadig/humane_test_output.clj b/src/pjstadig/humane_test_output.clj index d086e66..c9764a3 100644 --- a/src/pjstadig/humane_test_output.clj +++ b/src/pjstadig/humane_test_output.clj @@ -1,5 +1,6 @@ (ns pjstadig.humane-test-output - (:use [clojure.test]) + (:use [clojure.test] + [pjstadig.util]) (:require [clojure.data :as data] [clojure.pprint :as pp])) @@ -55,22 +56,7 @@ (print-expected actual)))))) ;; this code is just yanked from clojure.pprint (defmethod pp/simple-dispatch clojure.lang.IRecord [arec] - (pp/pprint-logical-block - :prefix (str "#" (.getName (class arec)) "{") :suffix "}" - (pp/print-length-loop - [aseq (seq arec)] - (when aseq - (pp/pprint-logical-block - (pp/write-out (ffirst aseq)) - (.write ^java.io.Writer *out* " ") - (pp/pprint-newline :linear) - ;; [pjs] this is kind of ugly, but it is a private var :( - (.set #'pp/*current-length* 0) ; always print both parts of the [k v] pair - (pp/write-out (fnext (first aseq)))) - (when (next aseq) - (.write ^java.io.Writer *out* ", ") - (pp/pprint-newline :linear) - (recur (next aseq))))))) + (pprint-record arec)) (prefer-method pp/simple-dispatch clojure.lang.IRecord clojure.lang.IPersistentMap)))) diff --git a/src/pjstadig/util.cljc b/src/pjstadig/util.cljc new file mode 100644 index 0000000..2146f26 --- /dev/null +++ b/src/pjstadig/util.cljc @@ -0,0 +1,29 @@ +(ns pjstadig.util + (:require #?(:clj [clojure.pprint :as pp] + :cljs [cljs.pprint :as pp :include-macros true]))) + +(defn- print-seq [aseq] + (pp/pprint-logical-block + (pp/write-out (ffirst aseq)) + (print " ") + (pp/pprint-newline :linear) + ;; [pjs] this is kind of ugly, but it is a private var :( + ;; always print both parts of the [k v] pair + #?(:clj (.set #'pp/*current-length* 0) + :cljs (set! pp/*current-length* 0)) + (pp/write-out (fnext (first aseq))))) + + +(defn pprint-record [arec] + (pp/pprint-logical-block + #?@(:clj [:prefix (str "#" (.getName (class arec)) "{") :suffix "}"] + :cljs [:prefix (re-find #".*?\{" (with-out-str (print arec))) :suffix "}"]) + (pp/print-length-loop + [aseq (seq arec)] + (when aseq + (print-seq aseq) + (when (next aseq) + (print ", ") + (pp/pprint-newline :linear) + (recur (next aseq))))))) + diff --git a/test/pjstadig/run_all.cljs b/test/pjstadig/run_all.cljs index 51af3bd..6f2e87f 100644 --- a/test/pjstadig/run_all.cljs +++ b/test/pjstadig/run_all.cljs @@ -6,34 +6,17 @@ [pjstadig.humane-test-output.records-test] [clojure.data :refer [diff]] [cljs.pprint :as pp] - [pjstadig.macro :refer [do-report]]) + [pjstadig.macro :refer [do-report]] + [pjstadig.util :as util]) (:require-macros [pjstadig.assert-expr])) (enable-console-print!) (def pprint-map (get-method pp/simple-dispatch :map)) -(defn pprint-record [arec] - (pp/pprint-logical-block - :prefix (re-find #".*?\{" (with-out-str (print arec))) :suffix "}" - (pp/print-length-loop - [aseq (seq arec)] - (when aseq - (pp/pprint-logical-block - (pp/write-out (ffirst aseq)) - (print " ") - (pp/pprint-newline :linear) - ;; [pjs] this is kind of ugly, but it is a private var :( - (set! pp/*current-length* 0) ; always print both parts of the [k v] pair - (pp/write-out (fnext (first aseq)))) - (when (next aseq) - (print ", ") - (pp/pprint-newline :linear) - (recur (next aseq))))))) - (defmethod pp/simple-dispatch :map [amap] (if (record? amap) - (pprint-record amap) + (util/pprint-record amap) (pprint-map amap))) (defmethod cljs.test/report [:cljs.test/default :fail]