From b6e65c08a8fef8d04d9ad46685a99b4902e52e89 Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 10 Jul 2021 15:39:23 -0400 Subject: [PATCH] add cl-format tests for nil and Writer args (#931) --- test/babashka/main_test.clj | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index ead8de87..22f57620 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -462,8 +462,16 @@ (clojure.pprint/pprint (range 10) sw)) (str sw))")))) (testing "print-table writes to sci/out" (is (str/includes? (test-utils/bb "(with-out-str (clojure.pprint/print-table [{:a 1} {:a 2}]))") "----"))) - (testing "cl-format writes to sci/out" - (is (= "[1, 2, 3]" (bb nil "(with-out-str (clojure.pprint/cl-format true \"~<[~;~@{~w~^, ~:_~}~;]~:>\" [1,2,3]))")))) + (testing "cl-format outputs" + (testing "cl-format true writes to sci/out" + (is (= "[1, 2, 3]" (bb nil "(with-out-str (clojure.pprint/cl-format true \"~<[~;~@{~w~^, ~:_~}~;]~:>\" [1,2,3]))")))) + (testing "cl-format nil returns a string" + (is (= "forty-two" (bb nil "(clojure.pprint/cl-format nil \"~R\" 42)")))) + (testing "cl-format with a writer uses the writer" + (is (= "1,234,567 " (bb nil " +(let [sw (java.io.StringWriter.)] + (clojure.pprint/cl-format sw \"~15@<~:d~>\" 1234567) + (str sw))"))))) (testing "formatter-out" (is (= "[1, 2, 3]\n" (bb nil (pr-str '(do (require '[clojure.pprint :as pprint])