From 782fc5794209b296ccab7aadf8c5db50f8d52665 Mon Sep 17 00:00:00 2001 From: Brandon Bloom Date: Mon, 4 Jun 2012 18:42:08 -0700 Subject: [PATCH] Fix printing of RegExp objects --- src/cljs/cljs/core.cljs | 7 ++++++- test/cljs/cljs/core_test.cljs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs index c7d18ca..b0232c2 100644 --- a/src/cljs/cljs/core.cljs +++ b/src/cljs/cljs/core.cljs @@ -6029,6 +6029,9 @@ reduces them without incurring seq initialization" ;;;;;;;;;;;;;;;;;;;;;;;;; Regular Expressions ;;;;;;;;;; +(defn regexp? [o] + (js* "~{o} instanceof RegExp")) + (defn re-matches "Returns the result of (re-find re s) if re fully matches s." [re s] @@ -6093,10 +6096,12 @@ reduces them without incurring seq initialization" ;; handle CLJS ctors (and (not (nil? obj)) ^boolean (.-cljs$lang$type obj)) - (.cljs$lang$ctorPrSeq obj obj) + (.cljs$lang$ctorPrSeq obj obj) (satisfies? IPrintable obj) (-pr-seq obj opts) + (regexp? obj) (list "#\"" (.-source obj) "\"") + :else (list "#<" (str obj) ">"))))) (defn- pr-sb [objs opts] diff --git a/test/cljs/cljs/core_test.cljs b/test/cljs/cljs/core_test.cljs index 792ed7e..f31d543 100644 --- a/test/cljs/cljs/core_test.cljs +++ b/test/cljs/cljs/core_test.cljs @@ -213,8 +213,8 @@ (assoc (cljs.core.ObjMap. nil (array) (js-obj)) :foo 5))) (assert (= "\"asdf\"" (pr-str "asdf"))) - (assert (= "[1 true {:a 2, :b 42} #]" - (pr-str [1 true {:a 2 :b 42} (array 3 4)]))) + (assert (= "[1 true {:a 2, :b #\"x\\\"y\"} #]" + (pr-str [1 true {:a 2 :b #"x\"y"} (array 3 4)]))) (assert (= "\"asdf\"\n" (prn-str "asdf"))) (assert (= "[1 true {:a 2, :b 42} #]\n" -- 1.7.9.1