branch: elpa/llama
commit 089cf6f80f4e5c89e5b014b431a4d103dee3c219
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    Add note about opaqueness of macros' argument handling
    
    Add that in form of a commented test.
    
    Basically, we cannot know what macros do with their arguments.
    
    One might of course argue that we should add special handling for
    `setq', `setq-local' and `setq-default'.  But where to stop?  What about
    `setf'?  And what about external macros such as `-setq'?  It is probably
    best to stop before even entering the special case lane at all.
---
 llama-test.el | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/llama-test.el b/llama-test.el
index 8f2007645f..534997e42a 100644
--- a/llama-test.el
+++ b/llama-test.el
@@ -431,6 +431,46 @@
   (should-error (##list  %1   %1  &1))
   )
 
+(ert-deftest llama-test-801-ambiguity nil
+
+  ;; We cannot know how every special form and macro uses its arguments,
+  ;; and can therefore not always do the right thing™.  However, whatever
+  ;; we end up doing, font-lock should agree.  Here are some noteworthy
+  ;; examples where our macro expansion and our font-lock agree, but the
+  ;; author might have intended something else.
+
+  (with-no-warnings ; unused arguments
+
+    ;; A good example of what we might not want and theoretically could
+    ;; prevent.  However, this can also be prevented by just not going
+    ;; out of our way to wander into ambigious territory.  While not
+    ;; impossible, it is unlikely that someone does this accidentally.
+    (should (equal (##setq % 1)
+                   (lambda (%)
+                     (setq % 1))))
+
+    ;; We have to fake `-setq' because we don't want to depend on `dash'
+    ;; and because (equal (lambda () (-setq a 1)) (lambda () (-setq a 1)))
+    ;; is never true because `-setq' uses `make-symbol'.  Mocking that
+    ;; macro does *not* affect the expansion of `##' into a `lambda'.
+    (cl-macrolet ((-setq (&rest args) `'(,@args)))
+      (should (equal (##-setq % 1)
+                     (lambda (%)
+                       (-setq % 1))))
+      (should (equal (##-setq (%) '(1))
+                     (lambda ()
+                       (-setq (%) '(1)))))
+      (should (equal (##-setq [(%)] [(1)])
+                     (lambda ()
+                       (-setq [(%)] [(1)]))))
+      (should (equal (##-setq [(% %)] [(1 2)])
+                     (lambda (%)
+                       (-setq [(% %)] [(1 2)]))))
+      (should (equal (##-setq [(%1)] [(1)])
+                     (lambda (%1)
+                       (-setq [(%1)] [(1)]))))))
+  )
+
 (ert-deftest llama-test-902-errors-second nil
   (should-error (##list  %2   &2))
   (should-error (##list  &2   %2))

Reply via email to