Skip to content

Commit bbcadde

Browse files
kamnswannodette
authored andcommitted
CLJS-1353: range inconsistent with Clojure if step is 0 Changed the implementation to match Clojure's and also updated tests. Used == instead of =
1 parent 19bcf10 commit bbcadde

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8430,11 +8430,10 @@ reduces them without incurring seq initialization"
84308430

84318431
ISeqable
84328432
(-seq [rng]
8433-
(if (pos? step)
8434-
(when (< start end)
8435-
rng)
8436-
(when (> start end)
8437-
rng)))
8433+
(cond
8434+
(pos? step) (when (< start end) rng)
8435+
(neg? step) (when (> start end) rng)
8436+
:else (when-not (== start end) rng)))
84388437

84398438
ISeq
84408439
(-first [rng]

src/test/cljs/cljs/core_test.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,11 @@
12211221
(is (= (range 0 -3 -1) (list 0 -1 -2)))
12221222
(is (= (range 3 0 -1) (list 3 2 1)))
12231223
(is (= (range 0 10 -1) (list)))
1224-
(is (= (range 0 1 0) (list)))
1224+
(is (= (take 3 (range 0 1 0)) (list 0 0 0)))
12251225
(is (= (range 10 0 1) (list)))
12261226
(is (= (range 0 0 0) (list)))
12271227
(is (= (count (range 0 10 -1)) 0))
1228-
(is (= (count (range 0 1 0)) 0))
1228+
(is (= (count (take 3 (range 0 2 0))) 3))
12291229
(is (= (count (range 10 0 1)) 0))
12301230
(is (= (count (range 0 0 0)) 0))
12311231
(is (= (take 3 (range 1 0 0)) (list 1 1 1)))

0 commit comments

Comments
 (0)