aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimen Heggestøyl2019-05-26 11:11:23 +0200
committerSimen Heggestøyl2019-05-26 11:22:27 +0200
commita51ab2f357af49f67feaa6e9484fcca2c91f5cb4 (patch)
treed5ed557ed8728b76cea4cb2952375cb6622112b7
parent852d28176990d035366142bfde36a0440a317228 (diff)
downloademacs-a51ab2f357af49f67feaa6e9484fcca2c91f5cb4.tar.gz
emacs-a51ab2f357af49f67feaa6e9484fcca2c91f5cb4.zip
Use lexical-binding in paren.el and add tests
* lisp/paren.el: Use lexical-binding. (show-paren--default): Use imperative form in doc-string. * test/lisp/paren-tests.el: New file with tests for paren.el.
-rw-r--r--lisp/paren.el4
-rw-r--r--test/lisp/paren-tests.el121
2 files changed, 123 insertions, 2 deletions
diff --git a/lisp/paren.el b/lisp/paren.el
index 13908d46eef..c7d782a8a1d 100644
--- a/lisp/paren.el
+++ b/lisp/paren.el
@@ -1,4 +1,4 @@
1;;; paren.el --- highlight matching paren 1;;; paren.el --- highlight matching paren -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1993, 1996, 2001-2019 Free Software Foundation, Inc. 3;; Copyright (C) 1993, 1996, 2001-2019 Free Software Foundation, Inc.
4 4
@@ -173,7 +173,7 @@ if there's no opener/closer near point, or a list of the form
173Where HERE-BEG..HERE-END is expected to be near point.") 173Where HERE-BEG..HERE-END is expected to be near point.")
174 174
175(defun show-paren--default () 175(defun show-paren--default ()
176 "Finds the opener/closer near point and its match. 176 "Find the opener/closer near point and its match.
177 177
178It is the default value of `show-paren-data-function'." 178It is the default value of `show-paren-data-function'."
179 (let* ((temp (show-paren--locate-near-paren)) 179 (let* ((temp (show-paren--locate-near-paren))
diff --git a/test/lisp/paren-tests.el b/test/lisp/paren-tests.el
new file mode 100644
index 00000000000..5aaea8a7d94
--- /dev/null
+++ b/test/lisp/paren-tests.el
@@ -0,0 +1,121 @@
1;;; paren-tests.el --- Tests for paren.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Simen Heggestøyl <simenheg@gmail.com>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'ert)
30(require 'paren)
31
32(ert-deftest paren-tests-unescaped-p ()
33 (with-temp-buffer
34 (insert "(insert)")
35 (backward-char)
36 (should (show-paren--unescaped-p (point)))
37 (insert "\\")
38 (should-not (show-paren--unescaped-p (point)))))
39
40(ert-deftest paren-tests-categorize-paren ()
41 (with-temp-buffer
42 (insert "(insert)")
43 (backward-char)
44 (should (equal (show-paren--categorize-paren (point))
45 (cons -1 (+ (point) 1))))
46 (goto-char (point-min))
47 (should (equal (show-paren--categorize-paren (point))
48 (cons 1 (point))))))
49
50(ert-deftest paren-tests-locate-near-paren ()
51 (with-temp-buffer
52 (let ((show-paren-when-point-inside-paren nil)
53 (show-paren-when-point-in-periphery nil))
54 (insert "(insert)")
55 (should (equal (show-paren--locate-near-paren)
56 (cons -1 (point))))
57 (backward-char)
58 (should-not (show-paren--locate-near-paren))
59 (goto-char (point-min))
60 (should (equal (show-paren--locate-near-paren)
61 (cons 1 (point-min))))
62 (forward-char)
63 (should-not (show-paren--locate-near-paren)))))
64
65(ert-deftest paren-tests-locate-near-paren-inside ()
66 (with-temp-buffer
67 (let ((show-paren-when-point-inside-paren t)
68 (show-paren-when-point-in-periphery nil))
69 (insert "(insert)")
70 (should (equal (show-paren--locate-near-paren)
71 (cons -1 (point))))
72 (backward-char)
73 (should (equal (show-paren--locate-near-paren)
74 (cons -1 (+ (point) 1))))
75 (goto-char (point-min))
76 (should (equal (show-paren--locate-near-paren)
77 (cons 1 (point-min))))
78 (forward-char)
79 (should (equal (show-paren--locate-near-paren)
80 (cons 1 (point-min)))))))
81
82(ert-deftest paren-tests-locate-near-paren-in-periphery ()
83 (with-temp-buffer
84 (let ((show-paren-when-point-inside-paren nil)
85 (show-paren-when-point-in-periphery t))
86 (insert " (insert) ")
87 (should (equal (show-paren--locate-near-paren)
88 (cons -1 (- (point) 1))))
89 (backward-char 2)
90 (should-not (show-paren--locate-near-paren))
91 (goto-char (point-min))
92 (should (equal (show-paren--locate-near-paren)
93 (cons 1 (+ (point) 1))))
94 (forward-char)
95 (should (equal (show-paren--locate-near-paren)
96 (cons 1 (point))))
97 (forward-char)
98 (should-not (show-paren--locate-near-paren)))))
99
100(ert-deftest paren-tests-default ()
101 (with-temp-buffer
102 (insert "(insert")
103 (goto-char (point-min))
104 (should (equal (show-paren--default)
105 (list (point) (+ (point) 1)
106 nil nil
107 t)))
108 (goto-char (point-max))
109 (insert ")")
110 (should (equal (show-paren--default)
111 (list (- (point) 1) (point)
112 (point-min) (+ (point-min) 1)
113 nil)))
114 (goto-char (point-min))
115 (should (equal (show-paren--default)
116 (list (point) (+ (point) 1)
117 (- (point-max) 1) (point-max)
118 nil)))))
119
120(provide 'paren-tests)
121;;; paren-tests.el ends here