Skip to content

Commit

Permalink
* add missing :js spec
Browse files Browse the repository at this point in the history
* basic tests for loop, recur, case
  • Loading branch information
swannodette committed Nov 1, 2024
1 parent ac8b0de commit 6a353c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/test/clojure/cljs/analyzer/spec_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,25 @@
(is (s/valid? ::a/node node)))
(let [node (analyze ns-env '(loop [x 1] x))]
(is (s/valid? ::a/node node)))
#_(let [node (analyze ns-env '(loop [x 1] (recur (inc x))))]
(let [node (analyze ns-env '(loop [x 1] (recur (inc x))))]
(is (s/valid? ::a/node node)))
#_(let [node (no-warn
(let [node (no-warn
(analyze ns-env
'(loop [x 100]
(if (pos? x)
(recur (dec x))
x))))]
(is (s/valid? ::a/node node))))

;; leftfn
(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)))]
(is (s/valid? ::a/node node))))

;; letfn

;; local

Expand All @@ -145,7 +153,4 @@

(test/run-tests)

(s/valid? ::a/node (no-warn (analyze ns-env '(case x 1 :foo 2 :bar))))
(s/explain ::a/node (no-warn (analyze ns-env '(case x 1 :foo 2 :bar))))

)
7 changes: 7 additions & 0 deletions src/test/clojure/cljs/analyzer/specs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@
(s/keys
:req-un [::meta ::expr])))

(s/def ::code string?)

(defmethod node :js [_]
(s/merge ::base
(s/keys
:opt-un [::code])))

(comment

(s/valid? ::node 1)
Expand Down

0 comments on commit 6a353c3

Please sign in to comment.