emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] scratch/so-long abfa102 2/2: Add tests for so-long.el


From: Phil
Subject: [Emacs-diffs] scratch/so-long abfa102 2/2: Add tests for so-long.el
Date: Fri, 14 Jun 2019 00:52:29 -0400 (EDT)

branch: scratch/so-long
commit abfa102f57380d0cf3991f7b292f5f6aeef831c4
Author: Phil Sainty <address@hidden>
Commit: Phil Sainty <address@hidden>

    Add tests for so-long.el
---
 .../so-long-tests/autoload-longlines-mode-tests.el |  53 ++++
 .../so-long-tests/autoload-major-mode-tests.el     |  49 ++++
 .../so-long-tests/autoload-minor-mode-tests.el     |  52 ++++
 test/lisp/so-long-tests/so-long-tests-helpers.el   | 104 +++++++
 test/lisp/so-long-tests/so-long-tests.el           | 311 +++++++++++++++++++++
 5 files changed, 569 insertions(+)

diff --git a/test/lisp/so-long-tests/autoload-longlines-mode-tests.el 
b/test/lisp/so-long-tests/autoload-longlines-mode-tests.el
new file mode 100644
index 0000000..d32f99a
--- /dev/null
+++ b/test/lisp/so-long-tests/autoload-longlines-mode-tests.el
@@ -0,0 +1,53 @@
+;;; autoload-longlines-mode-tests.el --- Test suite for so-long.el  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Phil Sainty <address@hidden>
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(load (expand-file-name "so-long-tests-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+
+(declare-function so-long-tests-remember "so-long-tests-helpers")
+(declare-function so-long-tests-assert-active "so-long-tests-helpers")
+(declare-function so-long-tests-assert-reverted "so-long-tests-helpers")
+
+;; We're testing the initial state.  We could alternatively use
+;; `unload-feature' to revert to that, but this option is simple.
+
+(autoload 'so-long "so-long")
+(autoload 'longlines-mode "longlines")
+
+(ert-deftest so-long-tests-autoload-longlines-mode ()
+  "File-local -*- so-long-action: longlines-mode; eval: (so-long) -*-"
+  (with-temp-buffer
+    (so-long-tests-remember)
+    (insert "-*- so-long-action: longlines-mode; eval: (so-long) -*-\n")
+    (put 'so-long-action 'safe-local-variable #'symbolp)
+    (push '(eval . (so-long)) safe-local-variable-values)
+    (hack-local-variables)
+    (should (eq so-long-action 'longlines-mode))
+    (so-long-tests-assert-active 'longlines-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'longlines-mode)))
+
+;;; autoload-longlines-mode-tests.el ends here
diff --git a/test/lisp/so-long-tests/autoload-major-mode-tests.el 
b/test/lisp/so-long-tests/autoload-major-mode-tests.el
new file mode 100644
index 0000000..1b542b6
--- /dev/null
+++ b/test/lisp/so-long-tests/autoload-major-mode-tests.el
@@ -0,0 +1,49 @@
+;;; autoload-major-mode-tests.el --- Test suite for so-long.el  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Phil Sainty <address@hidden>
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(load (expand-file-name "so-long-tests-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+
+(declare-function so-long-tests-remember "so-long-tests-helpers")
+(declare-function so-long-tests-assert-active "so-long-tests-helpers")
+(declare-function so-long-tests-assert-reverted "so-long-tests-helpers")
+
+;; We're testing the initial state.  We could alternatively use
+;; `unload-feature' to revert to that, but this option is simple.
+
+(autoload 'so-long-mode "so-long")
+
+(ert-deftest so-long-tests-autoload-major-mode ()
+  "File-local -*- so-long -*-"
+  (with-temp-buffer
+    (so-long-tests-remember)
+    (insert "-*- so-long -*-\n")
+    (normal-mode)
+    (so-long-tests-assert-active 'so-long-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'so-long-mode)))
+
+;;; autoload-major-mode-tests.el ends here
diff --git a/test/lisp/so-long-tests/autoload-minor-mode-tests.el 
b/test/lisp/so-long-tests/autoload-minor-mode-tests.el
new file mode 100644
index 0000000..5ce2834
--- /dev/null
+++ b/test/lisp/so-long-tests/autoload-minor-mode-tests.el
@@ -0,0 +1,52 @@
+;;; autoload-minor-mode-tests.el --- Test suite for so-long.el  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Phil Sainty <address@hidden>
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(load (expand-file-name "so-long-tests-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+
+(declare-function so-long-tests-remember "so-long-tests-helpers")
+(declare-function so-long-tests-assert-active "so-long-tests-helpers")
+(declare-function so-long-tests-assert-reverted "so-long-tests-helpers")
+
+;; We're testing the initial state.  We could alternatively use
+;; `unload-feature' to revert to that, but this option is simple.
+
+(autoload 'so-long "so-long")
+
+(ert-deftest so-long-tests-autoload-minor-mode ()
+  "File-local -*- so-long-action: so-long-minor-mode; eval: (so-long) -*-"
+  (with-temp-buffer
+    (so-long-tests-remember)
+    (insert "-*- so-long-action: so-long-minor-mode; eval: (so-long) -*-\n")
+    (put 'so-long-action 'safe-local-variable #'symbolp)
+    (push '(eval . (so-long)) safe-local-variable-values)
+    (hack-local-variables)
+    (should (eq so-long-action 'so-long-minor-mode))
+    (so-long-tests-assert-active 'so-long-minor-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'so-long-minor-mode)))
+
+;;; autoload-minor-mode-tests.el ends here
diff --git a/test/lisp/so-long-tests/so-long-tests-helpers.el 
b/test/lisp/so-long-tests/so-long-tests-helpers.el
new file mode 100644
index 0000000..88b6799
--- /dev/null
+++ b/test/lisp/so-long-tests/so-long-tests-helpers.el
@@ -0,0 +1,104 @@
+;;; so-long-tests-helpers.el --- Test suite for so-long.el  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Phil Sainty <address@hidden>
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'so-long)
+
+(defvar longlines-mode)
+(declare-function longlines-mode "longlines")
+
+(defvar so-long-tests-memory nil
+  "Original values of minor modes and variables.")
+
+(defun so-long-tests-assert-active (action &optional ignore-so-long-action)
+  "Assert that ACTION is active."
+  (cl-destructuring-bind (_key _label actionfunc revertfunc)
+      (assq action so-long-action-alist)
+    (unless ignore-so-long-action
+      (should (eq so-long-action action)))
+    (should (eq so-long-function actionfunc))
+    (should (eq so-long-revert-function revertfunc))
+    (should (eq so-long-enabled t))
+    (should (eq so-long--active t))
+    (pcase action
+      ('so-long-mode
+       (should (eq major-mode 'so-long-mode))
+       (so-long-tests-assert-overrides))
+      ('so-long-minor-mode
+       (should (eq so-long-minor-mode t))
+       (so-long-tests-assert-overrides))
+      ('longlines-mode
+       (should (eq longlines-mode t))))))
+
+(defun so-long-tests-assert-reverted (action &optional ignore-so-long-action)
+  "Assert that ACTION has been reverted."
+  (cl-destructuring-bind (_key _label actionfunc revertfunc)
+      (assq action so-long-action-alist)
+    (unless ignore-so-long-action
+      (should (eq so-long-action action)))
+    (should (eq so-long-function actionfunc))
+    (should (eq so-long-revert-function revertfunc))
+    (should (eq so-long-enabled t))
+    (should (eq so-long--active nil))
+    (pcase action
+      ('so-long-mode
+       (should-not (eq major-mode 'so-long-mode))
+       (so-long-tests-assert-overrides-reverted))
+      ('so-long-minor-mode
+       (should-not (eq so-long-minor-mode t))
+       (so-long-tests-assert-overrides-reverted))
+      ('longlines-mode
+       (should-not (eq longlines-mode t))))))
+
+(defun so-long-tests-assert-overrides ()
+  "Assert that overridden modes and variables have their expected values."
+  (dolist (ovar so-long-variable-overrides)
+    (when (boundp (car ovar))
+      (should (equal (symbol-value (car ovar)) (cdr ovar)))))
+  (dolist (mode so-long-minor-modes)
+    (when (boundp mode)
+      (should (eq (symbol-value mode) nil)))))
+
+(defun so-long-tests-assert-overrides-reverted ()
+  "Assert that each remembered variable has its original value."
+  (dolist (ovar so-long-tests-memory)
+    (when (boundp (car ovar))
+      (should (equal (symbol-value (car ovar)) (cdr ovar))))))
+
+(defun so-long-tests-remember ()
+  "Remember the original states of modes and variables."
+  (setq so-long-tests-memory nil)
+  (push (cons 'major-mode major-mode)
+        so-long-tests-memory)
+  (dolist (ovar so-long-variable-overrides)
+    (when (boundp (car ovar))
+      (push (cons (car ovar) (symbol-value (car ovar)))
+            so-long-tests-memory)))
+  (dolist (mode so-long-minor-modes)
+    (when (boundp mode)
+      (push (cons mode (symbol-value mode))
+            so-long-tests-memory))))
+
+(provide 'so-long-tests-helpers)
+;;; so-long-tests-helpers.el ends here
diff --git a/test/lisp/so-long-tests/so-long-tests.el 
b/test/lisp/so-long-tests/so-long-tests.el
new file mode 100644
index 0000000..3b35b64
--- /dev/null
+++ b/test/lisp/so-long-tests/so-long-tests.el
@@ -0,0 +1,311 @@
+;;; so-long-tests.el --- Test suite for so-long.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Phil Sainty <address@hidden>
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Most of these tests use the shebang #!emacs to get `normal-mode' to
+;; select `emacs-lisp-mode', as using a file-local mode variable might
+;; trigger `so-long-file-local-mode-function'.
+
+;; Running the tests with "make lisp/so-long-tests" is like:
+;;
+;; HOME=/nonexistent EMACSLOADPATH= LC_ALL=C \
+;; EMACS_TEST_DIRECTORY=/home/phil/emacs/trunk/repository/test \
+;; "../src/emacs" --no-init-file --no-site-file --no-site-lisp \
+;; -L ":." -l ert -l lisp/so-long-tests.el --batch --eval \
+;; '(ert-run-tests-batch-and-exit (quote (not (tag :unstable))))'
+;;
+;; See also `ert-run-tests-batch-and-exit'.
+
+;;; Code:
+
+(require 'ert)
+(require 'so-long)
+(load (expand-file-name "so-long-tests-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+
+(declare-function so-long-tests-remember "so-long-tests-helpers")
+(declare-function so-long-tests-assert-active "so-long-tests-helpers")
+(declare-function so-long-tests-assert-reverted "so-long-tests-helpers")
+
+;; Enable the automated behaviour for all tests.
+(global-so-long-mode 1)
+
+(ert-deftest so-long-tests-threshold-under ()
+  "Under threshold."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1- so-long-threshold) ?x))
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode))))
+
+(ert-deftest so-long-tests-threshold-at ()
+  "At length threshold."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1- so-long-threshold) ?x))
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode))))
+
+(ert-deftest so-long-tests-threshold-over ()
+  "Over length threshold."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (normal-mode)
+    (so-long-tests-remember)
+    (insert (make-string (1+ so-long-threshold) ?x))
+    (normal-mode)
+    (so-long-tests-assert-active 'so-long-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'so-long-mode)))
+
+(ert-deftest so-long-tests-skip-comments ()
+  "Skip leading shebang, whitespace, and comments."
+  ;; Long comment, no newline.
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1+ so-long-threshold) ?\;))
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode)))
+  ;; Long comment, with newline.
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1+ so-long-threshold) ?\;))
+    (insert "\n")
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode)))
+  ;; Long comment, with short text following.
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1+ so-long-threshold) ?\;))
+    (insert "\n")
+    (insert (make-string so-long-threshold ?x))
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode)))
+  ;; Long comment, with long text following.
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1+ so-long-threshold) ?\;))
+    (insert "\n")
+    (insert (make-string (1+ so-long-threshold) ?x))
+    (normal-mode)
+    (should (eq major-mode 'so-long-mode))))
+
+(ert-deftest so-long-tests-max-lines ()
+  "Give up after `so-long-max-lines'."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    ;; Insert exactly `so-long-max-lines' non-comment lines, followed
+    ;; by a long line.
+    (dotimes (_ so-long-max-lines)
+      (insert "x\n"))
+    (insert (make-string (1+ so-long-threshold) ?x))
+    (normal-mode)
+    (should (eq major-mode 'emacs-lisp-mode))
+    ;; If `so-long-max-lines' is nil, don't give up the search.
+    (let ((so-long-max-lines nil))
+      (normal-mode)
+      (should (eq major-mode 'so-long-mode)))
+    ;; If `so-long-skip-leading-comments' is nil, all lines are
+    ;; counted, and so the shebang line counts, which makes the
+    ;; long line one line further away.
+    (let ((so-long-skip-leading-comments nil)
+          (so-long-max-lines (1+ so-long-max-lines)))
+      (normal-mode)
+      (should (eq major-mode 'emacs-lisp-mode))
+      (let ((so-long-max-lines (1+ so-long-max-lines)))
+        (normal-mode)
+        (should (eq major-mode 'so-long-mode))))))
+
+(ert-deftest so-long-tests-actions ()
+  "Test each of the standard actions."
+  (dolist (action (mapcar #'car so-long-action-alist))
+    (with-temp-buffer
+      (insert "#!emacs\n")
+      (normal-mode)
+      (so-long-tests-remember)
+      (insert (make-string (1+ so-long-threshold) ?x))
+      (let ((so-long-action action))
+        (normal-mode)
+        (so-long-tests-assert-active action)
+        (so-long-revert)
+        (so-long-tests-assert-reverted action)))))
+
+(ert-deftest so-long-tests-target-modes ()
+  "Targeted major modes."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    (insert (make-string (1+ so-long-threshold) ?x))
+    ;; Nil target modes.
+    (let ((so-long-target-modes nil))
+      (normal-mode)
+      (should (eq major-mode 'emacs-lisp-mode)))
+    ;; Non-matching target modes.
+    (let ((so-long-target-modes '(text-mode)))
+      (normal-mode)
+      (should (eq major-mode 'emacs-lisp-mode)))
+    ;; Matching mode (direct).
+    (let ((so-long-target-modes '(emacs-lisp-mode)))
+      (normal-mode)
+      (should (eq major-mode 'so-long-mode)))
+    ;; Matching mode (indirect).
+    (let ((so-long-target-modes '(prog-mode)))
+      (normal-mode)
+      (should (eq major-mode 'so-long-mode)))))
+
+(ert-deftest so-long-tests-predicate ()
+  "Custom predicate function."
+  (with-temp-buffer
+    (insert "#!emacs\n")
+    ;; Always false.
+    (let ((so-long-predicate #'ignore))
+      (normal-mode)
+      (should (eq major-mode 'emacs-lisp-mode)))
+    ;; Always true.
+    (let ((so-long-predicate (lambda () t)))
+      (normal-mode)
+      (should (eq major-mode 'so-long-mode)))))
+
+(ert-deftest so-long-tests-file-local-action ()
+  "File-local action."
+  (with-temp-buffer
+    (setq buffer-file-name (concat (make-temp-name "so-long-tests-") ".el"))
+    (normal-mode)
+    (so-long-tests-remember)
+    (insert ";; -*- so-long-action:so-long-minor-mode; -*-\n")
+    (put 'so-long-action 'safe-local-variable #'symbolp)
+    (insert (make-string (1+ so-long-threshold) ?x))
+    (normal-mode)
+    (so-long-tests-assert-active 'so-long-minor-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'so-long-minor-mode)))
+
+(ert-deftest so-long-tests-file-local-action-eval-so-long ()
+  "File-local action and eval:(so-long)."
+  (with-temp-buffer
+    (setq buffer-file-name (concat (make-temp-name "so-long-tests-") ".el"))
+    (normal-mode)
+    (so-long-tests-remember)
+    (insert ";; -*- so-long-action:so-long-minor-mode; eval:(so-long) -*-\n")
+    (put 'so-long-action 'safe-local-variable #'symbolp)
+    (push '(eval . (so-long)) safe-local-variable-values)
+    (normal-mode)
+    (so-long-tests-assert-active 'so-long-minor-mode)
+    (so-long-revert)
+    (so-long-tests-assert-reverted 'so-long-minor-mode)))
+
+(defmacro so-long-tests-deftest-file-local-emacs-lisp-mode
+    (sym docstring file-local-spec)
+  "Generate tests for using `emacs-lisp-mode' as a file-local mode."
+  `(ert-deftest ,sym ()
+     ,docstring
+     (let ((orig so-long-file-local-mode-function))
+       ;; Do nothing at all.
+       (setq-default so-long-file-local-mode-function 'so-long-inhibit)
+       (with-temp-buffer
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         ;; Remember the `emacs-lisp-mode' state.  The other cases
+         ;; will validate the 'reverted' state against this.
+         (so-long-tests-remember)
+         (should (eq major-mode 'emacs-lisp-mode)))
+       ;; Downgrade the action from major mode to minor mode.
+       (setq-default so-long-file-local-mode-function 'so-long-mode-downgrade)
+       (with-temp-buffer
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         (so-long-tests-assert-active 'so-long-minor-mode t)
+         (so-long-revert)
+         (so-long-tests-assert-reverted 'so-long-minor-mode t))
+       ;; Do not treat the file-local mode specially.
+       (setq-default so-long-file-local-mode-function nil)
+       (with-temp-buffer
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         (so-long-tests-assert-active 'so-long-mode)
+         (so-long-revert)
+         (so-long-tests-assert-reverted 'so-long-mode))
+       ;; end
+       (setq-default so-long-file-local-mode-function orig))))
+
+(so-long-tests-deftest-file-local-emacs-lisp-mode
+  so-long-tests-file-local-emacs-lisp-mode-short-form
+  "File-local mode (short form). -*- emacs-lisp -*-"
+  ";; -*- emacs-lisp -*-\n")
+
+(so-long-tests-deftest-file-local-emacs-lisp-mode
+  so-long-tests-file-local-emacs-lisp-mode-long-form
+  "File-local mode (long form). -*- emacs-lisp -*-"
+  ";; -*- mode: emacs-lisp -*-\n")
+
+(defmacro so-long-tests-deftest-file-local-so-long-mode
+    (sym docstring file-local-spec)
+  "Generate tests for using `so-long-mode' as a file-local mode."
+  `(ert-deftest ,sym ()
+     ,docstring
+     (let ((orig so-long-file-local-mode-function))
+       ;; Do nothing at all.
+       (setq-default so-long-file-local-mode-function 'so-long-inhibit)
+       (with-temp-buffer
+         ;; Remember the new-buffer state.  The other cases will
+         ;; validate the 'reverted' state against this.
+         (so-long-tests-remember)
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         (should (eq major-mode 'so-long-mode)))
+       ;; Downgrade from major mode to minor mode.
+       (setq-default so-long-file-local-mode-function 'so-long-mode-downgrade)
+       (with-temp-buffer
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         (so-long-tests-assert-active 'so-long-mode)
+         (so-long-revert)
+         (so-long-tests-assert-reverted 'so-long-mode))
+       ;; Do not treat the file-local mode specially.
+       (setq-default so-long-file-local-mode-function nil)
+       (with-temp-buffer
+         (insert ,file-local-spec)
+         (insert (make-string (1+ so-long-threshold) ?x))
+         (normal-mode)
+         (so-long-tests-assert-active 'so-long-mode)
+         (so-long-revert)
+         (so-long-tests-assert-reverted 'so-long-mode))
+       ;; end
+       (setq-default so-long-file-local-mode-function orig))))
+
+(so-long-tests-deftest-file-local-so-long-mode
+  so-long-tests-file-local-so-long-mode-short-form
+  "File-local mode (short form). -*- so-long -*-"
+  ";; -*- so-long -*-\n")
+
+(so-long-tests-deftest-file-local-so-long-mode
+  so-long-tests-file-local-so-long-mode-long-form
+  "File-local mode (long form). -*- mode: so-long -*-"
+  ";; -*- mode: so-long -*-\n")
+
+;;; so-long-tests.el ends here



reply via email to

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