1 ;; Tests for various functions around applying a function to an indented block -*- lexical-binding: t -*-
3 (add-to-list 'load-path
".")
7 (ert-deftest apply-block-asserts
()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char
"\^@"))
10 (should (equal ert-Buf-mark-char
"\^?"))
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 (defun find-leftmost-column ()
16 "Call `rst-find-leftmost-column' with current region."
17 (rst-find-leftmost-column (region-beginning) (region-end)))
19 (ert-deftest rst-find-leftmost-column
()
20 "Tests for `rst-find-leftmost-column'."
21 (should (ert-equal-buffer-return
22 '(find-leftmost-column)
27 (should (ert-equal-buffer-return
28 '(find-leftmost-column)
34 (should (ert-equal-buffer-return
35 '(find-leftmost-column)
41 (should (ert-equal-buffer-return
42 '(find-leftmost-column)
49 (should (ert-equal-buffer-return
50 '(find-leftmost-column)
57 (should (ert-equal-buffer-return
58 '(find-leftmost-column)
65 (should (ert-equal-buffer-return
66 '(find-leftmost-column)
67 ; Empty lines contain spaces
78 (should (ert-equal-buffer-return
79 '(find-leftmost-column)
84 (should (ert-equal-buffer-return
85 '(find-leftmost-column)
92 (should (ert-equal-buffer-return
93 '(find-leftmost-column)
98 (should (ert-equal-buffer-return
99 '(find-leftmost-column)
106 (should (ert-equal-buffer-return
107 '(find-leftmost-column)
114 (should (ert-equal-buffer-return
115 '(find-leftmost-column)
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 (defun bullet-list-region (all)
127 "Call `rst-bullet-list-region' with current region and ALL."
128 (rst-bullet-list-region (region-beginning) (region-end) all
))
130 (ert-deftest rst-bullet-list-region
()
131 "Tests for `rst-bullet-list-region'."
132 (let ((rst-preferred-bullets '(?
*)))
133 (should (ert-equal-buffer
134 '(bullet-list-region nil
)
151 (should (ert-equal-buffer
152 '(bullet-list-region nil
)
173 (should (ert-equal-buffer
174 '(bullet-list-region nil
)
189 (should (ert-equal-buffer
190 '(bullet-list-region t
)
211 (ert-deftest rst-bullet-list-region-error
()
212 "Tests for `rst-bullet-list-region' ending in an error."
213 (let ((rst-preferred-bullets nil
))
214 (should-error (ert-equal-buffer
215 '(bullet-list-region nil
)
222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
224 (defun enumerate-region (all)
225 "Call `rst-enumerate-region' with current region and ALL."
226 (rst-enumerate-region (region-beginning) (region-end) all
))
228 (ert-deftest rst-enumerate-region
()
229 "Tests for `rst-enumerate-region'."
230 (should (ert-equal-buffer
231 '(enumerate-region nil
)
246 (should (ert-equal-buffer
247 '(enumerate-region nil
)
266 (should (ert-equal-buffer
267 '(enumerate-region t
)
282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
284 (defun line-block-region (empty)
285 "Call `rst-line-block-region' with current region and EMPTY."
286 (rst-line-block-region (region-beginning) (region-end) empty
))
288 (ert-deftest rst-line-block-region
()
289 "Tests for `rst-line-block-region'."
290 (should (ert-equal-buffer
291 '(line-block-region nil
)
306 (should (ert-equal-buffer
307 '(line-block-region nil
)
324 (should (ert-equal-buffer
325 '(line-block-region nil
)
342 (should (ert-equal-buffer
343 '(line-block-region t
)
358 (should (ert-equal-buffer
359 '(line-block-region t
)
374 (should (ert-equal-buffer
375 '(line-block-region t
)
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
394 (defun apply-indented-blocks (ind &optional limit
)
395 "Call `rst-apply-indented-blocks' on current region with IND.
396 Stop after LIMIT calls if given. Return a list of all parameter
397 packs to the callback function followed by the return value."
400 (setq r
(rst-apply-indented-blocks
401 (region-beginning) (region-end) ind
402 #'(lambda (count firstp subp supp emptyp relind
)
407 (list (current-column)
408 count firstp subp supp emptyp relind
))))
410 (and limit
(>= called limit
) called
))))
411 (append params
(list r
))))
413 (ert-deftest rst-apply-indented-blocks
()
414 "Tests for `rst-apply-indented-blocks'."
415 (should (ert-equal-buffer-return
416 '(apply-indented-blocks 0)
420 '((0 1 t nil nil nil
0)
422 (should (ert-equal-buffer-return
423 '(apply-indented-blocks 0)
426 '((0 1 t nil nil nil
0)
428 (should (ert-equal-buffer-return
429 '(apply-indented-blocks 2)
434 '((2 0 nil nil nil t nil
)
435 (2 1 t nil nil nil
0)
437 (should (ert-equal-buffer-return
438 '(apply-indented-blocks 2)
445 '((0 0 nil nil nil t nil
)
446 (2 1 t nil nil nil
0)
447 (0 1 nil nil nil t nil
)
448 (4 1 nil t nil nil
2)
450 (should (ert-equal-buffer-return
451 '(apply-indented-blocks 2)
460 '((0 0 nil nil nil t nil
)
461 (2 1 t nil nil nil
0)
462 (0 1 nil nil nil t nil
)
463 (4 1 nil t nil nil
2)
464 (6 1 nil t nil nil
4)
465 (2 1 nil t nil t nil
)
467 (should (ert-equal-buffer-return
468 '(apply-indented-blocks 0)
472 (should (ert-equal-buffer-return
473 '(apply-indented-blocks 2)
481 '((0 0 nil nil nil t nil
)
482 (2 1 t nil nil nil
0)
483 (0 1 nil nil nil t nil
)
484 (2 2 t nil nil nil
0)
485 (4 2 nil t nil nil
2)
487 (should (ert-equal-buffer-return
488 '(apply-indented-blocks 2)
499 '((0 0 nil nil nil t nil
)
500 (2 1 t nil nil nil
0)
501 (0 1 nil nil nil t nil
)
502 (0 1 nil nil t nil -
2)
503 (0 1 nil nil t t nil
)
504 (4 1 nil t nil nil
2)
505 (2 2 t nil nil nil
0)
506 (2 2 nil nil nil nil
0)
508 (should (ert-equal-buffer-return
509 '(apply-indented-blocks 2 2)
516 '((0 0 nil nil nil t nil
)
517 (2 1 t nil nil nil
0)