|
| 1 | +;; Copyright (c) Rich Hickey. All rights reserved. |
| 2 | +;; The use and distribution terms for this software are covered by the |
| 3 | +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
| 4 | +;; which can be found in the file epl-v10.html at the root of this distribution. |
| 5 | +;; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +;; the terms of this license. |
| 7 | +;; You must not remove this notice, or any other, from this software. |
| 8 | + |
| 9 | +(ns cljs.analyzer.as-alias-test |
| 10 | + (:require [cljs.analyzer.impl.namespaces :as ana-nses] |
| 11 | + [cljs.env :as env] |
| 12 | + [clojure.test :as test :refer [deftest testing is]])) |
| 13 | + |
| 14 | +;; ============================================================================= |
| 15 | + |
| 16 | +(deftest test-check-and-remove-as-alias |
| 17 | + (let [cenv (env/default-compiler-env)] |
| 18 | + (env/with-compiler-env cenv |
| 19 | + (testing "check-and-remove-as-alias basic tests" |
| 20 | + (is (= '{:as-alias {bar bar.core}} |
| 21 | + (ana-nses/check-and-remove-as-alias '[bar.core :as-alias bar]))) |
| 22 | + (is (= '{:as-alias {bar bar.core} |
| 23 | + :libspec [bar.core :as boo]} |
| 24 | + (ana-nses/check-and-remove-as-alias '[bar.core :as-alias bar :as boo]))) |
| 25 | + (is (thrown? Throwable |
| 26 | + (ana-nses/check-and-remove-as-alias '[bar.core :as-alias :bar])))) |
| 27 | + (testing "check-and-remove-as-alias should not elide simple specs" |
| 28 | + (is (= '{:libspec bar.core} |
| 29 | + (ana-nses/check-and-remove-as-alias 'bar.core))) |
| 30 | + (is (= '{:libspec [bar.core]} |
| 31 | + (ana-nses/check-and-remove-as-alias '[bar.core]))))))) |
| 32 | + |
| 33 | +(deftest test-elide-aliases-from-libspecs |
| 34 | + (let [cenv (env/default-compiler-env)] |
| 35 | + (env/with-compiler-env cenv |
| 36 | + (is (= '{:as-aliases {foo foo.core |
| 37 | + bar bar.core |
| 38 | + woz woz.core} |
| 39 | + :libspecs [[woz.core :as wozc]]} |
| 40 | + (ana-nses/elide-aliases-from-libspecs |
| 41 | + '([foo.core :as-alias foo] |
| 42 | + [bar.core :as-alias bar] |
| 43 | + [woz.core :as-alias woz :as wozc])))) |
| 44 | + (is (thrown? Throwable |
| 45 | + (ana-nses/elide-aliases-from-libspecs |
| 46 | + '([foo.core :as-alias foo] |
| 47 | + [bar.core :as-alias bar] |
| 48 | + [woz.core :as-alias woz :as wozc] |
| 49 | + [foo.impl :as-alias foo]))))))) |
| 50 | + |
| 51 | +(deftest test-elide-aliases-from-ns-specs |
| 52 | + (let [cenv (env/default-compiler-env)] |
| 53 | + (env/with-compiler-env cenv |
| 54 | + (is (= '{:as-aliases {blah blah.core, foo foo.core, bar bar.core}, |
| 55 | + :libspecs [(:require-macros [[lala.core :as-lias lala :as tralala]]) |
| 56 | + (:require [[woz.core :as woz]])]}) |
| 57 | + (ana-nses/elide-aliases-from-ns-specs |
| 58 | + '((:require-macros [blah.core :as-alias blah] |
| 59 | + [lala.core :as-alias lala :as tralala]) |
| 60 | + (:require |
| 61 | + [foo.core :as-alias foo] |
| 62 | + [bar.core :as-alias bar] |
| 63 | + [woz.core :as woz])))) |
| 64 | + (testing "Proper handling of ns-spec edgecases" |
| 65 | + (is (= '{:as-aliases {} :libspecs [(:require foo.core bar.core woz.core)]} |
| 66 | + (ana-nses/elide-aliases-from-ns-specs |
| 67 | + '((:require foo.core bar.core woz.core))))) |
| 68 | + (is (= '{:as-aliases {} :libspecs [(:require [foo.core] [bar.core] [woz.core])]} |
| 69 | + (ana-nses/elide-aliases-from-ns-specs |
| 70 | + '((:require [foo.core] [bar.core] [woz.core])))))) |
| 71 | + (testing ":refer-clojure is ignored" |
| 72 | + (is (= '{:as-aliases {} |
| 73 | + :libspecs [(:refer-clojure :exclude [first]) |
| 74 | + (:require foo.core bar.core woz.core)]} |
| 75 | + (ana-nses/elide-aliases-from-ns-specs |
| 76 | + '((:refer-clojure :exclude [first]) |
| 77 | + (:require foo.core bar.core woz.core)))))) |
| 78 | + (testing ":reload/:reload-all is ignored" |
| 79 | + (is (= '{:as-aliases {}, |
| 80 | + :libspecs [(:refer-clojure :exclude [first]) |
| 81 | + (:require foo.core bar.core woz.core :reload-all)]} |
| 82 | + (ana-nses/elide-aliases-from-ns-specs |
| 83 | + '((:refer-clojure :exclude [first]) |
| 84 | + (:require foo.core bar.core woz.core :reload-all))))))))) |
| 85 | + |
| 86 | +(comment |
| 87 | + |
| 88 | + (test/run-tests) |
| 89 | + |
| 90 | + ) |
0 commit comments