Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ns-unalias #796

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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