emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fd653f5208 2/2: ; whitespace: Add test case for read-only buffers


From: Lars Ingebrigtsen
Subject: master fd653f5208 2/2: ; whitespace: Add test case for read-only buffers (bug#58082)
Date: Tue, 27 Sep 2022 07:45:13 -0400 (EDT)

branch: master
commit fd653f5208e8600166003af41660ce2ad0b6362f
Author: Richard Hansen <rhansen@rhansen.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    ; whitespace: Add test case for read-only buffers (bug#58082)
---
 test/lisp/whitespace-tests.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 97c30c4d62..fb53543c9e 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -27,7 +27,8 @@
 (defmacro whitespace-tests--with-test-buffer (style &rest body)
   "Run BODY in a buffer with `whitespace-mode' style STYLE.
 The buffer is displayed in `selected-window', and
-`noninteractive' is set to nil even in batch mode."
+`noninteractive' is set to nil even in batch mode.  If STYLE is
+nil, `whitespace-mode' is left disabled."
   (declare (debug ((style form) def-body))
            (indent 1))
   `(ert-with-test-buffer-selected ()
@@ -37,7 +38,8 @@ The buffer is displayed in `selected-window', and
      (let ((noninteractive nil)
            (whitespace-style ,style))
        (font-lock-mode 1)
-       (whitespace-mode 1)
+       ,(when style
+          '(whitespace-mode 1))
        ,@body)))
 
 (defun whitespace-tests--faceup (&rest lines)
@@ -310,6 +312,21 @@ buffer's content."
                                       "\t\n"
                                       " »"))))
 
+(ert-deftest whitespace-tests--empty-bob-eob-read-only-buffer ()
+  (whitespace-tests--with-test-buffer '()
+    (insert "\nx\n\n")
+    (should (equal (buffer-string) "\nx\n\n"))
+    (setq-local buffer-read-only t)
+    (goto-char 2)
+    (should (equal (line-number-at-pos) 2))
+    (should (equal (- (point) (line-beginning-position)) 0))
+    (let ((whitespace-style '(face empty)))
+      (whitespace-mode 1)
+      (should (whitespace-tests--faceup "«:whitespace-empty:\n"
+                                        "»x\n"
+                                        "«:whitespace-empty:\n"
+                                        "»")))))
+
 (provide 'whitespace-tests)
 
 ;;; whitespace-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]