A simple first stab at a series of regression
[docutils.git] / tools / editors / emacs / tests / tests-adjust-section.el
blobdf01b2bd5d25fcb4ecf11d744b50a4da8bb5e9c1
1 ;; Authors: Martin Blais <blais@furius.ca>
2 ;; Date: $Date: 2005/04/01 23:19:41 $
3 ;; Copyright: This module has been placed in the public domain.
4 ;;
5 ;; Regression tests for rest-adjust-section-title.
6 ;;
8 (defvar rest-adjust-section-tests
9 '(
10 (simple
12 Some Title@
16 Some Title
17 ==========
21 (simple-cursor-in-line
23 Some Tit@le
27 Some Title
28 ==========
32 (simple-cursor-beginning
34 @Some Title
38 Some Title
39 ==========
43 (simple-at-end-of-buffer
45 Some Title@"
47 Some Title
48 ==========
51 (cursor-on-empty-line-under
53 Some Title
57 Some Title
58 ==========
64 (partial
66 Some Title@
67 ---
70 Some Title
71 ----------
75 (cursor-on-underline
77 Some Title
78 ---@
81 Some Title
82 ----------
86 (cursor-on-underline-one-char
88 Some Title
92 Some Title
93 ~~~~~~~~~~
97 (with-previous-text
99 Some Title
100 **********
102 Subtitle@
106 Some Title
107 **********
109 Subtitle
110 ********
114 (with-previous-text-rotating
116 Some Title
117 ==========
119 Subtitle
120 --------
122 Subtitle2@
126 Some Title
127 ==========
129 Subtitle
130 --------
132 Subtitle2
133 =========
140 "A list of regression tests for the section update method.")
143 (defun regression-test-compare-expect-buffer (testlist fun)
144 "Run the regression tests for the section adjusting method."
146 (let ((buf (get-buffer-create "restructuredtext-regression-tests"))
147 (specchar "@")
149 (dolist (curtest testlist)
150 ;; prepare a buffer with the starting text, and move the cursor where
151 ;; the special character is located
152 (switch-to-buffer buf)
153 (erase-buffer)
154 (insert (cadr curtest))
155 (search-backward specchar)
156 (delete-char 1)
158 ;; run the section title update command n times
159 (dotimes (x (or (cadddr curtest) 1))
160 (funcall fun))
162 ;; compare the buffer output with the expected text
163 (or (string=
164 (buffer-string)
165 (caddr curtest))
166 (progn
167 (error "Test %s failed." (car curtest))))
171 ;; evaluate this to run the tests, either interactively or in batch
172 (regression-test-compare-expect-buffer
173 rest-adjust-section-tests
174 (lambda ()
175 (call-interactively 'rest-adjust-section-title)))