File tree 2 files changed +34
-12
lines changed
test/clojure/test_clojure/pprint
2 files changed +34
-12
lines changed Original file line number Diff line number Diff line change 20
20
(fn [k]
21
21
(apply max (count (str k)) (map #(count (str (get % k))) rows)))
22
22
ks)
23
- fmts (map #(str " %-" % " s" ) widths)
24
- fmt-row (fn [row]
25
- (apply str (interpose " | "
26
- (for [[col fmt] (map vector (map #(get row %) ks) fmts)]
27
- (format fmt (str col))))))
28
- header (fmt-row (zipmap ks ks))
29
- bar (apply str (repeat (count header) " =" ))]
30
- (println bar)
31
- (println header)
32
- (println bar)
23
+ spacers (map #(apply str (repeat % " -" )) widths)
24
+ fmts (map #(str " %" % " s" ) widths)
25
+ fmt-row (fn [leader divider trailer row]
26
+ (str leader
27
+ (apply str (interpose divider
28
+ (for [[col fmt] (map vector (map #(get row %) ks) fmts)]
29
+ (format fmt (str col)))))
30
+ trailer))]
31
+ (println )
32
+ (println (fmt-row " | " " | " " |" (zipmap ks ks)))
33
+ (println (fmt-row " |-" " -+-" " -|" (zipmap ks spacers)))
33
34
(doseq [row rows]
34
- (println (fmt-row row)))
35
- (println bar))))
35
+ (println (fmt-row " | " " | " " |" row))))))
36
36
([rows] (print-table (keys (first rows)) rows)))
Original file line number Diff line number Diff line change @@ -759,3 +759,25 @@ but it was called with an argument of type short-float.\n")
759
759
'((hot dog) (hamburger ) (ice cream) (french fries)))
760
760
" /hot .../hamburger" )
761
761
762
+ (simple-tests pprint-table-tests
763
+ (with-out-str
764
+ (print-table [:b :a ]
765
+ [{:a 1 :b {:a 'is-a} :c [" hi" " there" ]}
766
+ {:b 5 :a 7 :c " dog" :d -700 }]))
767
+ "
768
+ | :b | :a |
769
+ |-----------+----|
770
+ | {:a is-a} | 1 |
771
+ | 5 | 7 |
772
+ "
773
+ (with-out-str
774
+ (print-table [:a :e :d :c ]
775
+ [{:a 54.7e17 :b {:a 'is-a} :c [" hi" " there" ]}
776
+ {:b 5 :a -2/3 :c " dog" :d 'panda}]))
777
+ "
778
+ | :a | :e | :d | :c |
779
+ |---------+----+-------+----------------|
780
+ | 5.47E18 | | | [\" hi\" \" there\" ] |
781
+ | -2/3 | | panda | dog |
782
+ "
783
+ )
You can’t perform that action at this time.
0 commit comments