]> code.delx.au - gnu-emacs-elpa/blob - packages/adjust-parens/adjust-parens-tests.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / adjust-parens / adjust-parens-tests.el
1 ;;; adjust-parens-tests.el --- Tests of adjust-parens package
2
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5 ;; Author: Barry O'Reilly <gundaetiapo@gmail.com>
6
7 ;; This program 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.
11
12 ;; This program 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.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;;; Code:
23
24 (require 'ert)
25 (require 'adjust-parens)
26
27 (defun apt-check-buffer (text-before-point text-after-point)
28 (should (string= text-before-point
29 (buffer-substring-no-properties (point-min)
30 (point))))
31 (should (string= text-after-point
32 (buffer-substring-no-properties (point)
33 (point-max)))))
34
35 (ert-deftest apt-mode-test ()
36 (with-temp-buffer
37 (emacs-lisp-mode)
38 (adjust-parens-mode -1)
39 (should-not (eq (key-binding (kbd "TAB"))
40 #'lisp-indent-adjust-parens))
41 (adjust-parens-mode 1)
42 (should (eq (key-binding (kbd "TAB"))
43 #'lisp-indent-adjust-parens))
44 (adjust-parens-mode -1)
45 (should-not (eq (key-binding (kbd "TAB"))
46 #'lisp-indent-adjust-parens))))
47
48 (ert-deftest apt-near-bob-test ()
49 (with-temp-buffer
50 (emacs-lisp-mode)
51 (adjust-parens-mode 1)
52 (insert "(foo)\n")
53 (lisp-indent-adjust-parens)
54 (apt-check-buffer "(foo\n " ")")))
55
56 (ert-deftest apt-indent-dedent-test ()
57 (with-temp-buffer
58 (emacs-lisp-mode)
59 (adjust-parens-mode 1)
60 (setq indent-tabs-mode nil)
61 (insert ";;\n"
62 "(let ((x 10) (y (some-func 20))))\n"
63 "; Comment")
64 (back-to-indentation)
65 (lisp-indent-adjust-parens)
66 (apt-check-buffer (concat ";;\n"
67 "(let ((x 10) (y (some-func 20)))\n"
68 " ")
69 "); Comment")
70 (lisp-indent-adjust-parens 3)
71 (apt-check-buffer (concat ";;\n"
72 "(let ((x 10) (y (some-func 20\n"
73 " ")
74 ")))); Comment")
75 (lisp-dedent-adjust-parens 2)
76 (apt-check-buffer (concat ";;\n"
77 "(let ((x 10) (y (some-func 20))\n"
78 " ")
79 ")); Comment")
80 ;; Check what happens when point is not at the indentation, or
81 ;; indentation is not correct, or both
82 (beginning-of-line) ; Point not at indentation
83 ;; Should simply move point to indentation and not change buffer
84 (lisp-indent-adjust-parens)
85 (apt-check-buffer (concat ";;\n"
86 "(let ((x 10) (y (some-func 20))\n"
87 " ")
88 ")); Comment")
89
90 (delete-backward-char 3) ; Incorrect indentation
91 ;; Should reindent line via indent-for-tab-command and move point to
92 ;; indentation but not change parens
93 (lisp-indent-adjust-parens)
94 (apt-check-buffer (concat ";;\n"
95 "(let ((x 10) (y (some-func 20))\n"
96 " ")
97 ")); Comment")
98 (insert " ") ; Wrong indentation
99 (forward-char 2) ; Point is past indentation
100 ;; Should reindent line without moving point or changing parens
101 (lisp-indent-adjust-parens)
102 (apt-check-buffer (concat ";;\n"
103 "(let ((x 10) (y (some-func 20))\n"
104 " ))")
105 "; Comment")))
106
107 ;;; adjust-parens-tests.el ends here