Skip to content

Commit

Permalink
Add support for ns-unalias (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
eerohele authored Sep 7, 2022
1 parent c346099 commit 57fcb5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,12 @@
:else the-ns-map))))))
nil)

(defn sci-ns-unalias [ctx sci-ns sym]
(swap! (:env ctx)
(fn [env]
(update-in env [:namespaces (sci-ns-name (sci-the-ns ctx sci-ns)) :aliases] dissoc sym)))
nil)

(defn sci-all-ns [ctx]
(let [env (:env ctx)
namespaces (get @env :namespaces)
Expand Down Expand Up @@ -1322,6 +1328,7 @@
'ns-refers (core-var 'ns-refers sci-ns-refers true)
'ns-map (core-var 'ns-map sci-ns-map true)
'ns-unmap (core-var 'ns-unmap sci-ns-unmap true)
'ns-unalias (core-var 'ns-unalias sci-ns-unalias true)
'ns-name (core-var 'ns-name sci-ns-name)
'odd? (copy-core-var odd?)
#?@(:cljs ['object? (copy-core-var object?)])
Expand Down
13 changes: 13 additions & 0 deletions test/sci/namespaces_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@
(deftest remove-ns-test
(is (nil? (eval* "(ns foo) (ns bar) (remove-ns 'foo) (find-ns 'foo)"))))

(deftest ns-unalias-test
(testing "Removing an alias in an unknown namespace throws"
(is (thrown? #?(:clj Exception :cljs js/Error) (eval* "(ns-unalias (find-ns 'unknown) 'core)"))))

(testing "Removing an undefined alias is a no-op"
(is (nil? (eval* "(ns-unalias *ns* 'core)"))))

(testing "Removing a defined alias -- ns symbol"
(is (nil? (eval* "(alias 'core 'clojure.core) (ns-unalias 'user 'core) (get (ns-aliases *ns*) 'core)"))))

(testing "Removing a defined alias -- ns object"
(is (nil? (eval* "(alias 'core 'clojure.core) (ns-unalias *ns* 'core) (get (ns-aliases *ns*) 'core)")))))

(deftest ns-syntax-test
(is (thrown-with-msg?
#?(:clj Exception :cljs js/Error)
Expand Down

0 comments on commit 57fcb5a

Please sign in to comment.