diff --git a/src/test/clojure/cljs/analyzer/spec_tests.clj b/src/test/clojure/cljs/analyzer/spec_tests.clj index 72167104c..991a81db8 100644 --- a/src/test/clojure/cljs/analyzer/spec_tests.clj +++ b/src/test/clojure/cljs/analyzer/spec_tests.clj @@ -13,6 +13,14 @@ [clojure.test :as test :refer [deftest is]] [clojure.spec.alpha :as s])) +(deftest test-case + (let [node (no-warn (analyze ns-env '(case x 1 :foo 2 :bar)))] + (is (s/valid? ::a/node node)))) + +;; case-node +;; case-test +;; case-then + (deftest test-const (is (s/valid? ::a/node (analyze ns-env 1))) (is (s/valid? ::a/node (analyze ns-env 1.2))) @@ -31,31 +39,6 @@ (is (= :set (:op node))) (is (s/valid? ::a/node node)))) -(deftest test-if - (let [node (analyze ns-env '(if true true))] - (is (= :if (:op node))) - (is (s/valid? ::a/node node))) - (is (s/valid? ::a/node (analyze ns-env '(if true true false))))) - -(deftest test-do - (let [node (analyze ns-env '(do))] - (is (= :do (:op node))) - (is (s/valid? ::a/node node))) - (is (s/valid? ::a/node (analyze ns-env '(do 1)))) - (is (s/valid? ::a/node (analyze ns-env '(do 1 2 3))))) - -(deftest test-let - (let [node (analyze ns-env '(let []))] - (is (= :let (:op node))) - (is (s/valid? ::a/node node))) - (is (s/valid? ::a/node (analyze ns-env '(let [x 1])))) - (is (s/valid? ::a/node (analyze ns-env '(let [x 1] x))))) - -(deftest test-throw - (let [node (no-warn (analyze ns-env '(throw (js/Error. "foo"))))] - (is (= :throw (:op node))) - (is (s/valid? ::a/node node)))) - (deftest test-def (let [node (no-warn (analyze ns-env '(def x)))] (is (= :def (:op node))) @@ -64,37 +47,38 @@ (is (s/valid? ::a/node (analyze ns-env '(def x (fn []))))) (is (s/valid? ::a/node (analyze ns-env '(def x (fn [y] y)))))) -(deftest test-fn - (let [node (no-warn (analyze ns-env '(fn [])))] - (is (= :fn (:op node))) - (is (s/valid? ::a/node node))) - (is (s/valid? ::a/node (analyze ns-env '(fn [] 1)))) - (is (s/valid? ::a/node (analyze ns-env '(fn [x])))) - (is (s/valid? ::a/node (analyze ns-env '(fn [x] 1))))) - (deftest test-defn (is (s/valid? ::a/node (analyze ns-env '(defn x [])))) (is (s/valid? ::a/node (analyze ns-env '(defn x [] 1)))) (is (s/valid? ::a/node (analyze ns-env '(defn x [y] y))))) -(deftest test-new - (let [node (no-warn (analyze ns-env '(new String)))] - (is (= :new (:op node))) - (is (s/valid? ::a/node node))) - (is (s/valid? ::a/node (analyze ns-env '(new js/String)))) - (is (s/valid? ::a/node (no-warn (analyze ns-env '(String.))))) - (is (s/valid? ::a/node (analyze ns-env '(js/String.))))) +(deftest test-defrecord + (let [node (no-warn (analyze ns-env '(defrecord A []))) + body (:body node)] + (is (= :defrecord (-> body :statements first :ret :op))) + (is (s/valid? ::a/node node)))) (deftest test-deftype (let [node (no-warn (analyze ns-env '(deftype A [])))] (is (= :deftype (-> node :statements first :op))) (is (s/valid? ::a/node node)))) -(deftest test-defrecord - (let [node (no-warn (analyze ns-env '(defrecord A []))) - body (:body node)] - (is (= :defrecord (-> body :statements first :ret :op))) - (is (s/valid? ::a/node node)))) +(deftest test-do + (let [node (analyze ns-env '(do))] + (is (= :do (:op node))) + (is (s/valid? ::a/node node))) + (is (s/valid? ::a/node (analyze ns-env '(do 1)))) + (is (s/valid? ::a/node (analyze ns-env '(do 1 2 3))))) + +(deftest test-fn + (let [node (no-warn (analyze ns-env '(fn [])))] + (is (= :fn (:op node))) + (is (s/valid? ::a/node node))) + (is (s/valid? ::a/node (analyze ns-env '(fn [] 1)))) + (is (s/valid? ::a/node (analyze ns-env '(fn [x])))) + (is (s/valid? ::a/node (analyze ns-env '(fn [x] 1))))) + +;; fn-method (deftest test-host-call (let [node (analyze ns-env '(.substring "foo" 0 1))] @@ -112,11 +96,38 @@ (is (= :host-field (:op node))) (is (s/valid? ::a/node node)))) +(deftest test-if + (let [node (analyze ns-env '(if true true))] + (is (= :if (:op node))) + (is (s/valid? ::a/node node))) + (is (s/valid? ::a/node (analyze ns-env '(if true true false))))) + (deftest test-invoke (let [node (no-warn (analyze ns-env '(count "foo")))] (is (= :invoke (:op node))) (is (s/valid? ::a/node node)))) +;; js-array + +;; js-object +;(deftest test-js-object +; ) + +;; js-var + +(deftest test-let + (let [node (analyze ns-env '(let []))] + (is (= :let (:op node))) + (is (s/valid? ::a/node node))) + (is (s/valid? ::a/node (analyze ns-env '(let [x 1])))) + (is (s/valid? ::a/node (analyze ns-env '(let [x 1] x))))) + +;; letfn + +;; list + +;; local + (deftest test-loop (let [node (analyze ns-env '(loop []))] (is (= :loop (:op node))) @@ -133,21 +144,46 @@ x))))] (is (s/valid? ::a/node node)))) +;; map + +(deftest test-new + (let [node (no-warn (analyze ns-env '(new String)))] + (is (= :new (:op node))) + (is (s/valid? ::a/node node))) + (is (s/valid? ::a/node (analyze ns-env '(new js/String)))) + (is (s/valid? ::a/node (no-warn (analyze ns-env '(String.))))) + (is (s/valid? ::a/node (analyze ns-env '(js/String.))))) + +;; no-op + +;; ns + +;; ns* + +;; quote + (deftest test-recur (let [node (no-warn (analyze ns-env '(fn [x] (recur (inc x)))))] (is (s/valid? ::a/node node)))) -(deftest test-case - (let [node (no-warn (analyze ns-env '(case x 1 :foo 2 :bar)))] +;; set + +;; set! + +;; the-var + +(deftest test-throw + (let [node (no-warn (analyze ns-env '(throw (js/Error. "foo"))))] + (is (= :throw (:op node))) (is (s/valid? ::a/node node)))) -;; letfn +;; try -;; local +;; var -; TODO: #js -;(deftest test-js-object -; ) +;; vector + +;; with-meta (comment diff --git a/src/test/clojure/cljs/analyzer/specs.cljc b/src/test/clojure/cljs/analyzer/specs.cljc index e64c02521..b6cb386d4 100644 --- a/src/test/clojure/cljs/analyzer/specs.cljc +++ b/src/test/clojure/cljs/analyzer/specs.cljc @@ -222,6 +222,10 @@ (defmethod node :no-op [_] ::base) +;; :ns + +;; :ns* + (s/def ::expr ::node) (defmethod node :quote [_]