aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorBasil L. Contovounesios2019-03-27 15:13:25 +0000
committerBasil L. Contovounesios2019-03-31 17:08:21 +0100
commit0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6 (patch)
treea50516ab3cc6eebcfc683a037a88d31a805c8a7f /test
parent99be0aba4defb8377cb148f7805ea07babc6182f (diff)
downloademacs-0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6.tar.gz
emacs-0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6.zip
Fix recently extended delete-indentation behavior
* doc/lispref/text.texi (User-Level Deletion): Document new optional arguments of delete-indentation. * lisp/simple.el (delete-indentation): Do not barf if called interactively when region is inactive. (bug#35021) Do not skip blank lines. (bug#35036) Consistently deactivate mark even when no text was changed. Handle active region spanning a single line. * test/lisp/simple-tests.el (simple-test--buffer-substrings): New convenience function. (simple-test--dummy-buffer, simple-test--transpositions): Use it. (simple-delete-indentation-no-region) (simple-delete-indentation-inactive-region): Update commentary. Call delete-indentation interactively when testing for behavior with inactive region and region is not explicitly defined. (simple-delete-indentation-blank-line) (simple-delete-indentation-boundaries) (simple-delete-indentation-region) (simple-delete-indentation-prefix): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/simple-tests.el176
1 files changed, 142 insertions, 34 deletions
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index d9f059c8fc2..cc2feebbefa 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -22,6 +22,11 @@
22(require 'ert) 22(require 'ert)
23(eval-when-compile (require 'cl-lib)) 23(eval-when-compile (require 'cl-lib))
24 24
25(defun simple-test--buffer-substrings ()
26 "Return cons of buffer substrings before and after point."
27 (cons (buffer-substring (point-min) (point))
28 (buffer-substring (point) (point-max))))
29
25(defmacro simple-test--dummy-buffer (&rest body) 30(defmacro simple-test--dummy-buffer (&rest body)
26 (declare (indent 0) 31 (declare (indent 0)
27 (debug t)) 32 (debug t))
@@ -31,10 +36,7 @@
31 (insert "(a b") 36 (insert "(a b")
32 (save-excursion (insert " c d)")) 37 (save-excursion (insert " c d)"))
33 ,@body 38 ,@body
34 (with-no-warnings 39 (with-no-warnings (simple-test--buffer-substrings))))
35 (cons (buffer-substring (point-min) (point))
36 (buffer-substring (point) (point-max))))))
37
38 40
39 41
40;;; `transpose-sexps' 42;;; `transpose-sexps'
@@ -46,8 +48,7 @@
46 (insert "(s1) (s2) (s3) (s4) (s5)") 48 (insert "(s1) (s2) (s3) (s4) (s5)")
47 (backward-sexp 1) 49 (backward-sexp 1)
48 ,@body 50 ,@body
49 (cons (buffer-substring (point-min) (point)) 51 (simple-test--buffer-substrings)))
50 (buffer-substring (point) (point-max)))))
51 52
52;;; Transposition with negative args (bug#20698, bug#21885) 53;;; Transposition with negative args (bug#20698, bug#21885)
53(ert-deftest simple-transpose-subr () 54(ert-deftest simple-transpose-subr ()
@@ -215,37 +216,144 @@
215 216
216 217
217;;; `delete-indentation' 218;;; `delete-indentation'
219
218(ert-deftest simple-delete-indentation-no-region () 220(ert-deftest simple-delete-indentation-no-region ()
219 "delete-indentation works when no mark is set." 221 "Test `delete-indentation' when no mark is set; see bug#35021."
220 ;; interactive \r returns nil for BEG END args 222 (with-temp-buffer
221 (unwind-protect 223 (insert " first \n second \n third \n fourth ")
222 (with-temp-buffer 224 (should-not (mark t))
223 (insert (concat "zero line \n" 225 ;; Without prefix argument.
224 "first line \n" 226 (should-not (call-interactively #'delete-indentation))
225 "second line")) 227 (should (equal (simple-test--buffer-substrings)
226 (delete-indentation) 228 '(" first \n second \n third" . " fourth ")))
227 (should (string-equal 229 (should-not (call-interactively #'delete-indentation))
228 (buffer-string) 230 (should (equal (simple-test--buffer-substrings)
229 (concat "zero line \n" 231 '(" first \n second" . " third fourth ")))
230 "first line second line"))) 232 ;; With prefix argument.
231 ))) 233 (goto-char (point-min))
234 (let ((current-prefix-arg '(4)))
235 (should-not (call-interactively #'delete-indentation)))
236 (should (equal (simple-test--buffer-substrings)
237 '(" first" . " second third fourth ")))))
232 238
233(ert-deftest simple-delete-indentation-inactive-region () 239(ert-deftest simple-delete-indentation-inactive-region ()
234 "delete-indentation ignores inactive region." 240 "Test `delete-indentation' with an inactive region."
235 ;; interactive \r returns non-nil for BEG END args 241 (with-temp-buffer
236 (unwind-protect 242 (insert " first \n second \n third ")
237 (with-temp-buffer 243 (set-marker (mark-marker) (point-min))
238 (insert (concat "zero line \n" 244 (should (mark t))
239 "first line \n" 245 (should-not (call-interactively #'delete-indentation))
240 "second line")) 246 (should (equal (simple-test--buffer-substrings)
241 (push-mark (point-min) t t) 247 '(" first \n second" . " third ")))))
242 (deactivate-mark) 248
243 (delete-indentation) 249(ert-deftest simple-delete-indentation-blank-line ()
244 (should (string-equal 250 "Test `delete-indentation' does not skip blank lines.
245 (buffer-string) 251See bug#35036."
246 (concat "zero line \n" 252 (with-temp-buffer
247 "first line second line"))) 253 (insert "\n\n third \n \n \n sixth \n\n")
248 ))) 254 ;; Without prefix argument.
255 (should-not (delete-indentation))
256 (should (equal (simple-test--buffer-substrings)
257 '("\n\n third \n \n \n sixth \n" . "")))
258 (should-not (delete-indentation))
259 (should (equal (simple-test--buffer-substrings)
260 '("\n\n third \n \n \n sixth" . "")))
261 (should-not (delete-indentation))
262 (should (equal (simple-test--buffer-substrings)
263 '("\n\n third \n \n" . "sixth")))
264 ;; With prefix argument.
265 (goto-char (point-min))
266 (should-not (delete-indentation t))
267 (should (equal (simple-test--buffer-substrings)
268 '("" . "\n third \n \nsixth")))
269 (should-not (delete-indentation t))
270 (should (equal (simple-test--buffer-substrings)
271 '("" . "third \n \nsixth")))
272 (should-not (delete-indentation t))
273 (should (equal (simple-test--buffer-substrings)
274 '("third" . "\nsixth")))
275 (should-not (delete-indentation t))
276 (should (equal (simple-test--buffer-substrings)
277 '("third" . " sixth")))))
278
279(ert-deftest simple-delete-indentation-boundaries ()
280 "Test `delete-indentation' motion at buffer boundaries."
281 (with-temp-buffer
282 (insert " first \n second \n third ")
283 ;; Stay at EOB.
284 (should-not (delete-indentation t))
285 (should (equal (simple-test--buffer-substrings)
286 '(" first \n second \n third " . "")))
287 ;; Stay at BOB.
288 (forward-line -1)
289 (save-restriction
290 (narrow-to-region (point) (line-end-position))
291 (should-not (delete-indentation))
292 (should (equal (simple-test--buffer-substrings)
293 '("" . " second ")))
294 ;; Go to EOB.
295 (should-not (delete-indentation t))
296 (should (equal (simple-test--buffer-substrings)
297 '(" second " . ""))))
298 ;; Go to BOB.
299 (end-of-line 0)
300 (should-not (delete-indentation))
301 (should (equal (simple-test--buffer-substrings)
302 '("" . " first \n second \n third ")))))
303
304(ert-deftest simple-delete-indentation-region ()
305 "Test `delete-indentation' with an active region."
306 (with-temp-buffer
307 ;; Empty region.
308 (insert " first ")
309 (should-not (delete-indentation nil (point) (point)))
310 (should (equal (simple-test--buffer-substrings)
311 '(" first " . "")))
312 ;; Single line.
313 (should-not (delete-indentation
314 nil (line-beginning-position) (1- (point))))
315 (should (equal (simple-test--buffer-substrings)
316 '("" . " first ")))
317 (should-not (delete-indentation nil (1+ (point)) (line-end-position)))
318 (should (equal (simple-test--buffer-substrings)
319 '(" " . "first ")))
320 (should-not (delete-indentation
321 nil (line-beginning-position) (line-end-position)))
322 (should (equal (simple-test--buffer-substrings)
323 '("" . " first ")))
324 ;; Multiple lines.
325 (goto-char (point-max))
326 (insert "\n second \n third \n fourth ")
327 (goto-char (point-min))
328 (should-not (delete-indentation
329 nil (line-end-position) (line-beginning-position 2)))
330 (should (equal (simple-test--buffer-substrings)
331 '(" first" . " second \n third \n fourth ")))
332 (should-not (delete-indentation
333 nil (point) (1+ (line-beginning-position 2))))
334 (should (equal (simple-test--buffer-substrings)
335 '(" first second" . " third \n fourth ")))
336 ;; Prefix argument overrides region.
337 (should-not (delete-indentation t (point-min) (point)))
338 (should (equal (simple-test--buffer-substrings)
339 '(" first second third" . " fourth ")))))
340
341(ert-deftest simple-delete-indentation-prefix ()
342 "Test `delete-indentation' with a fill prefix."
343 (with-temp-buffer
344 (insert "> first \n> second \n> third \n> fourth ")
345 (let ((fill-prefix ""))
346 (delete-indentation))
347 (should (equal (simple-test--buffer-substrings)
348 '("> first \n> second \n> third" . " > fourth ")))
349 (let ((fill-prefix "<"))
350 (delete-indentation))
351 (should (equal (simple-test--buffer-substrings)
352 '("> first \n> second" . " > third > fourth ")))
353 (let ((fill-prefix ">"))
354 (delete-indentation))
355 (should (equal (simple-test--buffer-substrings)
356 '("> first" . " second > third > fourth ")))))
249 357
250 358
251;;; `delete-trailing-whitespace' 359;;; `delete-trailing-whitespace'