                    [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
 

      (is (= @res (+ 2 @a)))
      (is (= @b-changed 1))
      (is (= @c-changed 0))
             
      (reset! a -1)
      (is (= @res (+ 2 @a)))
      (is (= @b-changed 2))
      (is (= @c-changed 0))
      (is (= @a-base {:test {:unsubscribe -1 :value 42}}))
             
      (reset! a 2)
      (is (= @res (+ 10 @a)))
      (is (<= 2 @b-changed 3))
      (is (= @c-changed 1))
      (is (= @a-base {:test {:unsubscribe 2 :value 42}}))
             
      (reset! a 3)
      (is (= @res (+ 10 @a)))
      (is (<= 2 @b-changed 3))
      (is (= @c-changed 2))
      (is (= @a-base {:test {:unsubscribe 3 :value 42}}))
             
      (reset! a 3)
      (is (= @res (+ 10 @a)))
      (is (<= 2 @b-changed 3))
      (is (= @c-changed 2))
      (is (= @a-base {:test {:unsubscribe 3 :value 42}}))
             
      (reset! a -1)
      (is (= @res (+ 2 @a)))
      (is (= @a-base {:test {:unsubscribe -1 :value 42}}))

    (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"}))))
