Skip to content

Commit

Permalink
* add basic :ns & :ns* specs
Browse files Browse the repository at this point in the history
* test-letfn, test-ns, test-set!
* some problematic ones
  • Loading branch information
swannodette committed Nov 17, 2024
1 parent 6226322 commit 17c79e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
34 changes: 27 additions & 7 deletions src/test/clojure/cljs/analyzer/spec_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
;; You must not remove this notice, or any other, from this software.

(ns cljs.analyzer.spec-tests
(:require [cljs.analyzer.api :as ana :refer [no-warn]]
(:require [cljs.analyzer :as ana]
[cljs.analyzer.api :as ana-api :refer [no-warn]]
[cljs.analyzer-tests :refer [analyze ns-env]]
[cljs.analyzer.specs :as a]
[clojure.test :as test :refer [deftest is]]
Expand Down Expand Up @@ -128,7 +129,10 @@
(is (s/valid? ::a/node (analyze ns-env '(let [x 1]))))
(is (s/valid? ::a/node (analyze ns-env '(let [x 1] x)))))

;; letfn
(deftest test-letfn
(let [node (analyze ns-env '(letfn [(foo [] (bar)) (bar [] (foo))]))]
(is (= :letfn (:op node)))
(is (s/valid? ::a/node node))))

;; list, no longer needed, subsumed by :quote

Expand Down Expand Up @@ -165,9 +169,19 @@

;; no-op

;; ns
(deftest test-ns
(let [node (no-warn
(binding [ana/*cljs-ns* 'cljs.user]
(analyze ns-env '(ns foo (:require [goog.string])))))]
(is (= :ns (:op node)))
(is (s/valid? ::a/node node))))

;; ns*
#_(deftest test-ns*
(let [node (no-warn
(binding [ana/*cljs-ns* 'cljs.user]
(analyze ns-env '(ns* foo '(:require [goog.string])))))]
(is (= :ns (:op node)))
(is (s/valid? ::a/node node))))

(deftest test-quote
(let [node (analyze ns-env ''(1 2 3))]
Expand All @@ -179,11 +193,14 @@
(is (s/valid? ::a/node node))))

(deftest test-set
(let [node (no-warn (analyze ns-env #{1 2 3}))]
(let [node (analyze ns-env #{1 2 3})]
(is (= :set (:op node)))
(is (s/valid? ::a/node node))))

;; set!
(deftest test-set!
(let [node (no-warn (analyze ns-env '(set! x 1)))]
(is (= :set! (:op node)))
(is (s/valid? ::a/node node))))

;; the-var

Expand All @@ -192,7 +209,10 @@
(is (= :throw (:op node)))
(is (s/valid? ::a/node node))))

;; try
#_(deftest test-try
(let [node (no-warn (analyze ns-env '(try 1 (catch :default e) (finally))))]
(is (= :try (:op node)))
(is (s/valid? ::a/node node))))

;; var

Expand Down
6 changes: 4 additions & 2 deletions src/test/clojure/cljs/analyzer/specs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@
(defmethod node :no-op [_]
::base)

;; :ns
(defmethod node :ns [_]
::base)

;; :ns*
(defmethod node :ns* [_]
::base)

(s/def ::expr ::node)

Expand Down

0 comments on commit 17c79e7

Please sign in to comment.