Add equality test for cursor

This commit is contained in:
Dan Holmsand 2014-11-22 10:45:36 +01:00
parent 30427973d6
commit f94fcd5542
1 changed files with 41 additions and 8 deletions

View File

@ -4,7 +4,8 @@
[reagent.ratom :refer [run! reaction]]
[reagent.debug :refer [dbg]])
(:require [cemerick.cljs.test :as t]
[reagent.ratom :as rv]))
[reagent.ratom :as rv]
[reagent.core :as r]))
;; this repeats all the atom tests but using cursors instead
@ -256,3 +257,35 @@
(is (= {:set 11} @a-base))
(is (= runs (running)))))
(deftest test-equality
(let [a (atom {:foo "bar"})
a1 (atom {:foo "bar"})
c (r/cursor [:foo] a)
c2 (r/cursor [:foo] a swap! a assoc :foo)
c3 (r/cursor [:foo] a swap! a assoc :foobar)]
(is (= @c "bar"))
(is (= @c2 "bar"))
(is (= @c3 "bar"))
(is (= c (r/cursor [:foo] a)))
(is (not= c (r/cursor [:foo] a1)))
(is (not= c (r/cursor [:foobar] a)))
(is (= c2 (r/cursor [:foo] a swap! a assoc :foo)))
(is (not= c2 (r/cursor [:foo] a swap! a assoc :foobar)))
(is (not= c2 (r/cursor [:foo] a1 swap! a assoc :foo)))
(is (not= c2 (r/cursor [:foo] a swap! a1 assoc :foo)))
(reset! c2 "foobar")
(is (= @c2 "foobar"))
(is (= @c "foobar"))
(is (= @a {:foo "foobar"}))
(reset! c "bar")
(is (= @c2 "bar"))
(is (= @c "bar"))
(is (= @a {:foo "bar"}))
(is (= c (r/cursor [:foo] a)))
(is (= c2 (r/cursor [:foo] a swap! a assoc :foo)))
(reset! c3 "foo")
(is (= @a {:foo "bar" :foobar "foo"}))))