Skip to content

Commit c7082b4

Browse files
tonskyswannodette
authored andcommitted
CLJS-1201 Empty Vectors and Subvecs throw on comparison
1 parent 53780c6 commit c7082b4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/cljs/cljs/core.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,7 @@ reduces them without incurring seq initialization"
19381938
(cond
19391939
(< xl yl) -1
19401940
(> xl yl) 1
1941+
(== xl 0) 0
19411942
:else (compare-indexed xs ys xl 0))))
19421943
([xs ys len n]
19431944
(let [d (compare (nth xs n) (nth ys n))]

test/cljs/cljs/core_test.cljs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,18 +1679,23 @@
16791679
(is (= 1 (compare [1 2] [1 1])))
16801680
(is (= 1 (compare [1 1 1] [1 2])))
16811681
(is (= 1 (compare [1 1 2] [1 1 1])))
1682+
(is (= 0 (compare [] [])))
1683+
(is (= 0 (compare (vec #js []) [])))
1684+
(is (= 0 (compare (with-meta [] {}) [])))
1685+
(is (= 0 (compare (pop [1]) [])))
16821686

16831687
(is (= -1 (compare (subvec [1 2 3] 1) (subvec [1 2 4] 1))))
16841688
(is (= 0 (compare (subvec [1 2 3] 1) (subvec [1 2 3] 1))))
1685-
(is (= 1 (compare (subvec [1 2 4] 1) (subvec [1 2 3] 1)))))
1689+
(is (= 1 (compare (subvec [1 2 4] 1) (subvec [1 2 3] 1))))
1690+
(is (= 0 (compare (subvec [1] 0 0) (subvec [2] 0 0))))
16861691

16871692
(is (= 0 (compare (js/Date. 2015 2 8 19 13 00 999)
16881693
(js/Date. 2015 2 8 19 13 00 999))))
16891694
(is (= -1 (compare (js/Date. 2015 2 8 19 12 00 999)
16901695
(js/Date. 2015 2 8 19 13 00 999))))
16911696
(is (= 1 (compare (js/Date. 2015 2 8 19 14 00 999)
16921697
(js/Date. 2015 2 8 19 13 00 999))))
1693-
)
1698+
))
16941699

16951700
(deftest test-dot
16961701
(let [s "abc"]

0 commit comments

Comments
 (0)