Skip to content
Browse files

* src/clj/cljs/core.clj: CLJS-162: fix broken str implementation

`str` was using the `str*` internally when called with multiple arity
arguments, this was causing symbols and keywords to not behave correctly
on the `str` function.

NOTE: Some tests are being added with this code.
  • Loading branch information...
1 parent aa51a01 commit ec75a897fc7069176aff81e2df91b848c26af1c8 @roman roman committed with David Nolen Mar 19, 2012
Showing with 19 additions and 9 deletions.
  1. +7 −3 src/cljs/cljs/core.cljs
  2. +12 −6 test/cljs/cljs/core_test.cljs
View
10 src/cljs/cljs/core.cljs
@@ -1030,6 +1030,8 @@ reduces them without incurring seq initialization"
;;;;;;;;;;;;;;;;;;;;;;;;;; basics ;;;;;;;;;;;;;;;;;;
+(declare apply)
+
(defn- str*
"Internal - do not use!"
([] "")
@@ -1043,8 +1045,6 @@ reduces them without incurring seq initialization"
(str* sb)))
(gstring/StringBuffer. (str* x)) ys)))
-(declare apply)
-
(defn str
"With no args, returns the empty string. With one arg x, returns
x.toString(). (str nil) returns the empty string. With more than
@@ -1056,7 +1056,11 @@ reduces them without incurring seq initialization"
(nil? x) ""
:else (. x (toString))))
([x & ys]
- (apply str* x ys)))
+ ((fn [sb more]
+ (if more
+ (recur (. sb (append (str (first more)))) (next more))
+ (str* sb)))
+ (gstring/StringBuffer. (str x)) ys)))
(defn subs
"Returns the substring of s beginning at start inclusive, and ending
View
18 test/cljs/cljs/core_test.cljs
@@ -160,6 +160,12 @@
(assert (= "baz" (name :foo/bar/baz)))
;(assert (= "foo/bar" (namespace :foo/bar/baz)))
+ ; str
+ (assert (= ":hello" (str :hello)))
+ (assert (= "hello" (str 'hello)))
+ (assert (= "hello:world" (str "hello" :world)))
+ (assert (= ":helloworld" (str :hello 'world)))
+
(assert (= {:a :b} (get {[1 2 3] {:a :b}, 4 5} [1 2 3])))
(assert (= :a (nth [:a :b :c :d] 0)))
(assert (= :a (nth [:a :b :c :d] 0.1)) )
@@ -925,7 +931,7 @@
(map->Person {:firstname "Fred" :lastname "Mertz" :wife :ethel})))
(assert (= (dissoc ethel :husband)
(map->Person {:firstname "Ethel" :lastname "Mertz"})))
-
+
(defrecord A [x])
(defrecord B [x])
(assert (not= (A. nil) (B. nil)))
@@ -946,22 +952,22 @@
(defmulti foo identity)
(defmethod foo 0 [x] x)
(assert (= foo (ffirst {foo 1})))
-
+
(defprotocol IMutate
(mutate [this]))
-
+
(deftype Mutate [^:mutable a]
IMutate
(mutate [_]
(set! a 'foo)))
-
+
;; IFn
(deftype FnLike []
IFn
(-invoke [_] :a)
(-invoke [_ a] :b)
(-invoke [_ a b] :c))
-
+
(assert (= :a ((FnLike.))))
(assert (= :b ((FnLike.) 1)))
(assert (= :c ((FnLike.) 1 2)))
@@ -973,7 +979,7 @@
(-invoke [_] a))
(assert (= 1 ((FnLikeB. 1))))
-
+
;; hashing bug in many JS runtimes CLJ-118
(let [g #{(conj #{:2} :alt)}
h #{#{:2 :alt}}]

0 comments on commit ec75a89

Please sign in to comment.
Something went wrong with that request. Please try again.