Subject: Re: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers

From: Ihor Radchenko <[email-masked]>
Date: Tue, 02 Jan 2024 11:08:22 +0000

Ihor Radchenko <[email-masked]> writes:

> See the following two almost identical snippets that yield completely
> different results depending on the present of `setq-default':
> ...

I believe that I now understand enough to add a new meaningful test.
See the attached. Please check the comments in the test to make sure
that they make sense.

>From dfc6dbcd844fbd8b8634b056fb441848b86311ca Mon Sep 17 00:00:00 2001
Message-ID: <[email-masked]>
From: Ihor Radchenko <[email-masked]>
Date: Tue, 2 Jan 2024 12:06:16 +0100
Subject: [PATCH] test/src/eval-tests.el (eval-tests/default-value): Add new
 test case

---
 test/src/eval-tests.el | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index c1219591e40..5cf9d4e2188 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -282,25 +282,38 @@ eval-tests-defvaralias
   (should-error (defvaralias 'eval-tests--my-c 'eval-tests--my-d)
                 :type 'cyclic-variable-indirection))
 
-(defvar eval-tests/global-var 'value)
-(defvar-local eval-tests/buffer-local-var 'value)
+(defvar eval-tests/global-var 'global-value)
+(defvar-local eval-tests/buffer-local-var 'default-value)
 (ert-deftest eval-tests/default-value ()
   ;; `let' overrides the default value for global variables.
   (should (default-boundp 'eval-tests/global-var))
-  (should (eq 'value (default-value 'eval-tests/global-var)))
-  (should (eq 'value eval-tests/global-var))
-  (let ((eval-tests/global-var 'bar))
-    (should (eq 'bar (default-value 'eval-tests/global-var)))
-    (should (eq 'bar eval-tests/global-var)))
+  (should (eq 'global-value (default-value 'eval-tests/global-var)))
+  (should (eq 'global-value eval-tests/global-var))
+  (let ((eval-tests/global-var 'let-value))
+    (should (eq 'let-value (default-value 'eval-tests/global-var)))
+    (should (eq 'let-value eval-tests/global-var)))
   ;; `let' overrides the default value everywhere, but leaves
   ;; buffer-local values unchanged in current buffer and in the
   ;; buffers where there is no explicitly set buffer-local value.
   (should (default-boundp 'eval-tests/buffer-local-var))
-  (should (eq 'value (default-value 'eval-tests/buffer-local-var)))
-  (should (eq 'value eval-tests/buffer-local-var))
+  (should (eq 'default-value (default-value 'eval-tests/buffer-local-var)))
+  (should (eq 'default-value eval-tests/buffer-local-var))
   (with-temp-buffer
-    (let ((eval-tests/buffer-local-var 'bar))
-      (should (eq 'bar (default-value 'eval-tests/buffer-local-var)))
-      (should (eq 'bar eval-tests/buffer-local-var)))))
+    (let ((eval-tests/buffer-local-var 'let-value))
+      (should (eq 'let-value (default-value 'eval-tests/buffer-local-var)))
+      (should (eq 'let-value eval-tests/buffer-local-var))))
+  ;; When current buffer has explicit buffer-local binding, `let' does
+  ;; not alter the default binding.
+  (with-temp-buffer
+    (setq-local eval-tests/buffer-local-var 'local-value)
+    (let ((eval-tests/buffer-local-var 'let-value))
+      ;; Let in a buffer with local binding does not change the
+      ;; default value for variable.
+      (should (eq 'default-value (default-value 'eval-tests/buffer-local-var)))
+      (should (eq 'let-value eval-tests/buffer-local-var))
+      (with-temp-buffer
+        ;; We are in a new buffer - `eval-tests/buffer-local-var' has its global default value.
+        (should (eq 'default-value (default-value 'eval-tests/buffer-local-var)))
+        (should (eq 'default-value eval-tests/buffer-local-var))))))
 
 ;;; eval-tests.el ends here
-- 
2.42.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>