Skip to content

Commit

Permalink
CLJS-3130: UUID compares equal to other values
Browse files Browse the repository at this point in the history
  • Loading branch information
mfikes committed Jun 23, 2020
1 parent ba048aa commit 25c9587
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11293,8 +11293,10 @@ reduces them without incurring seq initialization"
__hash)

IComparable
(-compare [_ other]
(garray/defaultCompare uuid (.-uuid other))))
(-compare [this other]
(if (instance? UUID other)
(garray/defaultCompare uuid (.-uuid other))
(throw (js/Error. (str "Cannot compare " this " to " other))))))

(defn uuid [s]
(assert (string? s))
Expand Down
4 changes: 4 additions & 0 deletions src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,10 @@
(is (= "a" (get "abc" -0.5)))
(is (nil? (get "abc" -1))))

(deftest test-cljs-3130
(is (thrown-with-msg? js/Error #"Cannot compare f151d12d-7bd5-4409-9352-5900ee07baf7 to a"
(compare (uuid "f151d12d-7bd5-4409-9352-5900ee07baf7") "a"))))

(deftest test-cljs-3202
(is (= :/ (keyword "/")))
(is (= (hash :/) (hash (keyword "/")))))

0 comments on commit 25c9587

Please sign in to comment.