Add tests for secrets.el
[emacs.git] / test / lisp / whitespace-tests.el
blobb6e1849dbdcdd29f53f77e991c1c0f663b879b0b
1 ;;; whitespace-tests.el --- Test suite for whitespace -*- lexical-binding: t -*-
3 ;; Copyright (C) 2016-2018 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 ;;; Code:
22 (require 'ert)
23 (require 'whitespace)
25 (defun whitespace-tests--cleanup-string (string)
26 (with-temp-buffer
27 (insert string)
28 (whitespace-cleanup)
29 (buffer-string)))
31 (ert-deftest whitespace-cleanup-eob ()
32 (let ((whitespace-style '(empty)))
33 (should (equal (whitespace-tests--cleanup-string "a\n")
34 "a\n"))
35 (should (equal (whitespace-tests--cleanup-string "a\n\n")
36 "a\n"))
37 (should (equal (whitespace-tests--cleanup-string "a\n\t\n")
38 "a\n"))
39 (should (equal (whitespace-tests--cleanup-string "a\n\t \n")
40 "a\n"))
41 (should (equal (whitespace-tests--cleanup-string "a\n\t \n\n")
42 "a\n"))
43 (should (equal (whitespace-tests--cleanup-string "\n\t\n")
44 ""))
45 ;; Whitespace at end of non-empty line is not covered by the
46 ;; `empty' style.
47 (should (equal (whitespace-tests--cleanup-string "a \n\t \n\n")
48 "a \n"))))
51 ;; We cannot call whitespace-mode because it will do nothing in batch
52 ;; mode. So we call its innards instead.
53 (defun whitespace-tests-whitespace-mode-on ()
54 "Turn whitespace-mode on even in batch mode."
55 (whitespace-turn-on)
56 (whitespace-action-when-on)
57 (setq whitespace-mode t))
59 (ert-deftest whitespace-tests-display-tables ()
60 "Test whitespace stores and restores the buffer display table - bug26892."
61 (with-temp-buffer
62 (whitespace-mode -1) ; turn off in case global ws mode is active
63 (let ((whitespace-style '(space-mark tab-mark newline-mark))
64 (whitespace-display-mappings '((space-mark 32 [183] [46])
65 (space-mark 160 [164] [95])
66 (newline-mark 10 [36 10])
67 (tab-mark 9 [187 9] [92 9])))
68 (buffer-display-table nil))
69 ;test the display table actually changes
70 (should-not (equal nil
71 (progn (whitespace-tests-whitespace-mode-on)
72 buffer-display-table)))
73 ;test the display table restores correctly
74 (should (equal nil
75 (progn (whitespace-turn-off)
76 buffer-display-table)))
77 ;test the stored display table is preserved
78 (should (equal nil
79 (progn (whitespace-tests-whitespace-mode-on)
80 (whitespace-tests-whitespace-mode-on)
81 (whitespace-turn-off)
82 buffer-display-table))))))
84 (provide 'whitespace-tests)
86 ;;; whitespace-tests.el ends here