Skip to content

Commit b8101e6

Browse files
jeremyrsellarsswannodette
authored andcommitted
CLJS-2731: Failure comparing sorted sets
Catch comparison errors in PersistentTreeSet and PersistentHashSet .-equiv when compared with sorted sets.
1 parent 6950aff commit b8101e6

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9085,9 +9085,12 @@ reduces them without incurring seq initialization"
90859085
(set? other)
90869086
(== (count coll) (count other))
90879087
^boolean
9088-
(reduce-kv
9089-
#(or (contains? other %2) (reduced false))
9090-
true hash-map)))
9088+
(try
9089+
(reduce-kv
9090+
#(or (contains? other %2) (reduced false))
9091+
true hash-map)
9092+
(catch js/Error ex
9093+
false))))
90919094

90929095
IHash
90939096
(-hash [coll] (caching-hash coll hash-unordered-coll __hash))
@@ -9236,9 +9239,12 @@ reduces them without incurring seq initialization"
92369239
(set? other)
92379240
(== (count coll) (count other))
92389241
^boolean
9239-
(reduce-kv
9240-
#(or (contains? other %2) (reduced false))
9241-
true tree-map)))
9242+
(try
9243+
(reduce-kv
9244+
#(or (contains? other %2) (reduced false))
9245+
true tree-map)
9246+
(catch js/Error ex
9247+
false))))
92429248

92439249
IHash
92449250
(-hash [coll] (caching-hash coll hash-unordered-coll __hash))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(ns cljs.set-equiv-test
2+
(:refer-clojure :exclude [iter])
3+
(:require [cljs.test :refer-macros [deftest testing is]]
4+
[clojure.string :as s]
5+
[clojure.set :as set]))
6+
7+
(deftest test-set-equality
8+
(testing "Testing set equality"
9+
(is (= (sorted-set 3 2 1) (sorted-set 1 2 3)))
10+
(is (= (hash-set 3 2 1) (sorted-set 1 2 3)))
11+
(is (= (sorted-set :a :b :c) (hash-set :a :b :c)))
12+
(is (= (hash-set :a :b :c) (hash-set :a :b :c))))
13+
14+
(testing "CLJS-2731 uncomparable values"
15+
(is (not= (sorted-set 3 2 1) (sorted-set :a :b :c)))
16+
(is (not= (hash-set 3 2 1) (sorted-set :a :b :c)))
17+
(is (not= (sorted-set 3 2 1) (hash-set :a :b :c)))
18+
(is (not= (hash-set 3 2 1) (hash-set :a :b :c)))))

src/test/self/self_parity/test.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
[cljs.clojure-alias-test]
304304
[cljs.hash-map-test]
305305
[cljs.map-entry-test]
306+
[cljs.set-equiv-test]
306307
[cljs.syntax-quote-test]
307308
[cljs.predicates-test]
308309
[cljs.test-test]
@@ -345,6 +346,7 @@
345346
'cljs.clojure-alias-test
346347
'cljs.hash-map-test
347348
'cljs.map-entry-test
349+
'cljs.set-equiv-test
348350
'cljs.syntax-quote-test
349351
'cljs.predicates-test
350352
'cljs.test-test

0 commit comments

Comments
 (0)