Skip to content

Commit

Permalink
Update to avoid NullPointerException at namespace/aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Oct 3, 2018
1 parent ff19daf commit 15697d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/iced/nrepl/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
(defmulti aliases (fn [env _] env))
(defmethod aliases "clj"
[_ ns-code]
(->> ns-code i.u.ns/extract-ns-sym ns-aliases
(medley/map-vals ns-name)
ensure-string-map))
(or (some->> ns-code i.u.ns/extract-ns-sym ns-aliases
(medley/map-vals ns-name)
ensure-string-map)
{}))

(defmethod aliases "cljs"
[_ ns-code]
(-> ns-code read-string r.ns.parser/get-libspecs r.ns.parser/aliases
ensure-string-map))
(or (when (seq ns-code)
(some-> ns-code read-string r.ns.parser/get-libspecs
r.ns.parser/aliases
ensure-string-map))
{}))
14 changes: 13 additions & 1 deletion test/iced/nrepl/namespace_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
"sut" "iced.nrepl.namespace"}
(sut/aliases "clj" "(ns iced.nrepl.namespace-test)"))))

(t/testing "clj with no ns form"
(t/is (= {} (sut/aliases "clj" "(list 1 2 3)"))))

(t/testing "clj with no ns form"
(t/is (= {} (sut/aliases "clj" ""))))

(t/testing "cljs"
(t/is (= {"bar" "foo.bar"}
(sut/aliases "cljs" "(ns foo.core (:require [foo.bar :as bar]))")))))
(sut/aliases "cljs" "(ns foo.core (:require [foo.bar :as bar]))"))))

(t/testing "cljs with no ns form"
(t/is (= {} (sut/aliases "cljs" "(list 1 2 3)"))))

(t/testing "cljs with no ns form"
(t/is (= {} (sut/aliases "cljs" "")))))

0 comments on commit 15697d3

Please sign in to comment.