Lots of refactorings and a few minor improvements.
[docutils.git] / docutils / tools / editors / emacs / tests / adornment.el
blob489d05e48665b507833a8b4de12b32d852e1876a
1 ;; Tests for various functions handling adornments -*- lexical-binding: t -*-
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
7 (ert-deftest adornment-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
13 (defun ttl-at-point ()
14 "Wrapper for calling `rst-ttl-at-point'."
15 (apply-ttl-match (rst-ttl-at-point)))
17 (ert-deftest rst-ttl-at-point ()
18 "Tests for `rst-ttl-at-point'."
19 (should (ert-equal-buffer-return
20 '(ttl-at-point)
23 Du bon vin tous les jours.
24 \^@
28 \^@Du bon vin tous les jours.
31 '(nil 0 nil "Du bon vin tous les jours." nil)
33 (should (ert-equal-buffer-return
34 '(ttl-at-point)
36 \^@
37 Du bon vin tous les jours.
42 \^@Du bon vin tous les jours.
45 '(nil 0 nil "Du bon vin tous les jours." nil)
47 (should (ert-equal-buffer-return
48 '(ttl-at-point)
51 Du bon vin tous les jours.
52 ------\^@-----
56 \^@Du bon vin tous les jours.
57 -----------
59 (list
60 (rst-Ado-new-simple ?-) 0
61 nil "Du bon vin tous les jours." "-----------")
63 (should (ert-equal-buffer-return
64 '(ttl-at-point)
66 ------\^@-----
67 Du bon vin tous les jours.
71 -----------
72 \^@Du bon vin tous les jours.
75 (list
76 (rst-Ado-new-over-and-under ?-) 0
77 "-----------" "Du bon vin tous les jours." nil)
79 (should (ert-equal-buffer-return
80 '(ttl-at-point)
82 \^@-----------
83 Du bon vin tous les jours.
84 -----------
88 -----------
89 \^@Du bon vin tous les jours.
90 -----------
93 (list
94 (rst-Ado-new-over-and-under ?-) 0
95 "-----------" "Du bon vin tous les jours." "-----------")
97 (should (ert-equal-buffer-return
98 '(ttl-at-point)
100 \^@===========
101 Du bon vin tous les jours.
102 -----------
105 \^@===========
106 Du bon vin tous les jours.
107 -----------
111 (should (ert-equal-buffer-return
112 '(ttl-at-point)
114 Du bon vin tous les jours.
115 \^@-----------
116 Du bon vin tous les jours.
117 -----------
121 Du bon vin tous les jours.
122 -----------
123 \^@Du bon vin tous les jours.
124 -----------
126 " ; This is not how the parser works but looks more logical
127 (list
128 (rst-Ado-new-over-and-under ?-) 0
129 "-----------" "Du bon vin tous les jours." "-----------")
131 (should (ert-equal-buffer-return
132 '(ttl-at-point)
135 \^@===========
140 \^@===========
145 (should (ert-equal-buffer-return
146 '(ttl-at-point)
147 "\^@"
148 "\^@"
151 (should (ert-equal-buffer-return
152 '(ttl-at-point)
153 "\^@
155 "\^@
159 (should (ert-equal-buffer-return
160 '(ttl-at-point)
162 Line 1
164 Line 2
168 \^@Line 1
170 Line 2
173 '(nil 0 nil "Line 1" nil)
175 (should (ert-equal-buffer-return
176 '(ttl-at-point)
178 =====================================
179 Project Idea: Panorama Stitcher
180 ====================================
182 :Author: Martin Blais <blais@furius.ca>
184 Another Title
185 =============
188 =====================================
189 Project Idea: Panorama Stitcher
190 ====================================
192 \^@:Author: Martin Blais <blais@furius.ca>
194 Another Title
195 =============
197 '(nil 0 nil ":Author: Martin Blais <blais@furius.ca>" nil)
201 (setq text-1
202 "===============================
203 Project Idea: My Document
204 ===============================
206 :Author: Martin Blais
208 Introduction
209 ============
211 This is the introduction.
213 Notes
214 -----
216 Some notes.
218 Main Points
219 ===========
221 Yep.
223 Super Point
224 -----------
226 ~~~~~~~~~~~
227 \^@ Sub Point
228 ~~~~~~~~~~~
230 Isn't this fabulous?
232 Conclusion
233 ==========
235 That's it, really.
239 (setq text-2
242 Previous
243 --------
245 Current\^@
246 ~~~~~~~
248 Next
249 ++++
253 (setq text-3
256 Previous
257 --------
259 Current\^@
260 ~~~~~~~
262 Next
263 ++++
267 (setq text-4
270 Previous
271 --------
273 Current\^@
274 ~~~~~~~
276 Next
277 ++++
279 Same
280 ~~~~
284 (defun find-all-adornments ()
285 "Call `rst-all-ttls' and return conses of line and `rst-Ado'."
286 (mapcar (lambda (ttl)
287 (cons (line-number-at-pos (rst-Ttl-get-title-beginning ttl))
288 (rst-Ttl-ado ttl)))
289 (rst-all-ttls-compute)))
291 (ert-deftest rst-all-ttls ()
292 "Tests for `rst-all-ttls'."
293 (should (ert-equal-buffer-return
294 (find-all-adornments)
299 (should (ert-equal-buffer-return
300 '(find-all-adornments)
302 Not a valid section header because of indentation
303 ===================================================
308 (should (ert-equal-buffer-return
309 '(find-all-adornments)
311 Only a...
313 ===================================================
315 ...transition
320 (should (ert-equal-buffer-return
321 '(find-all-adornments)
323 =======================================================
324 Not a valid section header because of missing underline
330 (should (ert-equal-buffer-return
331 '(find-all-adornments)
333 =====================================================
334 Not a valid section header because of wrong underline
335 -----------------------------------------------------
340 (should (ert-equal-buffer-return
341 '(find-all-adornments)
343 Valid simple section header
344 ===========================
347 (list
348 (cons 2 (rst-Ado-new-simple ?=)))
350 (should (ert-equal-buffer-return
351 '(find-all-adornments)
353 =======================================
354 Valid over and under section header
355 =======================================
358 (list
359 (cons 3 (rst-Ado-new-over-and-under ?=)))
361 (should (ert-equal-buffer-return
362 '(find-all-adornments)
363 text-1
365 (list
366 (cons 2 (rst-Ado-new-over-and-under ?=))
367 (cons 7 (rst-Ado-new-simple ?=))
368 (cons 12 (rst-Ado-new-simple ?-))
369 (cons 17 (rst-Ado-new-simple ?=))
370 (cons 22 (rst-Ado-new-simple ?-))
371 (cons 26 (rst-Ado-new-over-and-under ?~))
372 (cons 31 (rst-Ado-new-simple ?=)))
374 (should (ert-equal-buffer-return
375 '(find-all-adornments)
376 text-2
378 (list
379 (cons 3 (rst-Ado-new-simple ?-))
380 (cons 6 (rst-Ado-new-simple ?~))
381 (cons 9 (rst-Ado-new-simple ?+)))
383 (should (ert-equal-buffer-return
384 '(find-all-adornments)
385 text-3
387 (list
388 (cons 3 (rst-Ado-new-simple ?-))
389 (cons 6 (rst-Ado-new-simple ?~)))
391 (should (ert-equal-buffer-return
392 '(find-all-adornments)
393 "=====
394 Title
395 =====
397 Header A
398 ========
400 Header B
401 ========
403 Subheader B.a
404 -------------
406 SubSubheader B.a.1
407 ~~~~~~~~~~~~~~~~~~
409 Header C
410 ========
412 Missing node C.a.1
413 ~~~~~~~~~~~~~~~~~~
416 (list
417 (cons 2 (rst-Ado-new-over-and-under ?=))
418 (cons 5 (rst-Ado-new-simple ?=))
419 (cons 8 (rst-Ado-new-simple ?=))
420 (cons 11 (rst-Ado-new-simple ?-))
421 (cons 14 (rst-Ado-new-simple ?~))
422 (cons 17 (rst-Ado-new-simple ?=))
423 (cons 20 (rst-Ado-new-simple ?~)))
427 (ert-deftest rst-hdr-hierarchy ()
428 "Tests for `rst-hdr-hierarchy'."
429 (let ( ;; Set customizable variables to defined values
430 (rst-default-indent 5))
431 (should (ert-equal-buffer-return
432 '(rst-hdr-hierarchy)
433 text-1
435 (list
436 (rst-Hdr-new (rst-Ado-new-over-and-under ?=) 3)
437 (rst-Hdr-new (rst-Ado-new-simple ?=) 0)
438 (rst-Hdr-new (rst-Ado-new-simple ?-) 0)
439 (rst-Hdr-new (rst-Ado-new-over-and-under ?~) 1))
441 (should (ert-equal-buffer-return
442 '(rst-hdr-hierarchy)
443 (concat text-1
445 =========
446 No indent
447 =========
450 (list
451 (rst-Hdr-new (rst-Ado-new-over-and-under ?=) 5)
452 (rst-Hdr-new (rst-Ado-new-simple ?=) 0)
453 (rst-Hdr-new (rst-Ado-new-simple ?-) 0)
454 (rst-Hdr-new (rst-Ado-new-over-and-under ?~) 1))
458 (ert-deftest rst-get-hierarchy-ignore ()
459 "Tests for `rst-hdr-hierarchy' with ignoring a line."
460 (should (ert-equal-buffer-return
461 '(rst-hdr-hierarchy (point))
462 text-1
464 (list
465 (rst-Hdr-new (rst-Ado-new-over-and-under ?=) 3)
466 (rst-Hdr-new (rst-Ado-new-simple ?=) 0)
467 (rst-Hdr-new (rst-Ado-new-simple ?-) 0))
469 (should (ert-equal-buffer-return
470 '(rst-hdr-hierarchy (point))
471 text-4
473 (list
474 (rst-Hdr-new (rst-Ado-new-simple ?-) 0)
475 (rst-Hdr-new (rst-Ado-new-simple ?~) 0)
476 (rst-Hdr-new (rst-Ado-new-simple ?+) 0))
480 (ert-deftest rst-adornment-level ()
481 "Tests for `rst-adornment-level'."
482 (should (ert-equal-buffer-return
483 '(rst-adornment-level (rst-Ado-new-transition))
484 text-1
488 (should (ert-equal-buffer-return
489 '(rst-adornment-level (rst-Ado-new-over-and-under ?=))
490 text-1
494 (should (ert-equal-buffer-return
495 '(rst-adornment-level (rst-Ado-new-simple ?=))
496 text-1
500 (should (ert-equal-buffer-return
501 '(rst-adornment-level (rst-Ado-new-simple ?-))
502 text-1
506 (should (ert-equal-buffer-return
507 '(rst-adornment-level (rst-Ado-new-over-and-under ?~))
508 text-1
512 (should (ert-equal-buffer-return
513 '(rst-adornment-level (rst-Ado-new-simple ?#))
514 text-1
520 (ert-deftest rst-adornment-complete-p ()
521 "Tests for `rst-adornment-complete-p'."
522 (should (ert-equal-buffer-return
523 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
524 "Vaudou\^@"
526 nil))
527 (should (ert-equal-buffer-return
528 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
529 "Vaudou\^@
530 ======"
532 nil))
533 (should (ert-equal-buffer-return
534 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
537 \^@Vaudou
541 nil))
542 (should (ert-equal-buffer-return
543 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
545 \^@Vaudou
546 ======
550 (should (ert-equal-buffer-return
551 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
553 ======
554 \^@Vaudou
555 ======
559 (should (ert-equal-buffer-return
560 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 2)
562 ==========
563 \^@ Vaudou
564 ==========
568 (should (ert-equal-buffer-return
569 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
571 \^@Vaudou
572 =====
575 nil))
576 (should (ert-equal-buffer-return
577 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
579 \^@Vaudou
580 =======
583 nil))
584 (should (ert-equal-buffer-return
585 '(rst-adornment-complete-p (rst-Ado-new-simple ?=) 0)
587 \^@Vaudou
588 ===-==
591 nil))
592 (should (ert-equal-buffer-return
593 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
595 ======
596 \^@Vaudou
597 =====
600 nil))
601 (should (ert-equal-buffer-return
602 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
604 =====
605 \^@Vaudou
606 ======
609 nil))
610 (should (ert-equal-buffer-return
611 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
613 ======
614 \^@Vaudou
615 ===-==
618 nil))
619 (should (ert-equal-buffer-return
620 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
622 ===-==
623 \^@Vaudou
624 ======
627 nil))
628 (should (ert-equal-buffer-return
629 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
631 ======
632 \^@Vaudou
636 nil))
637 (should (ert-equal-buffer-return
638 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
640 ======
641 \^@Vaudou
642 ------
645 nil))
646 (should (ert-equal-buffer-return
647 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
649 ==========
650 \^@Vaudou
651 =========
654 nil))
655 (should (ert-equal-buffer-return
656 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
658 =========
659 \^@Vaudou
660 ==========
663 nil))
664 (should (ert-equal-buffer-return
665 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
667 ==========
668 \^@Vaudou
669 ===-======
672 nil))
673 (should (ert-equal-buffer-return
674 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
676 ===-======
677 \^@Vaudou
678 ==========
681 nil))
682 (should (ert-equal-buffer-return
683 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
685 ==========
686 \^@Vaudou
690 nil))
691 (should (ert-equal-buffer-return
692 '(rst-adornment-complete-p (rst-Ado-new-over-and-under ?=) 0)
694 ==========
695 \^@Vaudou
696 ----------
699 nil))
702 (ert-deftest rst-get-previous-hdr ()
703 "Tests for `rst-get-previous-hdr'."
704 (should (ert-equal-buffer-return
705 '(rst-get-previous-hdr)
708 Previous
709 --------
711 \^@Current
713 Next
714 ++++
718 (rst-Hdr-new (rst-Ado-new-simple ?-) 0)))
719 (should (ert-equal-buffer-return
720 '(rst-get-previous-hdr)
723 Previous
724 --------
726 Current\^@
727 ~~~~~~~
729 Next
730 ++++
734 (rst-Hdr-new (rst-Ado-new-simple ?-) 0)))
737 (defun apply-ttl-match (ttl)
738 "Apply the match in TTL to the buffer and return important data.
739 Puts point at the beginning of the title line. Return a list
740 consisting of the `rst-Ado', the indent and the three matched
741 texts. Return nil if TTL is nil. Checks whether embedded match
742 groups match match group 0."
743 (when ttl
744 (let ((match (rst-Ttl-match ttl)))
745 (set-match-data match)
746 (let ((whole (match-string-no-properties 0))
747 (over (match-string-no-properties 1))
748 (text (match-string-no-properties 2))
749 (under (match-string-no-properties 3))
750 (gather ""))
751 (if over
752 (setq gather (concat gather over "\n")))
753 (if text
754 (setq gather (concat gather text "\n")))
755 (if under
756 (setq gather (concat gather under "\n")))
757 (if (not (string= (substring gather 0 -1) whole))
758 (error "Match 0 '%s' doesn't match concatenated parts '%s'"
759 whole gather))
760 (goto-char (match-beginning 2))
761 (list (rst-Ttl-ado ttl) (rst-Ttl-indent ttl) over text under)))))
763 (defun classify-adornment (beg end)
764 "Wrapper for calling `rst-classify-adornment'."
765 (interactive "r")
766 (apply-ttl-match (rst-classify-adornment
767 (buffer-substring-no-properties beg end) end)))
769 (defun classify-adornment-accept (beg end)
770 "Wrapper for calling `rst-classify-adornment'."
771 (interactive "r")
772 (apply-ttl-match (rst-classify-adornment
773 (buffer-substring-no-properties beg end) end t)))
775 (ert-deftest rst-classify-adornment ()
776 "Tests for `rst-classify-adornment'."
777 (should (ert-equal-buffer-return
778 '(classify-adornment)
781 Du bon vin tous les jours
782 \^@=========================\^?
786 (list
787 (rst-Ado-new-simple ?=) 0
788 nil "Du bon vin tous les jours" "=========================")
790 (should (ert-equal-buffer-return
791 '(classify-adornment)
794 Du bon vin tous les jours
795 \^@====================\^?
799 (list
800 (rst-Ado-new-simple ?=) 0
801 nil "Du bon vin tous les jours" "====================")
803 (should (ert-equal-buffer-return
804 '(classify-adornment)
805 "\^@====================\^?
806 Du bon vin tous les jours"
810 (should (ert-equal-buffer-return
811 '(classify-adornment-accept)
812 "\^@====================\^?
813 Du bon vin tous les jours"
815 (list
816 (rst-Ado-new-over-and-under ?=) 0
817 "====================" "Du bon vin tous les jours" nil)
819 (should (ert-equal-buffer-return
820 '(classify-adornment)
823 Du bon vin tous les jours
824 \^@====================\^?
828 (list
829 (rst-Ado-new-simple ?=) 5
830 nil " Du bon vin tous les jours" "====================")
832 (should (ert-equal-buffer-return
833 '(classify-adornment)
834 " Du bon vin tous les jours
835 \^@====================\^?
838 (list
839 (rst-Ado-new-simple ?=) 5
840 nil " Du bon vin tous les jours" "====================")
842 (should (ert-equal-buffer-return
843 '(classify-adornment)
846 Du bon vin tous les jours
847 \^@-\^?
852 (should (ert-equal-buffer-return
853 '(classify-adornment)
856 Du bon vin tous les jours
857 \^@--\^?
862 (should (ert-equal-buffer-return
863 '(classify-adornment)
866 Du bon vin tous les jours
867 \^@---\^?
870 (list
871 (rst-Ado-new-simple ?-) 0
872 nil "Du bon vin tous les jours" "---")
874 (should (ert-equal-buffer-return
875 '(classify-adornment)
877 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
878 Du bon vin tous les jours
879 ~~~~~~~~~~~~~~~~~~~~~~~~~
883 (list
884 (rst-Ado-new-over-and-under ?~) 0
885 "~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
887 (should (ert-equal-buffer-return
888 '(classify-adornment)
889 "~~~~~~~~~~~~~~~~~~~~~~~~~
890 Du bon vin tous les jours
891 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
895 (list
896 (rst-Ado-new-over-and-under ?~) 0
897 "~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
899 (should (ert-equal-buffer-return
900 '(classify-adornment)
902 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
903 Du bon vin tous les jours
904 ~~~~~~~~~~~~~~~~~~~~~~~~~
908 (list
909 (rst-Ado-new-over-and-under ?~) 3
910 "~~~~~~~~~~~~~~~~~~~~~~~~~" " Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
912 (should (ert-equal-buffer-return
913 '(classify-adornment)
915 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
916 Du bon vin tous les jours
917 ~~~~~~~~~~~~~~~~~~~
921 (list
922 (rst-Ado-new-over-and-under ?~) 0
923 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~")
925 (should (ert-equal-buffer-return
926 '(classify-adornment)
928 ---------------------------
929 Du bon vin tous les jours
930 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
936 (should (ert-equal-buffer-return
937 '(classify-adornment)
938 "\^@---------------------------\^?"
940 (list
941 (rst-Ado-new-transition) nil
942 nil "---------------------------" nil)
944 (should (ert-equal-buffer-return
945 '(classify-adornment)
947 \^@===\^?
950 (list
951 (rst-Ado-new-transition) nil
952 nil "===" nil)
954 (should (ert-equal-buffer-return
955 '(classify-adornment)
957 \^@---------------------------\^?
958 Du bon vin tous les jours
959 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
965 (should (ert-equal-buffer-return
966 '(classify-adornment)
968 =========================
969 Du bon vin tous les jours
970 \^@=========================\^?
971 Du bon vin
975 (list
976 (rst-Ado-new-over-and-under ?=) 0
977 "=========================" "Du bon vin tous les jours" "=========================")
979 (should (ert-equal-buffer-return
980 '(classify-adornment)
982 =========================
983 Du bon vin tous les jours
984 =========================
985 Du bon vin
986 \^@----------\^?
990 (list
991 (rst-Ado-new-simple ?-) 0
992 nil "Du bon vin" "----------")
994 (should (ert-equal-buffer-return
995 '(classify-adornment)
997 =========================
998 Du bon vin tous les jours
999 =========================
1000 \^@----------\^?
1001 Du bon vin
1002 ----------
1006 (list
1007 (rst-Ado-new-over-and-under ?-) 0
1008 "----------" "Du bon vin" "----------")
1010 (should (ert-equal-buffer-return
1011 '(classify-adornment)
1013 =========================
1014 Du bon vin tous les jours
1015 =========================
1016 --------------
1017 Du bon vin
1018 \^@--------------\^?
1022 (list
1023 (rst-Ado-new-over-and-under ?-) 2
1024 "--------------" " Du bon vin" "--------------")
1028 (defun display-adornments-hierarchy ()
1029 "Wrapper for calling `rst-display-hdr-hierarchy'."
1030 (rst-display-hdr-hierarchy)
1031 (let ((source (get-buffer "*rest section hierarchy*")))
1032 (delete-region (point-min) (point-max))
1033 (insert (with-current-buffer source
1034 (buffer-substring (point-min) (point-max))))
1035 (kill-buffer source)))
1037 (ert-deftest rst-display-hdr-hierarchy ()
1038 "Tests for `rst-display-hdr-hierarchy'."
1039 (should (ert-equal-buffer
1040 '(display-adornments-hierarchy)
1045 (should (ert-equal-buffer
1046 '(display-adornments-hierarchy)
1048 First
1049 -----
1051 Second
1052 ======
1054 First again
1055 -----------
1057 Second again
1058 ============
1060 +++++
1061 Third
1062 +++++
1066 Section Level 1
1067 ---------------
1070 Section Level 2
1071 ===============
1074 +++++++++++++++
1075 Section Level 3
1076 +++++++++++++++
1081 (ert-deftest rst-adjust-region ()
1082 "Tests for `rst-adjust-region'."
1083 (let ((rst-preferred-adornments '((?= over-and-under 1)
1084 (?= simple 0)
1085 (?- simple 0)
1086 (?~ simple 0)
1087 (?+ simple 0)
1088 (?` simple 0)
1089 (?# simple 0)
1090 (?@ simple 0))))
1091 (should (ert-equal-buffer
1092 '(rst-adjust-region nil)
1093 "\^@\^?"
1096 (should (ert-equal-buffer
1097 '(rst-adjust-region nil)
1099 First
1100 -----
1102 Second
1103 ======
1105 First again
1106 -----------
1108 Second again
1109 ============
1111 +++++
1112 Third
1113 +++++
1117 First
1118 -----
1120 Second
1121 ------
1123 First again
1124 -----------
1126 Second again
1127 ============
1129 +++++
1130 Third
1131 +++++
1135 (should (ert-equal-buffer
1136 '(rst-adjust-region nil)
1138 First
1139 -----
1141 Second
1142 ======
1144 First again
1145 -----------
1147 Second again
1148 ============
1150 +++++
1151 Third
1152 +++++
1156 First
1157 -----
1159 Second
1160 ======
1162 First again
1163 -----------
1165 Second again
1166 ------------
1168 Third
1169 =====
1173 (should (ert-equal-buffer
1174 '(rst-adjust-region nil)
1176 First
1177 -----
1179 Second
1180 ======
1182 First again
1183 -----------
1185 Second again
1186 ============
1188 +++++
1189 Third
1190 +++++
1194 First
1195 -----
1197 Second
1198 ======
1200 =============
1201 First again
1202 =============
1204 Second again
1205 ============
1207 +++++
1208 Third
1209 +++++
1213 (should (ert-equal-buffer
1214 '(rst-adjust-region t)
1216 First
1217 -----
1219 Second
1220 ======
1222 First again
1223 -----------
1225 Second again
1226 ============
1228 +++++
1229 Third
1230 +++++
1234 First
1235 -----
1237 Second
1238 ======
1240 First again
1241 ===========
1243 Second again
1244 ============
1246 +++++
1247 Third
1248 +++++
1252 (should (ert-equal-buffer
1253 '(rst-adjust-region t)
1255 First
1256 -----
1258 Second
1259 ======
1261 First again
1262 -----------
1264 Second again
1265 ============
1267 +++++
1268 Third
1269 +++++
1273 First
1274 -----
1276 Second
1277 ======
1279 First again
1280 -----------
1282 Second again
1283 ============
1285 =======
1286 Third
1287 =======
1293 (ert-deftest rst-straighten-sections ()
1294 "Tests for `rst-straighten-sections'."
1295 (let ((rst-preferred-adornments '((?= over-and-under 1)
1296 (?= simple 0)
1297 (?- simple 0)
1298 (?~ simple 0)
1299 (?+ simple 0)
1300 (?` simple 0)
1301 (?# simple 0)
1302 (?@ simple 0))))
1303 (should (ert-equal-buffer
1304 '(rst-straighten-sections)
1308 (should (ert-equal-buffer
1309 '(rst-straighten-sections)
1311 First
1312 -----
1314 Second
1315 ======
1317 First again
1318 -----------
1320 Second again
1321 ============
1323 +++++
1324 Third
1325 +++++
1329 =======
1330 First
1331 =======
1333 Second
1334 ======
1336 =============
1337 First again
1338 =============
1340 Second again
1341 ============
1343 Third
1344 -----
1350 (defun find-all-levels ()
1351 "Call `rst-all-ttls-with-level' and return conses of line and level."
1352 (mapcar (cl-function
1353 (lambda ((ttl . level))
1354 (cons (line-number-at-pos (rst-Ttl-get-title-beginning ttl))
1355 level)))
1356 (rst-all-ttls-with-level)))
1358 (ert-deftest rst-all-ttls-with-level ()
1359 "Tests for `rst-all-ttls-with-level'."
1360 (should (ert-equal-buffer-return
1361 '(find-all-levels)
1366 (should (ert-equal-buffer-return
1367 '(find-all-levels)
1369 Not a valid section header because of indentation
1370 ===================================================
1375 (should (ert-equal-buffer-return
1376 '(find-all-levels)
1378 Valid simple section header
1379 ===========================
1382 (list
1383 '(2 . 0))
1385 (should (ert-equal-buffer-return
1386 '(find-all-levels)
1388 =======================================
1389 Valid over and under section header
1390 =======================================
1393 (list
1394 '(3 . 0))
1396 (should (ert-equal-buffer-return
1397 '(find-all-levels)
1398 text-1
1401 (2 . 0)
1402 (7 . 1)
1403 (12 . 2)
1404 (17 . 1)
1405 (22 . 2)
1406 (26 . 3)
1407 (31 . 1))
1409 (should (ert-equal-buffer-return
1410 '(find-all-levels)
1411 text-2
1414 (3 . 0)
1415 (6 . 1)
1416 (9 . 2))
1418 (should (ert-equal-buffer-return
1419 '(find-all-levels)
1420 text-3
1423 (3 . 0)
1424 (6 . 1))
1428 (defun update-section (char simplep indent)
1429 "Call `rst-update-section' with proper header."
1430 (rst-update-section
1431 (rst-Hdr-new (if simplep
1432 (rst-Ado-new-simple char)
1433 (rst-Ado-new-over-and-under char)) indent)))
1435 (ert-deftest rst-update-section ()
1436 "Tests for `rst-update-section'."
1437 (should (ert-equal-buffer
1438 '(update-section ?= t 0)
1441 \^@abc
1446 abc\^@
1452 (should (ert-equal-buffer
1453 '(update-section ?= nil 2)
1456 \^@abc
1461 =======
1462 abc\^@
1463 =======
1468 (should (ert-equal-buffer
1469 '(update-section ?= nil 2)
1474 \^@abc
1481 =======
1482 abc\^@
1483 =======
1488 (should (ert-equal-buffer
1489 '(update-section ?= nil 2)
1493 \^@abc
1498 =======
1499 abc\^@
1500 =======
1505 (should (ert-equal-buffer
1506 '(update-section ?= t 0)
1507 "\^@abc
1510 "abc\^@
1516 (should (ert-equal-buffer
1517 '(update-section ?= nil 0)
1518 "\^@abc
1521 "===
1522 abc\^@
1528 (should (ert-equal-buffer
1529 '(update-section ?= t 0)
1530 "\^@abc"
1531 "abc\^@
1536 (should (ert-equal-buffer
1537 '(update-section ?= t 0)
1538 "\^@abc
1540 "abc\^@
1545 (should (ert-equal-buffer
1546 '(update-section ?= t 0)
1547 "\^@abc
1549 "abc\^@
1554 (should (ert-equal-buffer
1555 '(update-section ?= t 0)
1556 "===
1557 \^@abc
1560 "abc\^@