From 6247fe13cf291f009cc2bb145ba669b0c89a197e Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:12:58 -0800 Subject: [PATCH] tap warning on compile ambig attrs; added some wonky tests for attrs reflection --- src/dev/onionpancakes/chassis/compiler.clj | 8 +++-- .../chassis/tests/test_compiler.clj | 33 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/dev/onionpancakes/chassis/compiler.clj b/src/dev/onionpancakes/chassis/compiler.clj index 1cb3ede..97a1b60 100644 --- a/src/dev/onionpancakes/chassis/compiler.clj +++ b/src/dev/onionpancakes/chassis/compiler.clj @@ -263,7 +263,9 @@ (compilable-alias-element-children-attrs-present elem)) (if (attrs-absent? elem) (compilable-alias-element-children-attrs-absent elem) - (compilable-alias-element-children-attrs-ambig elem)))) + (do + (tap> {::warn :ambig-attrs ::elem elem}) + (compilable-alias-element-children-attrs-ambig elem))))) (defn compilable-element-children-attrs-present-evaluated [elem] @@ -340,7 +342,9 @@ (compilable-element-children-attrs-present elem)) (if (attrs-absent? elem) (compilable-element-children-attrs-absent elem) - (compilable-element-children-attrs-ambig elem)))) + (do + (tap> {::warn :ambig-attrs ::elem elem}) + (compilable-element-children-attrs-ambig elem))))) (extend-protocol CompilableNode clojure.lang.IPersistentVector diff --git a/test/dev/onionpancakes/chassis/tests/test_compiler.clj b/test/dev/onionpancakes/chassis/tests/test_compiler.clj index 14a645e..08ed8c9 100644 --- a/test/dev/onionpancakes/chassis/tests/test_compiler.clj +++ b/test/dev/onionpancakes/chassis/tests/test_compiler.clj @@ -83,14 +83,27 @@ [:div [:p "foo"] (example-elem-macro "123") [:p "bar"]] [c/doctype-html5 [:div "foo" c/nbsp "bar"]])) +;; Attributes reflection tests +;; Warnings are emitted at compile time, +;; so warning detection is a side effect? + +(def ambig-attrs-count + (atom 0)) + +(defonce count-ambig-attrs + (fn [m] + (when (identical? (::cc/warn m) :ambig-attrs) + (swap! ambig-attrs-count inc)))) + +(try + (add-tap count-ambig-attrs) + ;; Compile attrs reflection examples + (let [attrs nil] + (cc/compile [:div ^java.util.Map attrs "foobar"])) + (let [^java.util.Map attrs nil] + (cc/compile [:div attrs "foobar"])) + (finally + (remove-tap count-ambig-attrs))) + (deftest test-compile-attrs-reflection - (let [attrs nil - ret (cc/compile [:div ^java.util.Map attrs "foobar"])] - ;; how to write test???" - ;; macroexpand doesn't capture &env - ) - (let [^java.util.Map attrs nil - ret (cc/compile [:div attrs "foobar"])] - ;; how to write test???" - ;; macroexpand doesn't capture &env - )) + (is (zero? @ambig-attrs-count)))