Add support for `imenu` and `which-func-mode`. Remember setting
[docutils/kirr.git] / docutils / tools / editors / emacs / tests / shift.el
blobea30cf5e0e7d98af8b3aac7345966d58d2228856
1 ;; Tests for various functions around shifting text
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
7 (ert-deftest shift-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
13 (defun string-insert (s col char)
14 "Insert CHAR at position COL in S. Return S."
15 (let ((l (length s))
16 (c (char-to-string char)))
17 (if (<= l col)
18 (concat s (make-string (- col l) ? ) c)
19 (concat (substring s 0 col) c (substring s (1+ col))))))
21 (defun line-tabs ()
22 "Wrapper to call `rst-line-tabs' creating a readable result."
23 (let ((tabs (rst-line-tabs))
24 (s "")
25 (cnt 0)
27 (delete-region (point-min) (point-max))
28 (dolist (tab tabs)
29 (setq c (+ ?A cnt))
30 (if (cdr tab) (setq c (+ c (- ?a ?A))))
31 (setq s (string-insert s (car tab) c))
32 (setq cnt (1+ cnt)))
33 (insert "\n" s)))
35 (ert-deftest rst-line-tabs ()
36 "Tests for `rst-line-tabs'."
37 (let ((rst-indent-width 2)
38 (rst-indent-field 2)
39 (rst-indent-literal-normal 3)
40 (rst-indent-literal-minimized 2)
41 (rst-indent-comment 3))
42 (should (ert-equal-buffer
43 (line-tabs)
44 "\^@"
48 (should (ert-equal-buffer
49 (line-tabs)
51 * a\^@"
53 B a"
55 (should (ert-equal-buffer
56 (line-tabs)
58 * b\^@"
60 B a"
62 (should (ert-equal-buffer
63 (line-tabs)
65 XV. c\^@"
67 B a"
69 (should (ert-equal-buffer
70 (line-tabs)
72 * \^@"
76 (should (ert-equal-buffer
77 (line-tabs)
79 *\tb\^@"
81 B a"
83 (should (ert-equal-buffer
84 (line-tabs)
85 "Some para\^@"
89 (should (ert-equal-buffer
90 (line-tabs)
91 " A quoted block\^@"
95 (should (ert-equal-buffer
96 (line-tabs)
98 :Field: Content on same line\^@"
100 C b a"
102 (should (ert-equal-buffer
103 (line-tabs)
105 :Field: \^@"
107 B a"
109 (let ((rst-indent-field 0))
110 (should (ert-equal-buffer
111 (line-tabs)
113 :Field: Content on same line\^@"
115 B a"
117 (should (ert-equal-buffer
118 (line-tabs)
120 :Field: \^@"
122 B a"
124 (should (ert-equal-buffer
125 (line-tabs)
127 .. dir:: Content on same line\^@"
129 C b a"
131 (should (ert-equal-buffer
132 (line-tabs)
134 .. dir:: \^@"
136 B a"
138 (should (ert-equal-buffer
139 (line-tabs)
141 .. |sub| dir:: Content on same line\^@"
143 D c b a"
145 (should (ert-equal-buffer
146 (line-tabs)
148 .. |sub| dir::\^@"
150 C b a"
152 (should (ert-equal-buffer
153 (line-tabs)
155 .. [CIT] citation\^@"
157 C b a"
159 (should (ert-equal-buffer
160 (line-tabs)
162 .. [#FN] Footnote\^@"
164 C b a"
166 (should (ert-equal-buffer
167 (line-tabs)
169 .. [CIT]\^@"
171 B a"
173 (should (ert-equal-buffer
174 (line-tabs)
176 Some text::\^@"
178 B a"
180 (should (ert-equal-buffer
181 (line-tabs)
183 ::\^@"
185 B a"
187 (should (ert-equal-buffer
188 (line-tabs)
190 ::\^@"
192 B a"
194 (should (ert-equal-buffer
195 (line-tabs)
197 .. First comment\^@"
199 B a"
201 (should (ert-equal-buffer
202 (line-tabs)
204 XV. c::\^@"
206 C b a"
208 (should (ert-equal-buffer
209 (line-tabs)
211 :f: val::\^@"
213 D c b a"
217 (defun compute-tabs ()
218 "Wrapper to call `rst-compute-tabs' creating a readable result."
219 (let ((tabs (rst-compute-tabs (point)))
220 (s "")
221 (cnt 0))
222 (delete-region (point-min) (point-max))
223 (dolist (tab tabs)
224 (setq s (string-insert s tab (+ ?A cnt)))
225 (setq cnt (1+ cnt)))
226 (insert "\n" s)))
228 (ert-deftest rst-compute-tabs ()
229 "Tests for `rst-compute-tabs'."
230 (let ((rst-indent-width 2)
231 (rst-indent-field 2)
232 (rst-indent-literal-normal 3)
233 (rst-indent-literal-minimized 2)
234 (rst-indent-comment 3))
235 (should (ert-equal-buffer
236 (compute-tabs)
237 "\^@"
241 (should (ert-equal-buffer
242 (compute-tabs)
245 \^@"
247 B A"
249 (should (ert-equal-buffer
250 (compute-tabs)
254 \^@"
256 C B A"
258 (should (ert-equal-buffer
259 (compute-tabs)
263 XV. c
264 \^@"
266 D C B A"
268 (should (ert-equal-buffer
269 (compute-tabs)
272 XV. c
273 \^@"
275 D C B A"
277 (should (ert-equal-buffer
278 (compute-tabs)
281 XV. c
282 \^@"
284 C B A"
286 (should (ert-equal-buffer
287 (compute-tabs)
291 XV. c
293 \^@"
295 C B A"
297 (should (ert-equal-buffer
298 (compute-tabs)
302 XV. c
305 \^@"
307 B A"
309 (should (ert-equal-buffer
310 (compute-tabs)
314 XV. c
315 \^@"
317 D C B A"
319 (should (ert-equal-buffer
320 (compute-tabs)
323 *\tb
324 \^@"
326 C B A"
328 (should (ert-equal-buffer
329 (compute-tabs)
330 "* a
331 \^@"
333 B A"
335 (should (ert-equal-buffer
336 (compute-tabs)
337 " * a
339 XV. c
340 \^@"
342 D C B A"
344 (should (ert-equal-buffer
345 (compute-tabs)
346 "Some para
348 A quoted block
350 Quoting again
351 \^@"
353 C B A"
355 (should (ert-equal-buffer
356 (compute-tabs)
358 :Field: Content on same line
359 \^@"
361 C B A"
363 (should (ert-equal-buffer
364 (compute-tabs)
366 :Field: Content on same line
367 but continued differently
368 \^@"
370 D CA B"
372 (should (ert-equal-buffer
373 (compute-tabs)
375 :Field: Content on same line
376 but continued differently
377 \^@"
379 D C B A"
381 (should (ert-equal-buffer
382 (compute-tabs)
384 :Field:
386 Content on next line
387 \^@"
389 C BA"
391 (should (ert-equal-buffer
392 (compute-tabs)
394 :Field: Starts on same line
396 Content on next line
397 \^@"
399 C A B"
401 (should (ert-equal-buffer
402 (compute-tabs)
404 .. dir:: Content on same line
405 \^@"
407 C B A"
409 (should (ert-equal-buffer
410 (compute-tabs)
412 .. dir::
414 Content on next line
415 \^@"
417 B A"
419 (should (ert-equal-buffer
420 (compute-tabs)
422 .. dir::
424 Content on next line
425 \^@"
427 C B A"
429 (should (ert-equal-buffer
430 (compute-tabs)
432 .. dir:: Same
434 Content on next line
435 \^@"
437 D C A B"
439 (should (ert-equal-buffer
440 (compute-tabs)
442 .. |sub| dir:: Content on same line
443 \^@"
445 D C B A"
447 (should (ert-equal-buffer
448 (compute-tabs)
450 .. |sub| dir::
452 Content on next line
453 \^@"
455 C A B"
457 (should (ert-equal-buffer
458 (compute-tabs)
460 .. |sub| dir::
462 Content on next line
463 \^@"
465 D C A B"
467 (should (ert-equal-buffer
468 (compute-tabs)
470 .. |sub| dir:: Same
472 Content on next line
473 \^@"
475 E D A C B"
477 (should (ert-equal-buffer
478 (compute-tabs)
480 .. |sub| dir:: Same
482 :par: val
484 Content on next line
485 \^@"
487 E DC A B"
489 (should (ert-equal-buffer
490 (compute-tabs)
492 .. |sub| dir::
494 :par: val
496 Content on next line
497 \^@"
499 C A B"
501 (should (ert-equal-buffer
502 (compute-tabs)
504 .. |sub| dir:: Same
506 :f: val
508 Content on next line
509 \^@"
511 E DAC B"
513 (should (ert-equal-buffer
514 (compute-tabs)
516 .. |sub| dir:: Same
518 :f: val
520 Content on next line
521 \^@"
523 D A C B"
525 (should (ert-equal-buffer
526 (compute-tabs)
528 .. |sub| dir:: Same
530 :f: val
532 * Item
533 \^@"
535 C B A"
537 (should (ert-equal-buffer
538 (compute-tabs)
540 .. |sub| dir:: Same
542 :f: val
544 * Item
546 1. Enumerated
547 \^@"
549 D C B A"
551 (should (ert-equal-buffer
552 (compute-tabs)
554 .. [CIT] citation
555 \^@"
557 C B A"
559 (should (ert-equal-buffer
560 (compute-tabs)
562 .. [#FN] Footnote
563 \^@"
565 C B A"
567 (should (ert-equal-buffer
568 (compute-tabs)
570 .. [CIT]
572 citation
573 \^@"
575 B A"
577 (should (ert-equal-buffer
578 (compute-tabs)
580 .. [CIT]
582 citation
583 \^@"
585 C B A"
587 (should (ert-equal-buffer
588 (compute-tabs)
590 .. [CIT]
592 citation
594 .. |sub| dir:: Same
596 :f: val
598 * Item
600 1. Enumerated
601 \^@"
603 E D C B A"
605 (should (ert-equal-buffer
606 (compute-tabs)
608 Some text::
609 \^@"
611 B A"
613 (should (ert-equal-buffer
614 (compute-tabs)
616 No text
619 \^@"
621 B A"
623 (should (ert-equal-buffer
624 (compute-tabs)
626 No text
629 \^@"
631 C B A"
633 (should (ert-equal-buffer
634 (compute-tabs)
636 .. [CIT]
638 citation
640 .. |sub| dir:: Same
642 :f: val
644 No text
647 \^@"
649 E D C B A"
651 (should (ert-equal-buffer
652 (compute-tabs)
654 .. First comment
655 \^@"
657 B A"
659 (should (ert-equal-buffer
660 (compute-tabs)
663 XV. c::
664 \^@"
666 E D C B A"
668 (should (ert-equal-buffer
669 (compute-tabs)
671 .. [CIT]
673 citation
675 .. |sub| dir:: Same
677 :f: val::
678 \^@"
680 F E D C B A"
684 (ert-deftest rst-shift-region-right ()
685 "Tests for `rst-shift-region' to the right."
686 (let ((rst-indent-width 2)) ; Set relevant variables
687 (should (ert-equal-buffer
688 (rst-shift-region 1)
690 \^@a
691 \^?"
693 \^@ a
694 \^?"
696 (should (ert-equal-buffer
697 (rst-shift-region 1)
699 \^@ a
700 \^?"
702 \^@ a
703 \^?"
705 (should (ert-equal-buffer
706 (rst-shift-region 1)
707 "\^@
710 \^?"
711 "\^@
714 \^?"
716 (should (ert-equal-buffer
717 (rst-shift-region 1)
718 "* x
722 \^?"
723 "* x
727 \^?"
729 (should (ert-equal-buffer
730 (rst-shift-region 1)
731 "* x
735 \^?"
736 "* x
740 \^?"
742 (should (ert-equal-buffer
743 (rst-shift-region 1)
744 "* x
749 \^?"
750 "* x
755 \^?"
757 (should (ert-equal-buffer
758 (rst-shift-region 1)
759 "* x
763 \^@"
764 "* x
768 \^@"
770 (should (ert-equal-buffer
771 (rst-shift-region 2)
772 "* x
776 \^@"
777 "* x
781 \^@"
785 (ert-deftest rst-shift-region-left ()
786 "Tests for `rst-shift-region' to the left."
787 (let ((rst-indent-width 2)) ; Set relevant variables
788 (should (ert-equal-buffer
789 (rst-shift-region -1)
790 "* x
794 \^?"
795 "* x
799 \^?"
801 (should (ert-equal-buffer
802 (rst-shift-region -1)
804 \^@ a
805 \^?"
807 \^@a
808 \^?"
810 (should (ert-equal-buffer
811 (rst-shift-region -1)
813 \^@ a
814 \^?"
816 \^@ a
817 \^?"
819 (should (ert-equal-buffer
820 (rst-shift-region -1)
821 "\^@
824 \^?"
825 "\^@
828 \^?"
830 (should (ert-equal-buffer
831 (rst-shift-region -1)
832 "* x
836 \^?"
837 "* x
841 \^?"
843 (should (ert-equal-buffer
844 (rst-shift-region -1)
845 "* x
850 \^?"
851 "* x
856 \^?"
858 (should (ert-equal-buffer
859 (rst-shift-region -1)
860 "* x
864 \^@"
865 "* x
869 \^@"
871 (should (ert-equal-buffer
872 (rst-shift-region 0)
873 "* x
878 \^?"
879 "* x
884 \^?"
886 (should (ert-equal-buffer
887 (rst-shift-region -1)
888 "\^@* x
893 \^?"
894 "\^@* x
899 \^?"
901 (should (ert-equal-buffer
902 (rst-shift-region -2)
903 "* x
908 \^?"
909 "* x
914 \^?"