Permalink
Browse files

CLJS-504: Empty arrays and strings don't seq as nil

Colin Jones' patch w/ fixed test and formatting.
  • Loading branch information...
swannodette committed May 7, 2013
1 parent 009db3c commit 49144218321bf8c355642fb683f197b05d6d9f8a
Showing with 9 additions and 2 deletions.
  1. +4 −2 src/cljs/cljs/core.cljs
  2. +5 −0 test/cljs/cljs/core_test.cljs
View
@@ -397,10 +397,12 @@
(-seq ^not-native coll)
(array? coll)
- (IndexedSeq. coll 0)
+ (when-not (zero? (alength coll))
+ (IndexedSeq. coll 0))
(string? coll)
- (IndexedSeq. coll 0)
+ (when-not (zero? (alength coll))
+ (IndexedSeq. coll 0))
(type_satisfies_ ILookup coll)
(-seq coll)
@@ -231,6 +231,10 @@
(assert (= [3 2 1] (seq (array 3 2 1))))
(assert (= 9 (reduce + (next (seq (array 1 2 3 4))))))
(assert (= () (rest nil)))
+ (assert (= nil (seq (array))))
+ (assert (= nil (seq "")))
+ (assert (= nil (seq [])))
+ (assert (= nil (seq {})))
(assert (= () (rest ())))
(assert (= () (rest [1])))
(assert (= () (rest (array 1))))
@@ -689,6 +693,7 @@
;; js->clj
(assert (= {"a" 1, "b" 2} (js->clj (js* "{\"a\":1,\"b\":2}"))))
(assert (= {"a" nil} (js->clj (js* "{\"a\":null}"))))
+ (assert (= {} (js->clj (js* "{}"))))
(assert (= {"a" true, "b" false} (js->clj (js* "{\"a\":true,\"b\":false}"))))
(assert (= {:a 1, :b 2} (js->clj (js* "{\"a\":1,\"b\":2}") :keywordize-keys true)))
(assert (= [[{:a 1, :b 2} {:a 1, :b 2}]]

0 comments on commit 4914421

Please sign in to comment.