Website: add template and basic stylesheet with menu. Update buildhtml.py (and theref...
[docutils.git] / sandbox / gitpull / web_stylesheet_and_menu / tools / editors / emacs / tests / adornment.el
blob10d18c07e2e9e8ec733317f1ef28d3cc86a1fb9d
1 ;; Tests for various functions handling adornments
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 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
20 (find-title-line)
23 Du bon vin tous les jours.
24 \^@
28 \^@Du bon vin tous les jours.
31 '((nil . nil) nil "Du bon vin tous les jours." nil)
33 (should (ert-equal-buffer-return
34 (find-title-line)
36 \^@
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
48 (find-title-line)
51 Du bon vin tous les jours.
52 ------\^@-----
56 \^@Du bon vin tous les jours.
57 -----------
59 '((?- . simple) nil "Du bon vin tous les jours." "-----------")
61 (should (ert-equal-buffer-return
62 (find-title-line)
64 ------\^@-----
65 Du bon vin tous les jours.
69 -----------
70 \^@Du bon vin tous les jours.
73 '((?- . nil) "-----------" "Du bon vin tous les jours." nil)
75 (should (ert-equal-buffer-return
76 (find-title-line)
78 \^@-----------
79 Du bon vin tous les jours.
80 -----------
84 -----------
85 \^@Du bon vin tous les jours.
86 -----------
89 '((?- . over-and-under) "-----------" "Du bon vin tous les jours."
90 "-----------")
92 (should (ert-equal-buffer-return
93 (find-title-line)
95 Du bon vin tous les jours.
96 \^@-----------
97 Du bon vin tous les jours.
98 -----------
102 Du bon vin tous les jours.
103 -----------
104 \^@Du bon vin tous les jours.
105 -----------
107 " ; This is not how the parser works but looks more logical
108 '((?- . over-and-under) "-----------" "Du bon vin tous les jours."
109 "-----------")
111 (should (ert-equal-buffer-return
112 (find-title-line)
115 \^@-----------
120 \^@-----------
125 (should (ert-equal-buffer-return
126 (find-title-line)
128 Line 1
130 Line 2
134 \^@Line 1
136 Line 2
139 '((nil . nil) nil "Line 1" nil)
141 (should (ert-equal-buffer-return
142 (find-title-line)
144 =====================================
145 Project Idea: Panorama Stitcher
146 ====================================
148 :Author: Martin Blais <blais@furius.ca>
150 Another Title
151 =============
154 =====================================
155 Project Idea: Panorama Stitcher
156 ====================================
158 \^@:Author: Martin Blais <blais@furius.ca>
160 Another Title
161 =============
163 '((nil . nil) nil ":Author: Martin Blais <blais@furius.ca>" nil)
167 (setq text-1
168 "===============================
169 Project Idea: My Document
170 ===============================
172 :Author: Martin Blais
174 Introduction
175 ============
177 This is the introduction.
179 Notes
180 -----
182 Some notes.
184 Main Points
185 ===========
187 Yep.
189 Super Point
190 -----------
192 ~~~~~~~~~~~
193 \^@ Sub Point
194 ~~~~~~~~~~~
196 Isn't this fabulous?
198 Conclusion
199 ==========
201 That's it, really.
205 (setq text-2
208 Previous
209 --------
211 Current\^@
212 ~~~~~~~
214 Next
215 ++++
219 (setq text-3
222 Previous
223 --------
225 Current\^@
226 ~~~~~~~
228 Next
229 ++++
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)
237 text-1
239 '((2 ?= over-and-under 3)
240 (7 ?= simple 0)
241 (12 ?- simple 0)
242 (17 ?= simple 0)
243 (22 ?- simple 0)
244 (26 ?~ over-and-under 1)
245 (31 ?= simple 0))
247 (should (ert-equal-buffer-return
248 (rst-find-all-adornments)
249 text-2
251 '((3 ?- simple 0)
252 (6 ?~ simple 0)
253 (9 ?+ simple 0))
255 (should (ert-equal-buffer-return
256 (rst-find-all-adornments)
257 text-3
259 '((3 ?- simple 0)
260 (6 ?~ simple 0))
264 (ert-deftest rst-get-hierarchy ()
265 "Tests for `rst-get-hierarchy'."
266 (should (ert-equal-buffer-return
267 (rst-get-hierarchy)
268 text-1
270 '((?= over-and-under 3)
271 (?= simple 0)
272 (?- simple 0)
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)
281 text-1
283 '((?= over-and-under 3)
284 (?= simple 0)
285 (?- simple 0))
289 (ert-deftest rst-adornment-level ()
290 "Tests for `rst-adornment-level'."
291 (should (ert-equal-buffer-return
292 (rst-adornment-level t)
293 text-1
297 (should (ert-equal-buffer-return
298 (rst-adornment-level nil)
299 text-1
303 (should (ert-equal-buffer-return
304 (rst-adornment-level (?= . over-and-under))
305 text-1
309 (should (ert-equal-buffer-return
310 (rst-adornment-level (?= . simple))
311 text-1
315 (should (ert-equal-buffer-return
316 (rst-adornment-level (?- . simple))
317 text-1
321 (should (ert-equal-buffer-return
322 (rst-adornment-level (?~ . over-and-under))
323 text-1
327 (should (ert-equal-buffer-return
328 (rst-adornment-level (?# . simple))
329 text-1
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))
341 \^@Vaudou
345 nil))
346 (should (ert-equal-buffer-return
347 (rst-adornment-complete-p (?= simple 0))
349 \^@Vaudou
350 ======
354 (should (ert-equal-buffer-return
355 (rst-adornment-complete-p (?= over-and-under 0))
357 ======
358 \^@Vaudou
359 ======
363 (should (ert-equal-buffer-return
364 (rst-adornment-complete-p (?= over-and-under 2))
366 ==========
367 \^@ Vaudou
368 ==========
372 (should (ert-equal-buffer-return
373 (rst-adornment-complete-p (?= simple 0))
375 \^@Vaudou
376 =====
379 nil))
380 (should (ert-equal-buffer-return
381 (rst-adornment-complete-p (?= simple 0))
383 \^@Vaudou
384 =======
387 nil))
388 (should (ert-equal-buffer-return
389 (rst-adornment-complete-p (?= simple 0))
391 \^@Vaudou
392 ===-==
395 nil))
396 (should (ert-equal-buffer-return
397 (rst-adornment-complete-p (?= over-and-under 0))
399 ======
400 \^@Vaudou
401 =====
404 nil))
405 (should (ert-equal-buffer-return
406 (rst-adornment-complete-p (?= over-and-under 0))
408 =====
409 \^@Vaudou
410 ======
413 nil))
414 (should (ert-equal-buffer-return
415 (rst-adornment-complete-p (?= over-and-under 0))
417 ======
418 \^@Vaudou
419 ===-==
422 nil))
423 (should (ert-equal-buffer-return
424 (rst-adornment-complete-p (?= over-and-under 0))
426 ===-==
427 \^@Vaudou
428 ======
431 nil))
432 (should (ert-equal-buffer-return
433 (rst-adornment-complete-p (?= over-and-under 0))
435 ======
436 \^@Vaudou
440 nil))
441 (should (ert-equal-buffer-return
442 (rst-adornment-complete-p (?= over-and-under 0))
444 ======
445 \^@Vaudou
446 ------
449 nil))
450 (should (ert-equal-buffer-return
451 (rst-adornment-complete-p (?= over-and-under 0))
453 ==========
454 \^@Vaudou
455 =========
458 nil))
459 (should (ert-equal-buffer-return
460 (rst-adornment-complete-p (?= over-and-under 0))
462 =========
463 \^@Vaudou
464 ==========
467 nil))
468 (should (ert-equal-buffer-return
469 (rst-adornment-complete-p (?= over-and-under 0))
471 ==========
472 \^@Vaudou
473 ===-======
476 nil))
477 (should (ert-equal-buffer-return
478 (rst-adornment-complete-p (?= over-and-under 0))
480 ===-======
481 \^@Vaudou
482 ==========
485 nil))
486 (should (ert-equal-buffer-return
487 (rst-adornment-complete-p (?= over-and-under 0))
489 ==========
490 \^@Vaudou
494 nil))
495 (should (ert-equal-buffer-return
496 (rst-adornment-complete-p (?= over-and-under 0))
498 ==========
499 \^@Vaudou
500 ----------
503 nil))
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)
512 Previous
513 --------
515 \^@Current
517 Next
518 ++++
522 '((?- simple 0) (?+ simple 0))))
523 (should (ert-equal-buffer-return
524 (rst-get-adornments-around)
527 Previous
528 --------
530 Current\^@
531 ~~~~~~~
533 Next
534 ++++
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."
548 (when match
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))
554 (gather ""))
555 (if over
556 (setq gather (concat gather over "\n")))
557 (if text
558 (setq gather (concat gather text "\n")))
559 (if under
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'"
563 whole gather))
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'."
569 (interactive "r")
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
576 (classify-adornment)
579 Du bon vin tous les jours
580 \^@=========================\^?
584 '((?= . simple)
585 nil "Du bon vin tous les jours" "=========================")
587 (should (ert-equal-buffer-return
588 (classify-adornment)
591 Du bon vin tous les jours
592 \^@====================\^?
596 '((?= . simple)
597 nil "Du bon vin tous les jours" "====================")
599 (should (ert-equal-buffer-return
600 (classify-adornment)
603 Du bon vin tous les jours
604 \^@====================\^?
608 '((?= . simple)
609 nil " Du bon vin tous les jours" "====================")
611 (should (ert-equal-buffer-return
612 (classify-adornment)
615 Du bon vin tous les jours
616 \^@-\^?
621 (should (ert-equal-buffer-return
622 (classify-adornment)
625 Du bon vin tous les jours
626 \^@--\^?
631 (should (ert-equal-buffer-return
632 (classify-adornment)
635 Du bon vin tous les jours
636 \^@---\^?
639 '((?- . simple)
640 nil "Du bon vin tous les jours" "---")
642 (should (ert-equal-buffer-return
643 (classify-adornment)
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
655 (classify-adornment)
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
666 (classify-adornment)
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
678 (classify-adornment)
680 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
681 Du bon vin tous les jours
682 ~~~~~~~~~~~~~~~~~~~
686 '((?~ . over-and-under)
687 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~")
689 (should (ert-equal-buffer-return
690 (classify-adornment)
692 ---------------------------
693 Du bon vin tous les jours
694 \^@~~~~~~~~~~~~~~~~~~~~~~~~~~~\^?
698 '((?~ . simple)
699 nil "Du bon vin tous les jours" "~~~~~~~~~~~~~~~~~~~~~~~~~~~")
701 (should (ert-equal-buffer-return
702 (classify-adornment)
703 "\^@---------------------------\^?"
706 nil "---------------------------" nil)
708 (should (ert-equal-buffer-return
709 (classify-adornment)
711 \^@---------------------------\^?
712 Du bon vin tous les jours
713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
719 (should (ert-equal-buffer-return
720 (classify-adornment)
722 =========================
723 Du bon vin tous les jours
724 \^@=========================\^?
725 Du bon vin
729 '((?= . over-and-under)
730 "=========================" "Du bon vin tous les jours" "=========================")
732 (should (ert-equal-buffer-return
733 (classify-adornment)
735 =========================
736 Du bon vin tous les jours
737 =========================
738 Du bon vin
739 \^@----------\^?
743 '((?- . simple)
744 nil "Du bon vin" "----------")
746 (should (ert-equal-buffer-return
747 (classify-adornment)
749 =========================
750 Du bon vin tous les jours
751 =========================
752 \^@----------\^?
753 Du bon vin
754 ----------
758 '((?- . over-and-under)
759 "----------" "Du bon vin" "----------")
761 (should (ert-equal-buffer-return
762 (classify-adornment)
764 =========================
765 Du bon vin tous les jours
766 =========================
767 --------------
768 Du bon vin
769 \^@--------------\^?
773 '((?- . over-and-under)
774 "--------------" " Du bon vin" "--------------")