Debian Codegraph @

tools/editors/emacs/tests/Ttl.el

raw
1 ;; Tests for class `rst-Ttl' -*- lexical-binding: t -*-
2
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
6
7 (setq buf-lines
8 "Simple
9 ======
10
11 ----------
12 Double
13 ----------
14
15 Candidate
16 \^@
17 ~~~~~~~~~~
18 Half
19
20 **********
21 "
22 ado-spl (rst-Ado-new-simple ?=)
23 txt-spl-beg 1
24 txt-spl-end 7
25 und-spl-beg 8
26 und-spl-end 14
27 mtc-spl (list txt-spl-beg und-spl-end
28 nil nil
29 txt-spl-beg txt-spl-end
30 und-spl-beg und-spl-end)
31 ind-spl 0
32 hdr-spl (rst-Hdr-new ado-spl 0)
33 txt-spl "Simple"
34 ado-dbl (rst-Ado-new-over-and-under ?-)
35 ovr-dbl-beg 16
36 ovr-dbl-end 26
37 txt-dbl-beg 27
38 txt-dbl-end 35
39 und-dbl-beg 36
40 und-dbl-end 46
41 mtc-dbl (list ovr-dbl-beg und-dbl-end
42 ovr-dbl-beg ovr-dbl-end
43 txt-dbl-beg txt-dbl-end
44 und-dbl-beg und-dbl-end)
45 ind-dbl 2
46 hdr-dbl (rst-Hdr-new ado-dbl 2)
47 txt-dbl "Double"
48 ado-cnd nil
49 txt-cnd-beg 48
50 txt-cnd-end 58
51 mtc-cnd (list txt-cnd-beg txt-cnd-end
52 nil nil
53 txt-cnd-beg txt-cnd-end
54 nil nil)
55 ind-cnd 1
56 txt-cnd "Candidate"
57 ado-hlf (rst-Ado-new-over-and-under ?~)
58 ovr-hlf-beg 60
59 ovr-hlf-end 70
60 txt-hlf-beg 71
61 txt-hlf-end 78
62 mtc-hlf (list ovr-hlf-beg txt-hlf-end
63 ovr-hlf-beg ovr-hlf-end
64 txt-hlf-beg txt-hlf-end
65 nil nil)
66 mtc-hlf (list ovr-hlf-beg txt-hlf-end
67 ovr-hlf-beg ovr-hlf-end
68 txt-hlf-beg txt-hlf-end
69 nil nil)
70 ind-hlf 3
71 txt-hlf "Half"
72 ado-trn (rst-Ado-new-transition)
73 txt-trn-beg 80
74 txt-trn-end 90
75 mtc-trn (list txt-trn-beg txt-trn-end
76 nil nil
77 txt-trn-beg txt-trn-end
78 nil nil)
79 ind-trn nil
80 txt-trn nil
81 )
82
83 (ert-deftest rst-Ttl-asserts ()
84 "Check some assertions."
85 (should (equal ert-Buf-point-char "\^@"))
86 (should (equal ert-Buf-mark-char "\^?"))
87 )
88
89 (ert-deftest rst-Ttl--new ()
90 "Test `rst-Ttl--new'."
91 ;; Check type checking of ado argument.
92 (should-error (rst-Ttl--new hdr-spl mtc-spl ind-spl txt-spl)
93 :type 'wrong-type-argument)
94
95 ;; Check type and value checking of match argument.
96 (should-error (rst-Ttl--new ado-spl 1 ind-spl txt-spl)
97 :type 'wrong-type-argument)
98 (should-error (rst-Ttl--new ado-spl nil ind-spl txt-spl)
99 :type 'wrong-type-argument)
100 (should-error (rst-Ttl--new ado-spl '(1 2 3) ind-spl txt-spl)
101 :type 'wrong-type-argument)
102 (should-error (rst-Ttl--new ado-spl '(1 2 "3" 4 5 6 7 8) ind-spl txt-spl)
103 :type 'wrong-type-argument)
104 (should-error (rst-Ttl--new nil '(1 2 3 4 5 6 7 8) ind-spl txt-spl)
105 :type 'args-out-of-range)
106
107 ;; Check value checking of match argument for tranisitions.
108 (should-error (rst-Ttl--new ado-trn (list nil nil
109 nil nil
110 txt-spl-beg txt-spl-end
111 und-spl-beg und-spl-end)
112 ind-spl txt-trn)
113 :type 'args-out-of-range)
114 (should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
115 txt-spl-beg txt-spl-end
116 und-spl-beg und-spl-end
117 nil nil)
118 ind-spl txt-trn)
119 :type 'args-out-of-range)
120 (should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
121 nil nil
122 txt-spl-beg txt-spl-end
123 und-spl-beg und-spl-end)
124 ind-spl txt-trn)
125 :type 'args-out-of-range)
126 (should-error (rst-Ttl--new ado-trn (list txt-spl-beg und-spl-end
127 nil nil
128 nil nil
129 und-spl-beg und-spl-end)
130 ind-spl txt-trn)
131 :type 'args-out-of-range)
132
133 ;; Check value checking of match argument for simple section header.
134 (should-error (rst-Ttl--new ado-spl (list nil nil
135 nil nil
136 txt-spl-beg txt-spl-end
137 und-spl-beg und-spl-end)
138 ind-spl txt-spl)
139 :type 'args-out-of-range)
140 (should-error (rst-Ttl--new ado-spl (list txt-spl-beg und-spl-end
141 txt-spl-beg txt-spl-end
142 und-spl-beg und-spl-end
143 und-spl-beg und-spl-end)
144 ind-spl txt-spl)
145 :type 'args-out-of-range)
146 (should-error (rst-Ttl--new ado-spl (list txt-spl-beg und-spl-end
147 nil nil
148 txt-spl-beg txt-spl-end
149 nil nil)
150 ind-spl txt-spl)
151 :type 'args-out-of-range)
152
153 ;; Check value checking of match argument for double section header.
154 (should-error (rst-Ttl--new ado-dbl (list nil nil
155 ovr-dbl-beg ovr-dbl-end
156 txt-dbl-beg txt-dbl-end
157 und-dbl-beg und-dbl-end)
158 ind-dbl txt-dbl)
159 :type 'args-out-of-range)
160 (should-error (rst-Ttl--new ado-dbl (list ovr-dbl-beg und-dbl-end
161 nil nil
162 txt-dbl-beg txt-dbl-end
163 und-dbl-beg und-dbl-end)
164 ind-dbl txt-dbl)
165 :type 'args-out-of-range)
166 (should-error (rst-Ttl--new ado-dbl (list ovr-dbl-beg und-dbl-end
167 ovr-dbl-beg ovr-dbl-end
168 nil nil
169 und-dbl-beg und-dbl-end)
170 ind-dbl txt-dbl)
171 :type 'args-out-of-range)
172
173 ;; Check type and value checking of indent argument.
174 (should-error (rst-Ttl--new ado-trn mtc-trn 1 txt-trn)
175 :type 'wrong-type-argument)
176 (should-error (rst-Ttl--new ado-spl mtc-spl nil txt-spl)
177 :type 'wrong-type-argument)
178 (should-error (rst-Ttl--new ado-spl mtc-spl -1 txt-spl)
179 :type 'wrong-type-argument)
180
181 ;; Check type and value checking of text argument.
182 (should-error (rst-Ttl--new ado-trn mtc-trn ind-trn "Text")
183 :type 'wrong-type-argument)
184 (should-error (rst-Ttl--new ado-spl mtc-spl ind-spl nil)
185 :type 'wrong-type-argument)
186 (should-error (rst-Ttl--new ado-spl mtc-spl ind-spl 3)
187 :type 'wrong-type-argument)
188 (should-error (rst-Ttl--new ado-trn mtc-spl ind-spl txt-spl)
189 :type 'args-out-of-range)
190
191 (should (rst-Ttl-p (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)))
192 (should (rst-Ttl-p (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)))
193 (should (rst-Ttl-p (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)))
194 (should (rst-Ttl-p (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)))
195 (should (rst-Ttl-p (rst-Ttl--new ado-trn mtc-trn ind-trn txt-trn)))
196
197 ;; Check setting of header.
198 (should (equal (rst-Ttl-hdr (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl))
199 (rst-Hdr-new ado-spl ind-spl)))
200 (should (equal (rst-Ttl-hdr (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl))
201 (rst-Hdr-new ado-dbl ind-dbl)))
202 (should (equal (rst-Ttl-hdr (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf))
203 (rst-Hdr-new ado-hlf ind-hlf)))
204 (should-not (rst-Ttl-hdr (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)))
205 (should-not (rst-Ttl-hdr (rst-Ttl--new ado-trn mtc-cnd nil txt-trn)))
206
207 )
208
209 (ert-deftest rst-Ttl-get-title-beginning ()
210 "Test `rst-Ttl-get-title-beginning'."
211 (should (equal (rst-Ttl-get-title-beginning
212 (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) txt-spl-beg))
213 (should (equal (rst-Ttl-get-title-beginning
214 (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) txt-dbl-beg))
215 (should (equal (rst-Ttl-get-title-beginning
216 (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) txt-hlf-beg))
217 (should (equal (rst-Ttl-get-title-beginning
218 (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-beg))
219 )
220
221 (ert-deftest rst-Ttl-get-beginning_end ()
222 "Test `rst-Ttl-get-beginning' and `rst-Ttl-get-end'."
223 (should (equal (rst-Ttl-get-beginning
224 (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) txt-spl-beg))
225 (should (equal (rst-Ttl-get-end
226 (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl)) und-spl-end))
227 (should (equal (rst-Ttl-get-beginning
228 (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) ovr-dbl-beg))
229 (should (equal (rst-Ttl-get-end
230 (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl)) und-dbl-end))
231 (should (equal (rst-Ttl-get-beginning
232 (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) ovr-hlf-beg))
233 (should (equal (rst-Ttl-get-end
234 (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf)) txt-hlf-end))
235 (should (equal (rst-Ttl-get-beginning
236 (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-beg))
237 (should (equal (rst-Ttl-get-end
238 (rst-Ttl--new ado-cnd mtc-cnd ind-cnd txt-cnd)) txt-cnd-end))
239 )
240
241 (ert-deftest rst-Ttl-from-buffer ()
242 "Test `rst-Ttl-from-buffer'."
243 (let ((ttl-spl (rst-Ttl--new ado-spl mtc-spl ind-spl txt-spl))
244 (ttl-dbl (rst-Ttl--new ado-dbl mtc-dbl ind-dbl txt-dbl))
245 (ttl-cnd (rst-Ttl--new nil mtc-cnd ind-cnd txt-cnd))
246 (ttl-hlf (rst-Ttl--new ado-hlf mtc-hlf ind-hlf txt-hlf))
247 (ttl-trn (rst-Ttl--new ado-trn mtc-trn ind-trn txt-trn)))
248
249 ;; Check type checking of beg-txt argument.
250 (should-error (rst-Ttl-from-buffer nil nil nil nil nil)
251 :type 'wrong-type-argument)
252
253 (should (ert-equal-buffer-return
254 '(rst-Ttl-from-buffer
255 ado-spl nil txt-spl-beg und-spl-beg txt-spl)
256 buf-lines
257 t
258 ttl-spl))
259 (should (ert-equal-buffer-return
260 '(rst-Ttl-from-buffer
261 ado-dbl ovr-dbl-beg txt-dbl-beg und-dbl-beg txt-dbl)
262 buf-lines
263 t
264 ttl-dbl))
265 (should (ert-equal-buffer-return
266 '(rst-Ttl-from-buffer
267 nil nil txt-cnd-beg nil txt-cnd)
268 buf-lines
269 t
270 ttl-cnd))
271 (should (ert-equal-buffer-return
272 '(rst-Ttl-from-buffer
273 ado-hlf ovr-hlf-beg txt-hlf-beg nil txt-hlf)
274 buf-lines
275 t
276 ttl-hlf))
277 (should (ert-equal-buffer-return
278 '(rst-Ttl-from-buffer
279 ado-trn nil txt-trn-beg nil txt-trn)
280 buf-lines
281 t
282 ttl-trn))
283 ))
284
285 (defun ttl-contains (pnt)
286 "Run `rst-Ttl-contains' on current buffer comparing first title with point."
287 (interactive "d")
288 (rst-Ttl-contains (car (rst-all-ttls-compute)) pnt))
289
290 (ert-deftest rst-Ttl-contains ()
291 "Test `rst-Ttl-contains'."
292 (should-error (rst-Ttl-contains nil nil)
293 :type 'wrong-type-argument)
294
295 (should (ert-equal-buffer-return
296 '(ttl-contains nil)
297 "
298 ===
299 \^@One
300 ===
301 "
302 nil
303 0
304 t))
305 (should (ert-equal-buffer-return
306 '(ttl-contains nil)
307 "
308 \^@===
309 One
310 ===
311 "
312 nil
313 0
314 t))
315 (should (ert-equal-buffer-return
316 '(ttl-contains nil)
317 "
318 ===
319 One
320 ===\^@
321 "
322 nil
323 0
324 t))
325 (should (ert-equal-buffer-return
326 '(ttl-contains nil)
327 "
328 \^@One
329 ===
330 "
331 nil
332 0
333 t))
334 (should (ert-equal-buffer-return
335 '(ttl-contains nil)
336 "
337 One
338 ===\^@
339 "
340 nil
341 0
342 t))
343 (should (ert-equal-buffer-return
344 '(ttl-contains nil)
345 "\^@
346 One
347 ===
348 "
349 nil
350 1
351 t))
352 (should (ert-equal-buffer-return
353 '(ttl-contains nil)
354 "
355 One
356 ===
357 \^@"
358 nil
359 -1
360 t))
361 )