aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Kangas2019-06-01 18:47:14 -0700
committerPaul Eggert2019-06-01 18:52:22 -0700
commit227b3c89f05f22556d49e127f236edc2d3cfc87a (patch)
treee2261b57f44f05c795b191148cf00606106df17b /test
parent5ad5c4ac991bc2b35a4a92e22f17a5a73009d7bc (diff)
downloademacs-227b3c89f05f22556d49e127f236edc2d3cfc87a.tar.gz
emacs-227b3c89f05f22556d49e127f236edc2d3cfc87a.zip
Use lexical-binding in paragraphs.el and add tests
* lisp/textmodes/paragraphs.el: Use lexical-binding. (repunctuate-sentences): Make it work non-interactively. * test/lisp/textmodes/paragraphs-tests.el: New file.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/textmodes/paragraphs-tests.el165
1 files changed, 165 insertions, 0 deletions
diff --git a/test/lisp/textmodes/paragraphs-tests.el b/test/lisp/textmodes/paragraphs-tests.el
new file mode 100644
index 00000000000..5772756740f
--- /dev/null
+++ b/test/lisp/textmodes/paragraphs-tests.el
@@ -0,0 +1,165 @@
1;;; paragraphs-tests.el --- Tests for paragraphs.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Stefan Kangas <stefankangas@gmail.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'ert)
27;; (require 'paragraphs) ; loaded by default
28
29(ert-deftest paragraphs-tests-sentence-end ()
30 (should (> (length (sentence-end)) 0))
31 (let ((sentence-end "override works"))
32 (should (equal (sentence-end) sentence-end))))
33
34(ert-deftest paragraphs-tests-forward-backward-paragraph ()
35 (with-temp-buffer
36 (insert "AA\nAA\n\nBB\nBB\n")
37 (goto-char (point-min))
38 (forward-paragraph)
39 (should (equal (point) 7))
40 (forward-paragraph)
41 (should (equal (point) 14))
42 (backward-paragraph)
43 (should (equal (point) 7))
44 (backward-paragraph)
45 (should (equal (point) (point-min)))))
46
47(ert-deftest paragraphs-tests-mark-paragraph ()
48 (with-temp-buffer
49 (insert "AA\nAA\n\nBB\nBB\n")
50 (goto-char (point-min))
51 (mark-paragraph)
52 (should mark-active)
53 (should (equal (mark) 7)))
54 (should-error (mark-paragraph 0)))
55
56(ert-deftest paragraphs-tests-kill-paragraph ()
57 (with-temp-buffer
58 (insert "AA\nAA\n\nBB\nBB\n")
59 (goto-char (point-min))
60 (kill-paragraph nil)
61 (should (equal (buffer-string) "\nBB\nBB\n"))))
62
63(ert-deftest paragraphs-tests-backward-kill-paragraph ()
64 (with-temp-buffer
65 (insert "AA\nAA\n\nBB\nBB\n")
66 (goto-char 7)
67 (backward-kill-paragraph nil)
68 (should (equal (buffer-string) "\nBB\nBB\n"))))
69
70(ert-deftest paragraphs-tests-transpose-paragraphs ()
71 (with-temp-buffer
72 (insert "AA\nAA\n\nBB\nBB\n")
73 (goto-char (point-min))
74 (transpose-paragraphs 1)
75 (should (equal (buffer-string) "\nBB\nBB\nAA\nAA\n"))))
76
77(ert-deftest paragraphs-tests-start-of-paragraph-text ()
78 (with-temp-buffer
79 (insert "AA\nAA\n\nBB\nBB\n")
80 (goto-char (point-max))
81 (start-of-paragraph-text)
82 (should (equal (point) 8))))
83
84(ert-deftest paragraphs-tests-end-of-paragraph-text ()
85 (with-temp-buffer
86 (insert "AA\nAA\n\nBB\nBB\n")
87 (goto-char (point-min))
88 (end-of-paragraph-text)
89 (should (equal (point) 6))))
90
91(ert-deftest paragraphs-tests-forward-sentence ()
92 (with-temp-buffer
93 (insert "First sentence. Second sentence.")
94 (goto-char (point-min))
95 (forward-sentence)
96 (should (equal (point) 16))
97 (goto-char (point-min))
98 (forward-sentence 2)
99 (should (equal (point) 34))))
100
101(ert-deftest paragraphs-tests-repunctuate-sentences ()
102 (with-temp-buffer
103 (insert "Just. Some. Sentences.")
104 (goto-char (point-min))
105 (repunctuate-sentences t)
106 (should (equal (buffer-string) "Just. Some. Sentences."))))
107
108(ert-deftest paragraphs-tests-backward-sentence ()
109 (with-temp-buffer
110 (insert "First sentence. Second sentence.")
111 (goto-char (point-max))
112 (backward-sentence)
113 (should (equal (point) 18))))
114
115(ert-deftest paragraphs-tests-kill-sentence ()
116 (with-temp-buffer
117 (insert "First sentence. Second sentence.")
118 (goto-char (point-min))
119 (kill-sentence)
120 (should (equal (buffer-string) " Second sentence."))))
121
122(ert-deftest paragraphs-tests-backward-kill-sentence ()
123 (with-temp-buffer
124 (insert "Should not be killed. Should be killed.")
125 (goto-char (point-max))
126 (backward-kill-sentence)
127 (should (equal (buffer-string) "Should not be killed. "))))
128
129(ert-deftest paragraphs-tests-mark-end-of-sentence ()
130 (with-temp-buffer
131 (insert "Example sentence. Followed by another one.")
132 (goto-char (point-min))
133 (mark-end-of-sentence 1)
134 (should mark-active)
135 (should (equal (mark) 18)))
136 (with-temp-buffer
137 (insert "Example sentence. Followed by another one.")
138 (goto-char (point-min))
139 (mark-end-of-sentence 2)
140 (should mark-active)
141 (should (equal (mark) 44)))
142 ;; FIXME: This does not work -- how do I do it?
143 (with-temp-buffer ; test repeating the command
144 (insert "Example sentence. Followed by another one.")
145 (goto-char (point-min))
146 (mark-end-of-sentence 1)
147 (setq last-command 'mark-end-of-sentence) ; hack
148 (mark-end-of-sentence 1)
149 (should mark-active)
150 (should (equal (mark) 18))))
151
152(ert-deftest paragraphs-tests-transpose-sentences ()
153 (with-temp-buffer
154 (insert "First sentence. Second sentence. Third sentence.")
155 (goto-char (point-min))
156 (transpose-sentences 1)
157 (should (equal (buffer-string)
158 "Second sentence. First sentence. Third sentence."))
159 (goto-char (point-min))
160 (transpose-sentences 2)
161 (should (equal (buffer-string)
162 "First sentence. Third sentence. Second sentence."))))
163
164(provide 'paragraphs-tests)
165;;; paragraphs-tests.el ends here