emacs-diffs
[Top][All Lists]
Advanced

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

master 9bc5c01: Strengthen js-mode indentation tests


From: Mattias Engdegård
Subject: master 9bc5c01: Strengthen js-mode indentation tests
Date: Sun, 18 Oct 2020 09:59:01 -0400 (EDT)

branch: master
commit 9bc5c016a1cbdcb0c29b2deaec1d8156852a3980
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Strengthen js-mode indentation tests
    
    Test not only that the indentation engine is idempotent but that it
    will indent a file to the expected shape from scratch.
    
    * test/lisp/progmodes/js-tests.el (js-tests--remove-indentation): New.
    (js-deftest-indent): Extend test.
---
 test/lisp/progmodes/js-tests.el | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el
index 1de2df0..6c3a618 100644
--- a/test/lisp/progmodes/js-tests.el
+++ b/test/lisp/progmodes/js-tests.el
@@ -199,6 +199,14 @@ if (!/[ (:,='\"]/.test(value)) {
 
 ;;;; Indentation tests.
 
+(defun js-tests--remove-indentation ()
+  "Remove all indentation in the current buffer."
+  (goto-char (point-min))
+  (while (re-search-forward (rx bol (+ (in " \t"))) nil t)
+    (let ((syntax (save-match-data (syntax-ppss))))
+      (unless (nth 3 syntax)       ; Avoid multiline string literals.
+        (replace-match "")))))
+
 (defmacro js-deftest-indent (file)
   `(ert-deftest ,(intern (format "js-indent-test/%s" file)) ()
      :tags '(:expensive-test)
@@ -206,6 +214,11 @@ if (!/[ (:,='\"]/.test(value)) {
        (unwind-protect
            (with-current-buffer buf
              (let ((orig (buffer-string)))
+               (js-tests--remove-indentation)
+               ;; Indent and check that we get the original text.
+               (indent-region (point-min) (point-max))
+               (should (equal (buffer-string) orig))
+               ;; Verify idempotency.
                (indent-region (point-min) (point-max))
                (should (equal (buffer-string) orig))))
          (kill-buffer buf)))))



reply via email to

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