1 ;;; adjust-parens-tests.el --- Tests of adjust-parens package
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; Author: Barry O'Reilly <gundaetiapo@gmail.com>
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.
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.
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/>.
25 (require 'adjust-parens)
27 (defun apt-check-buffer (text-before-point text-after-point)
28 (should (string= text-before-point
29 (buffer-substring-no-properties (point-min)
31 (should (string= text-after-point
32 (buffer-substring-no-properties (point)
35 (ert-deftest apt-mode-test ()
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))))
48 (ert-deftest apt-near-bob-test ()
51 (adjust-parens-mode 1)
53 (lisp-indent-adjust-parens)
54 (apt-check-buffer "(foo\n " ")")))
56 (ert-deftest apt-indent-dedent-test ()
59 (adjust-parens-mode 1)
60 (setq indent-tabs-mode nil)
62 "(let ((x 10) (y (some-func 20))))\n"
65 (lisp-indent-adjust-parens)
66 (apt-check-buffer (concat ";;\n"
67 "(let ((x 10) (y (some-func 20)))\n"
70 (lisp-indent-adjust-parens 3)
71 (apt-check-buffer (concat ";;\n"
72 "(let ((x 10) (y (some-func 20\n"
75 (lisp-dedent-adjust-parens 2)
76 (apt-check-buffer (concat ";;\n"
77 "(let ((x 10) (y (some-func 20))\n"
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"
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"
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"
107 ;;; adjust-parens-tests.el ends here