Skip to content

Commit

Permalink
* alphabetize tests
Browse files Browse the repository at this point in the history
* add missing cases / todos as comments
  • Loading branch information
swannodette committed Nov 15, 2024
1 parent 69c0f84 commit fb836ea
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 52 deletions.
140 changes: 88 additions & 52 deletions src/test/clojure/cljs/analyzer/spec_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)))
Expand All @@ -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))]
Expand All @@ -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)))
Expand All @@ -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

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

;; :ns

;; :ns*

(s/def ::expr ::node)

(defmethod node :quote [_]
Expand Down

0 comments on commit fb836ea

Please sign in to comment.