Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Malabarba committed Sep 3, 2015
1 parent e59f032 commit 70b0dfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/cider/nrepl/middleware/track_state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
[clojure.tools.nrepl.middleware :refer [set-descriptor!]])
(:import clojure.tools.nrepl.transport.Transport))

;;; Auxiliary
(defn update-vals
"Update the keys of map `m` via the function `f`."
[m f]
(reduce (fn [so-far [sym var]]
(assoc so-far sym (f var)))
{} m))
(into {} (map (fn [[k v]] [k (f v)]) m)))

(defn filter-core
"Remove keys whose values are vars in the core namespace."
Expand All @@ -30,6 +29,7 @@
(select-keys (meta var)
[:indent :cider-instrumented :macro :arglists]))

;;; State management
(defn ns-as-map
"Return a map of useful information about ns."
[ns]
Expand Down Expand Up @@ -77,7 +77,8 @@
merge changed-ns-map)
(assoc response :state {:repl-type (if (cljs/grab-cljs-env msg) :cljs :clj)
:changed-namespaces (misc/transform-value changed-ns-map)})))


;;; Middleware
(defn make-transport
"Return a Transport that defers to `transport` and possibly notifies
about the state."
Expand Down
20 changes: 8 additions & 12 deletions test/clj/cider/nrepl/middleware/track_state_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@
(is (= repl-type :cljs))
(is (map? changed-namespaces)))))


(deftest update-vals
"Update the keys of map `m` via the function `f`."
(= (s/update-vals {1 2 3 4 5 6} inc)
{1 3 3 5 5 7})
(= (s/update-vals {1 2 3 4 5 6} range)
'{5 (0 1 2 3 4 5), 3 (0 1 2 3), 1 (0 1)})
(= (s/update-vals {:a :b :c :d :e :f} str)
{:e ":f", :c ":d", :a ":b"})
(= (s/update-vals {1 2 3 4 5 6} odd?)
{1 false 3 false 5 false}))
(is (= (s/update-vals {1 2 3 4 5 6} inc)
{1 3 3 5 5 7}))
(is (= (s/update-vals {1 2 3 4 5 6} range)
'{5 (0 1 2 3 4 5), 3 (0 1 2 3), 1 (0 1)}))
(is (= (s/update-vals {:a :b :c :d :e :f} str)
{:e ":f", :c ":d", :a ":b"}))
(is (= (s/update-vals {1 2 3 4 5 6} odd?)
{1 false 3 false 5 false})))

(deftest filter-core
(is (= (s/filter-core {'and #'and, 'b #'map, 'c #'deftest})
Expand All @@ -56,15 +54,13 @@
seq not)))

(deftest relevant-meta
"Return the meta of var, selecting only keys of interest."
(is (= (:macro (s/relevant-meta #'deftest))
true))
(alter-meta! #'update-vals merge {:indent 1 :cider-instrumented 2 :something-else 3})
(is (= (s/relevant-meta #'update-vals)
{:cider-instrumented 2, :indent 1})))

(deftest ns-as-map
"Return a map of useful information about ns."
(alter-meta! #'update-vals
merge {:indent 1 :cider-instrumented 2 :something-else 3})
(let [{:keys [interns aliases] :as ns} (s/ns-as-map (find-ns 'cider.nrepl.middleware.track-state-test))]
Expand Down

0 comments on commit 70b0dfa

Please sign in to comment.