File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8282 (print-method x w))
8383 nil ))
8484
85+ #?(:clj (defn core-pr-on
86+ " Prints x to w under the interpreter's print settings. Exposed as the
87+ private clojure.core/pr-on, which host code reaches through the var. The
88+ host's own pr-on binds nothing, because there these settings are already
89+ the ones in effect."
90+ [x w]
91+ (binding [*print-length* @print-length
92+ *print-level* @print-level
93+ *print-meta* @print-meta
94+ *print-namespace-maps* @print-namespace-maps
95+ *print-readably* @print-readably
96+ *print-dup* @print-dup-var]
97+ (pr-on x w))))
98+
8599#?(:cljd (defn pr
86100 [& objs]
87101 (binding [*out* @out
Original file line number Diff line number Diff line change 13661366 'newline (copy-var sci.impl.io/newline clojure-core-ns {:name 'newline})
13671367 'flush (copy-core-var sci.impl.io/flush)
13681368 'pr (copy-var sci.impl.io/pr clojure-core-ns {:name 'pr})
1369+ #?@(:clj ['pr-on (new-var 'pr-on sci.impl.io/core-pr-on clojure-core-ns {:private true })])
13691370 'prn (copy-core-var sci.impl.io/prn)
13701371 'print (copy-core-var sci.impl.io/print)
13711372 'println (copy-core-var sci.impl.io/println)
Original file line number Diff line number Diff line change 22 (:require
33 [clojure.edn :as edn]
44 [clojure.string :as str]
5- [clojure.test :as test :refer [deftest is]]
5+ [clojure.test :as test :refer [deftest is testing ]]
66 [sci.core :as sci]
77 [sci.test-utils :as tu]))
88
3737 (is (= " \" hello\" " (sci/with-out-str (eval* " (pr \" hello\" )" ))))
3838 (is (= " \n " (sci/with-out-str (eval* " (newline)" ))))))
3939
40+ #?(:cljd nil
41+ :clj
42+ (deftest pr-on-test
43+ (when-not tu/native?
44+ (testing " clojure.core/pr-on prints to the writer it is given"
45+ (let [w (java.io.StringWriter. )]
46+ (tu/eval* " (@#'clojure.core/pr-on (range 5) w)" {:namespaces {'user {'w w}}})
47+ (is (= " (0 1 2 3 4)" (str w)))))
48+ (testing " and under the interpreter's print settings"
49+ (let [w (java.io.StringWriter. )]
50+ (tu/eval* " (binding [*print-length* 3] (@#'clojure.core/pr-on (range 10) w))"
51+ {:namespaces {'user {'w w}}})
52+ (is (= " (0 1 2 ...)" (str w))))))))
53+
4054(deftest print-length-test
4155 (when-not tu/native?
4256 (is (str/includes?
You can’t perform that action at this time.
0 commit comments