1 ;; Tests for various functions handling adornments
3 (add-to-list 'load-path
".")
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 find-title-line ()
14 "Wrapper for calling `rst-find-title-line'."
15 (apply-adornment-match (rst-find-title-line)))
17 (ert-deftest rst-find-title-line
()
18 "Tests for `rst-find-title-line'."
19 (should (ert-equal-buffer-return
23 Du bon vin tous les jours.
28 \^@Du bon vin tous les jours.
31 '((nil . nil
) nil
"Du bon vin tous les jours." nil
)
33 (should (ert-equal-buffer-return
37 Du bon vin tous les jours.
42 \^@Du bon vin tous les jours.
45 '((nil . nil
) nil
"Du bon vin tous les jours." nil
)
47 (should (ert-equal-buffer-return
51 Du bon vin tous les jours.
56 \^@Du bon vin tous les jours.
59 '((?- . simple
) nil
"Du bon vin tous les jours." "-----------")
61 (should (ert-equal-buffer-return
65 Du bon vin tous les jours.
70 \^@Du bon vin tous les jours.
73 '((?- . nil
) "-----------" "Du bon vin tous les jours." nil
)
75 (should (ert-equal-buffer-return
79 Du bon vin tous les jours.
85 \^@Du bon vin tous les jours.
89 '((?- . over-and-under
) "-----------" "Du bon vin tous les jours."
92 (should (ert-equal-buffer-return
95 Du bon vin tous les jours.
97 Du bon vin tous les jours.
102 Du bon vin tous les jours.
104 \^@Du bon vin tous les jours.
107 " ; This is not how the parser works but looks more logical
108 '((?- . over-and-under
) "-----------" "Du bon vin tous les jours."
111 (should (ert-equal-buffer-return
125 (should (ert-equal-buffer-return
139 '((nil . nil
) nil
"Line 1" nil
)
141 (should (ert-equal-buffer-return
144 =====================================
145 Project Idea: Panorama Stitcher
146 ====================================
148 :Author: Martin Blais <blais@furius.ca>
154 =====================================
155 Project Idea: Panorama Stitcher
156 ====================================
158 \^@:Author: Martin Blais <blais@furius.ca>
163 '((nil . nil
) nil
":Author: Martin Blais <blais@furius.ca>" nil
)
168 "===============================
169 Project Idea: My Document
170 ===============================
172 :Author: Martin Blais
177 This is the introduction.
233 (ert-deftest rst-find-all-adornments
()
234 "Tests for `rst-find-all-adornments'."
235 (should (ert-equal-buffer-return
236 (rst-find-all-adornments)
239 '((2 ?
= over-and-under
3)
244 (26 ?~ over-and-under
1)
247 (should (ert-equal-buffer-return
248 (rst-find-all-adornments)
255 (should (ert-equal-buffer-return
256 (rst-find-all-adornments)
264 (ert-deftest rst-get-hierarchy
()
265 "Tests for `rst-get-hierarchy'."
266 (should (ert-equal-buffer-return
270 '((?
= over-and-under
3)
273 (?~ over-and-under
1))
277 (ert-deftest rst-get-hierarchy-ignore
()
278 "Tests for `rst-get-hierarchy' with ignoring a line."
279 (should (ert-equal-buffer-return
280 (rst-get-hierarchy 26)
283 '((?
= over-and-under
3)
289 (ert-deftest rst-adornment-level
()
290 "Tests for `rst-adornment-level'."
291 (should (ert-equal-buffer-return
292 (rst-adornment-level t
)
297 (should (ert-equal-buffer-return
298 (rst-adornment-level nil
)
303 (should (ert-equal-buffer-return
304 (rst-adornment-level (?
= . over-and-under
))
309 (should (ert-equal-buffer-return
310 (rst-adornment-level (?
= . simple
))
315 (should (ert-equal-buffer-return
316 (rst-adornment-level (?- . simple
))
321 (should (ert-equal-buffer-return
322 (rst-adornment-level (?~ . over-and-under
))
327 (should (ert-equal-buffer-return
328 (rst-adornment-level (?
# . simple
))
335 (ert-deftest rst-adornment-complete-p
()
336 "Tests for `rst-adornment-complete-p'."
337 (should (ert-equal-buffer-return
338 (rst-adornment-complete-p (?
= simple
0))
346 (should (ert-equal-buffer-return
347 (rst-adornment-complete-p (?
= simple
0))
354 (should (ert-equal-buffer-return
355 (rst-adornment-complete-p (?
= over-and-under
0))
363 (should (ert-equal-buffer-return
364 (rst-adornment-complete-p (?
= over-and-under
2))
372 (should (ert-equal-buffer-return
373 (rst-adornment-complete-p (?
= simple
0))
380 (should (ert-equal-buffer-return
381 (rst-adornment-complete-p (?
= simple
0))
388 (should (ert-equal-buffer-return
389 (rst-adornment-complete-p (?
= simple
0))
396 (should (ert-equal-buffer-return
397 (rst-adornment-complete-p (?
= over-and-under
0))
405 (should (ert-equal-buffer-return
406 (rst-adornment-complete-p (?
= over-and-under
0))
414 (should (ert-equal-buffer-return
415 (rst-adornment-complete-p (?
= over-and-under
0))
423 (should (ert-equal-buffer-return
424 (rst-adornment-complete-p (?
= over-and-under
0))
432 (should (ert-equal-buffer-return
433 (rst-adornment-complete-p (?
= over-and-under
0))
441 (should (ert-equal-buffer-return
442 (rst-adornment-complete-p (?
= over-and-under
0))
450 (should (ert-equal-buffer-return
451 (rst-adornment-complete-p (?
= over-and-under
0))
459 (should (ert-equal-buffer-return
460 (rst-adornment-complete-p (?
= over-and-under
0))
468 (should (ert-equal-buffer-return
469 (rst-adornment-complete-p (?
= over-and-under
0))
477 (should (ert-equal-buffer-return
478 (rst-adornment-complete-p (?
= over-and-under
0))
486 (should (ert-equal-buffer-return
487 (rst-adornment-complete-p (?
= over-and-under
0))
495 (should (ert-equal-buffer-return
496 (rst-adornment-complete-p (?
= over-and-under
0))
506 (ert-deftest rst-get-adornments-around
()
507 "Tests for `rst-get-adornments-around'."
508 (should (ert-equal-buffer-return
509 (rst-get-adornments-around)
522 '((?- simple
0) (?
+ simple
0))))
523 (should (ert-equal-buffer-return
524 (rst-get-adornments-around)
538 '((?- simple
0) (?
+ simple
0))))
541 (defun apply-adornment-match (match)
542 "Apply the MATCH to the buffer and return important data.
543 MATCH is as returned by `rst-classify-adornment' or
544 `rst-find-title-line'. Puts point in the beginning of the title
545 line. Return a list consisting of (CHARACTER . STYLE) and the
546 three embedded match groups. Return nil if MATCH is nil. Checks
547 whether embedded match groups match match group 0."
549 (set-match-data (cdr match
))
550 (let ((whole (match-string-no-properties 0))
551 (over (match-string-no-properties 1))
552 (text (match-string-no-properties 2))
553 (under (match-string-no-properties 3))
556 (setq gather
(concat gather over
"\n")))
558 (setq gather
(concat gather text
"\n")))
560 (setq gather
(concat gather under
"\n")))
561 (if (not (string= (substring gather
0 -
1) whole
))
562 (error "Match 0 '%s' doesn't match concatenated parts '%s'"
564 (goto-char (match-beginning 2))
565 (list (car match
) over text under
))))
567 (defun classify-adornment (beg end
)
568 "Wrapper for calling `rst-classify-adornment'."
570 (apply-adornment-match (rst-classify-adornment
571 (buffer-substring-no-properties beg end
) end
)))
573 (ert-deftest rst-classify-adornment
()
574 "Tests for `rst-classify-adornment'."
575 (should (ert-equal-buffer-return
579 Du bon vin tous les jours
580 \^@=========================\^?
585 nil
"Du bon vin tous les jours" "=========================")
587 (should (ert-equal-buffer-return
591 Du bon vin tous les jours
592 \^@====================\^?
597 nil
"Du bon vin tous les jours" "====================")
599 (should (ert-equal-buffer-return
603 Du bon vin tous les jours
604 \^@====================\^?
609 nil
" Du bon vin tous les jours" "====================")
611 (should (ert-equal-buffer-return
615 Du bon vin tous les jours
621 (should (ert-equal-buffer-return
625 Du bon vin tous les jours
631 (should (ert-equal-buffer-return
635 Du bon vin tous les jours
640 nil
"Du bon vin tous les jours" "---")
642 (should (ert-equal-buffer-return
645 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
646 Du bon vin tous les jours
647 ~~~~~~~~~~~~~~~~~~~~~~~~~
651 '((?~ . over-and-under
)
652 "~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
654 (should (ert-equal-buffer-return
656 "~~~~~~~~~~~~~~~~~~~~~~~~~
657 Du bon vin tous les jours
658 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
662 '((?~ . over-and-under
)
663 "~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
665 (should (ert-equal-buffer-return
668 \^@~~~~~~~~~~~~~~~~~~~~~~~~~\^?
669 Du bon vin tous les jours
670 ~~~~~~~~~~~~~~~~~~~~~~~~~
674 '((?~ . over-and-under
)
675 "~~~~~~~~~~~~~~~~~~~~~~~~~" " Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~")
677 (should (ert-equal-buffer-return
680 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
681 Du bon vin tous les jours
686 '((?~ . over-and-under
)
687 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~")
689 (should (ert-equal-buffer-return
692 ---------------------------
693 Du bon vin tous les jours
694 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
699 nil
"Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~~~")
701 (should (ert-equal-buffer-return
703 "\^@---------------------------\^?"
706 nil
"---------------------------" nil
)
708 (should (ert-equal-buffer-return
711 \^@---------------------------\^?
712 Du bon vin tous les jours
713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
719 (should (ert-equal-buffer-return
722 =========================
723 Du bon vin tous les jours
724 \^@=========================\^?
729 '((?
= . over-and-under
)
730 "=========================" "Du bon vin tous les jours" "=========================")
732 (should (ert-equal-buffer-return
735 =========================
736 Du bon vin tous les jours
737 =========================
744 nil
"Du bon vin" "----------")
746 (should (ert-equal-buffer-return
749 =========================
750 Du bon vin tous les jours
751 =========================
758 '((?- . over-and-under
)
759 "----------" "Du bon vin" "----------")
761 (should (ert-equal-buffer-return
764 =========================
765 Du bon vin tous les jours
766 =========================
773 '((?- . over-and-under
)
774 "--------------" " Du bon vin" "--------------")