Lots of refactorings and a few minor improvements.
[docutils.git] / docutils / tools / editors / emacs / tests / items.el
blobf2f3002cf199e04674d25dbd0425a0a25a414abd
1 ;; Tests for operations on list items -*- lexical-binding: t -*-
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
7 (ert-deftest items-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
13 (defun find-begs (beg-re)
14 (rst-find-begs (region-beginning) (region-end) beg-re))
16 (ert-deftest rst-find-begs ()
17 "Tests `rst-find-begs'."
18 (should (ert-equal-buffer-return
19 '(find-begs 'itmany-beg-1)
20 "\^@1 Normal paragraph.
22 * 22 A bullet
24 * 37 Another bullet
26 58 Another normal paragraph.
28 \^?"
29 t '((22 . 0)
30 (37 . 0))))
31 (should (ert-equal-buffer-return
32 '(find-begs 'itmany-beg-1)
33 "1 Normal paragraph.
35 \^?* 22 A bullet
37 * 37 Another bullet
39 \^@58 Another normal paragraph.
42 t '((22 . 0)
43 (37 . 0))))
44 (should (ert-equal-buffer-return
45 '(find-begs 'itmany-beg-1)
46 "1 Normal paragraph.
48 \^?* 22 A bullet
50 * 37 Another bullet
52 1. 58 An enum.
54 2. 74 Another enum.
56 \^@95 Another normal paragraph.
59 t '((22 . 0)
60 (37 . 0)
61 (58 . 0)
62 (74 . 0))))
63 (should (ert-equal-buffer-return
64 '(find-begs 'bul-beg)
65 "\^@
66 - 2 one
67 + 10 two
68 * 19 three
69 \^?"
70 t '((2 . 0)
71 (10 . 0)
72 (19 . 0))))
73 (should (ert-equal-buffer-return
74 '(find-begs 'bul-beg)
76 - 2 one\^@
77 + 10 two
78 * 19 three
79 \^?"
80 t '((2 . 0)
81 (10 . 0)
82 (19 . 0))))
83 (should (ert-equal-buffer-return
84 '(find-begs 'bul-beg)
85 "+ 1 zero
86 \^@- 10 one
87 + 19 two
88 * 28 three\^?
90 t '((10 . 0)
91 (19 . 0)
92 (28 . 0))))
93 (should (ert-equal-buffer-return
94 '(find-begs 'bul-beg)
95 "\^@
96 - 2 one
98 + 11 two
100 * 23 three
101 \^?"
102 t '((2 . 0)
103 (13 . 2)
104 (23 . 0))))
105 (should (ert-equal-buffer-return
106 '(find-begs 'bul-beg)
107 "\^@Normal paragraph
109 * 19 bullet
111 * 32 three
113 Another normal paragraph
114 \^?"
115 t '((19 . 0)
116 (34 . 2))))
119 (ert-deftest rst-find-begs-BUGS ()
120 "Exposes bugs in `rst-find-begs'."
121 :expected-result :failed ;; These are bugs
122 (should (ert-equal-buffer-return
123 '(find-begs 'bul-beg)
124 "\^@Normal paragraph
125 * 18 bullet
126 * 30 three
127 Another normal paragraph
128 \^?"
129 t '((18 . 0)
130 (32 . 2))))
131 (should (ert-equal-buffer-return
132 '(find-begs 'bul-beg)
133 "\^@
134 - 2 one
135 + 10 two
136 * 21 three
137 \^?"
138 t '((2 . 0)
139 (12 . 2)
140 (19 . 0))))
143 (ert-deftest rst-convert-bullets-to-enumeration ()
144 "Tests `rst-convert-bullets-to-enumeration'."
145 (should (ert-equal-buffer
146 '(rst-convert-bullets-to-enumeration)
147 "\^@Normal paragraph.
149 * A bullet
151 * Another bullet
153 Another normal paragraph.
155 \^?"
156 "\^@Normal paragraph.
158 1. A bullet
160 2. Another bullet
162 Another normal paragraph.
164 \^?" t))
165 (should (ert-equal-buffer
166 '(rst-convert-bullets-to-enumeration)
167 "Normal paragraph.
169 \^?* A bullet
171 * Another bullet
173 \^@Another normal paragraph.
176 "Normal paragraph.
178 \^?1. A bullet
180 2. Another bullet
182 \^@Another normal paragraph.
184 " t))
185 (should (ert-equal-buffer
186 '(rst-convert-bullets-to-enumeration)
187 "Normal paragraph.
189 \^?* A bullet
191 * Another bullet
193 1. A bullet
195 2. Another bullet
197 \^@Another normal paragraph.
201 "Normal paragraph.
203 \^?1. A bullet
205 2. Another bullet
207 3. A bullet
209 4. Another bullet
211 \^@Another normal paragraph.
213 " t))
216 (ert-deftest rst-convert-bullets-to-enumeration-BUGS ()
217 "Exposes bugs in `rst-convert-bullets-to-enumeration'."
218 :expected-result :failed ;; These are bugs
219 (should (ert-equal-buffer
220 '(rst-convert-bullets-to-enumeration)
221 "\^@Normal paragraph.
223 * A bullet
225 * Another bullet
227 * A bullet
229 * Another bullet
231 Another normal paragraph.
233 \^?"
234 "\^@Normal paragraph.
236 1. A bullet
238 2. Another bullet
240 * A bullet
242 * Another bullet
244 Another normal paragraph.
246 \^?" t))
249 (ert-deftest rst-insert-list-continue ()
250 "Tests `rst-insert-list' when continuing a list."
251 (should (ert-equal-buffer
252 '(rst-insert-list)
253 "* Some text\^@\n"
254 "* Some text
255 * \^@\n"))
256 (should (ert-equal-buffer
257 '(rst-insert-list)
258 "* Some \^@text\n"
259 "* Some text
260 * \^@\n"))
261 (should (ert-equal-buffer
262 '(rst-insert-list)
263 "* \^@Some text\n"
264 "* Some text
265 * \^@\n"))
266 (should (ert-equal-buffer
267 '(rst-insert-list)
268 "* Some text
269 - A deeper hyphen bullet\^@\n"
270 "* Some text
271 - A deeper hyphen bullet
272 - \^@\n"))
273 (should (ert-equal-buffer
274 '(rst-insert-list)
275 "* Some text
276 - \^@Some text\n"
277 "* Some text
278 - Some text
279 - \^@\n"))
280 (should (ert-equal-buffer
281 '(rst-insert-list)
282 "1. Some text\^@\n"
283 "1. Some text
284 2. \^@\n"))
285 (should (ert-equal-buffer
286 '(rst-insert-list)
287 "2. Some text\^@\n"
288 "2. Some text
289 3. \^@\n"))
290 (should (ert-equal-buffer
291 '(rst-insert-list)
292 "a) Some text\^@\n"
293 "a) Some text
294 b) \^@\n"))
295 (should (ert-equal-buffer
296 '(rst-insert-list)
297 "(A) Some text\^@\n"
298 "(A) Some text
299 \(B) \^@\n"))
300 (should (ert-equal-buffer
301 '(rst-insert-list)
302 "(I) Some text\^@\n"
303 "(I) Some text
304 \(J) \^@\n"))
305 (should (ert-equal-buffer
306 '(rst-insert-list)
307 "(I) Some text\^@\n"
308 "(I) Some text
309 \(J) \^@\n"))
310 (should (ert-equal-buffer
311 '(rst-insert-list)
312 "(h) Some text
313 \(i) Some text\^@\n"
314 "(h) Some text
315 \(i) Some text
316 \(j) \^@\n"))
317 (should (ert-equal-buffer
318 '(rst-insert-list t)
319 "(i) Some text\^@\n"
320 "(i) Some text
321 \(ii) \^@\n"))
322 (should (ert-equal-buffer
323 '(rst-insert-list)
324 "(IV) Some text
325 \(V) Some text\^@\n"
326 "(IV) Some text
327 \(V) Some text
328 \(VI) \^@\n"))
331 (ert-deftest rst-insert-list-continue-BUGS ()
332 "Exposes bugs in `rst-insert-list-continue'."
333 :expected-result :failed ;; These are bugs
334 (should (ert-equal-buffer
335 '(rst-insert-list)
336 "(iv) Some text
338 \(v) Some text\^@\n"
339 "(iv) Some text
341 \(v) Some text
342 \(vi) \^@\n")))
344 (ert-deftest rst-insert-list-new ()
345 "Tests `rst-insert-list' when inserting a new list."
346 (should (ert-equal-buffer
347 '(rst-insert-list)
348 "\^@
350 "* \^@
351 " '("*")))
352 (should (ert-equal-buffer
353 '(rst-insert-list)
358 - \^@
359 " '("-")))
360 (should (ert-equal-buffer
361 '(rst-insert-list)
367 #. \^@
369 " '("#.")))
370 (should (ert-equal-buffer
371 '(rst-insert-list)
372 "\^@
374 "5) \^@
375 " '("1)" 5)))
376 (should (ert-equal-buffer
377 '(rst-insert-list)
378 "\^@
380 "(i) \^@
381 " '("(i)" "")))
382 (should (ert-equal-buffer
383 '(rst-insert-list)
384 "\^@
386 "IV. \^@
387 " '("I." 4)))
388 (should (ert-equal-buffer
389 '(rst-insert-list)
390 "Some line\^@
392 "Some line
394 c. \^@
395 " '("a." "c")))
396 (should (ert-equal-buffer
397 '(rst-insert-list)
398 "Some line
401 "Some line
403 B) \^@
404 " '("A)" "B")))
405 (should (ert-equal-buffer
406 '(rst-insert-list)
407 "Some line
411 "Some line
413 IV. \^@
414 " '("I." 4)))
415 (should (ert-equal-buffer
416 '(rst-insert-list)
417 "Some line
418 \^@Another line
420 "Some line
421 Another line
423 * \^@
424 " '("*")))
427 (ert-deftest rst-insert-list-new-BUGS ()
428 "Exposes bugs in `rst-insert-list' when inserting a new list."
429 :expected-result :failed ;; These are bugs
430 (should (ert-equal-buffer
431 '(rst-insert-list)
432 "\^@ \n"
433 "* \^@
434 " '("*")))
435 (should (ert-equal-buffer
436 '(rst-insert-list)
437 "Some line
439 Another line
441 "Some line
443 * \^@
445 Another line
446 " '("*")))
449 (ert-deftest rst-straighten-bullets-region ()
450 "Tests `rst-straighten-bullets-region'."
451 (let ((rst-preferred-bullets '(?* ?-)))
452 (should (ert-equal-buffer
453 '(rst-straighten-bullets-region)
454 "\^@\^?"
455 "\^@\^?"
457 (should (ert-equal-buffer
458 '(rst-straighten-bullets-region)
459 "\^@
460 - one
461 + two
462 * three
463 \^?"
464 "\^@
465 * one
466 * two
467 * three
468 \^?"
470 (should (ert-equal-buffer
471 '(rst-straighten-bullets-region)
472 "- one\^@
473 + two\^?"
474 "* one\^@
475 * two\^?"
477 (should (ert-equal-buffer
478 '(rst-straighten-bullets-region)
479 "+ zero
480 \^@- one
481 + two
482 * three\^?
483 - four"
484 "+ zero
485 \^@* one
486 * two
487 * three\^?
488 - four"
490 (should (ert-equal-buffer
491 '(rst-straighten-bullets-region)
492 "\^@
493 - one
495 + two
497 * three
498 \^?"
499 "\^@
500 * one
502 - two
504 * three
505 \^?"
507 (should (ert-equal-buffer
508 '(rst-straighten-bullets-region)
509 "\^@
510 - one
512 - two
514 * three
515 \^?"
516 "\^@
517 * one
519 - two
521 * three
522 \^?"
524 (should (ert-equal-buffer
525 '(rst-straighten-bullets-region)
526 "\^@
527 + one
529 * two
531 + three
532 \^?"
533 "\^@
534 * one
536 - two
538 * three
539 \^?"
542 (let ((rst-preferred-bullets nil))
543 (should (ert-equal-buffer
544 '(rst-straighten-bullets-region)
545 "\^@
546 - one
547 + two
548 * three
549 \^?"
550 "\^@
551 - one
552 + two
553 * three
554 \^?"
558 (ert-deftest rst-straighten-bullets-region-BUGS ()
559 "Tests `rst-straighten-bullets-region'."
560 :expected-result :failed ;; These are bugs
561 (let ((rst-preferred-bullets '(?* ?-)))
562 (should (ert-equal-buffer
563 '(rst-straighten-bullets-region)
564 "\^@
565 - one
566 + two
567 * three
568 \^?"
569 "\^@
570 * one
571 - two
572 * three
573 \^?"
575 (should (ert-equal-buffer
576 '(rst-straighten-bullets-region)
577 "\^@
578 - one
579 + two
580 * three
581 \^?"
582 "\^@
583 * one
584 - two
585 * three
586 \^?"
588 (should (ert-equal-buffer
589 '(rst-straighten-bullets-region)
590 "\^@
591 + one
592 * two
593 + three
594 \^?"
595 "\^@
596 * one
597 - two
598 * three
599 \^?"
603 (defun arabic-roman-roundtrip (arabic roman)
604 "Convert ARABIC to roman, compare it to ROMAN and convert this back.
605 Return t if roundtrip is correct."
606 (let ((cvt-roman (rst-arabic-to-roman arabic))
607 (cvt-arabic (rst-roman-to-arabic roman)))
608 (and (equal roman cvt-roman) (equal arabic cvt-arabic))))
610 (ert-deftest arabic-roman-roundtrip ()
611 "Test `rst-arabic-to-roman' and `rst-roman-to-arabic'."
613 ;; Test invalid arabic numbers.
614 (should-error (arabic-roman-roundtrip -1 "I")
615 :type 'wrong-type-argument)
616 (should-error (arabic-roman-roundtrip 0 "I")
617 :type 'wrong-type-argument)
618 (should-error (arabic-roman-roundtrip nil "I")
619 :type 'wrong-type-argument)
621 ;; Test invalid roman numbers.
622 (should-error (arabic-roman-roundtrip 1 nil)
623 :type 'wrong-type-argument)
624 (should-error (arabic-roman-roundtrip 1 "NoRoman")
625 :type 'wrong-type-argument)
626 (should-error (arabic-roman-roundtrip 1 "")
627 :type 'wrong-type-argument)
629 ;; Test values.
630 (should (arabic-roman-roundtrip 1 "I"))
631 (should (arabic-roman-roundtrip 4 "IV"))
632 (should (arabic-roman-roundtrip 5 "V"))
633 (should (arabic-roman-roundtrip 10 "X"))
634 (should (arabic-roman-roundtrip 20 "XX"))
635 (should (arabic-roman-roundtrip 1999 "MCMXCIX"))
636 (should (arabic-roman-roundtrip 2000 "MM"))
637 (should (arabic-roman-roundtrip 3333 "MMMCCCXXXIII"))
638 (should (arabic-roman-roundtrip 444 "CDXLIV"))