From 6a353c377bc7e49bb15032b9345fb8d7a775874c Mon Sep 17 00:00:00 2001 From: davidnolen Date: Fri, 1 Nov 2024 08:01:17 -0400 Subject: [PATCH] * add missing :js spec * basic tests for loop, recur, case --- src/test/clojure/cljs/analyzer/spec_tests.clj | 17 +++++++++++------ src/test/clojure/cljs/analyzer/specs.cljc | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/clojure/cljs/analyzer/spec_tests.clj b/src/test/clojure/cljs/analyzer/spec_tests.clj index faca7b06a..72167104c 100644 --- a/src/test/clojure/cljs/analyzer/spec_tests.clj +++ b/src/test/clojure/cljs/analyzer/spec_tests.clj @@ -123,9 +123,9 @@ (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) @@ -133,7 +133,15 @@ 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 @@ -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)))) - ) diff --git a/src/test/clojure/cljs/analyzer/specs.cljc b/src/test/clojure/cljs/analyzer/specs.cljc index 11b6ab029..2ef433cd0 100644 --- a/src/test/clojure/cljs/analyzer/specs.cljc +++ b/src/test/clojure/cljs/analyzer/specs.cljc @@ -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)