From 17c79e7cd80d4c3f0e05b70cda14852605f2fa0e Mon Sep 17 00:00:00 2001 From: davidnolen Date: Sun, 17 Nov 2024 11:28:08 -0500 Subject: [PATCH] * add basic :ns & :ns* specs * test-letfn, test-ns, test-set! * some problematic ones --- src/test/clojure/cljs/analyzer/spec_tests.clj | 34 +++++++++++++++---- src/test/clojure/cljs/analyzer/specs.cljc | 6 ++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/test/clojure/cljs/analyzer/spec_tests.clj b/src/test/clojure/cljs/analyzer/spec_tests.clj index 310763eb4..4eb45279f 100644 --- a/src/test/clojure/cljs/analyzer/spec_tests.clj +++ b/src/test/clojure/cljs/analyzer/spec_tests.clj @@ -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]] @@ -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 @@ -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))] @@ -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 @@ -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 diff --git a/src/test/clojure/cljs/analyzer/specs.cljc b/src/test/clojure/cljs/analyzer/specs.cljc index b6cb386d4..08e94910e 100644 --- a/src/test/clojure/cljs/analyzer/specs.cljc +++ b/src/test/clojure/cljs/analyzer/specs.cljc @@ -222,9 +222,11 @@ (defmethod node :no-op [_] ::base) -;; :ns +(defmethod node :ns [_] + ::base) -;; :ns* +(defmethod node :ns* [_] + ::base) (s/def ::expr ::node)