Debian Codegraph @

tools/editors/emacs/tests/shift.el

raw
1 ;; Tests for various functions around shifting text -*- lexical-binding: t -*-
2
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
6
7 (ert-deftest shift-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
11 )
12
13 (defun string-insert (s col char)
14 "Insert CHAR at position COL in S. Return S."
15 (let ((l (length s))
16 (c (char-to-string char)))
17 (if (<= l col)
18 (concat s (make-string (- col l) ? ) c)
19 (concat (substring s 0 col) c (substring s (1+ col))))))
20
21 (defun line-tabs ()
22 "Wrapper to call `rst-line-tabs' creating a readable result."
23 (let ((tabs (rst-line-tabs))
24 (s "")
25 (cnt 0)
26 c)
27 (delete-region (point-min) (point-max))
28 (dolist (tab tabs)
29 (setq c (+ ?A cnt))
30 (if (cdr tab) (setq c (+ c (- ?a ?A))))
31 (setq s (string-insert s (car tab) c))
32 (setq cnt (1+ cnt)))
33 (insert "\n" s)))
34
35 (ert-deftest rst-line-tabs ()
36 "Tests for `rst-line-tabs'."
37 (let ((rst-indent-width 2)
38 (rst-indent-field 2)
39 (rst-indent-literal-normal 3)
40 (rst-indent-literal-minimized 2)
41 (rst-indent-comment 3))
42 (should (ert-equal-buffer
43 '(line-tabs)
44 "\^@"
45 "
46 "
47 ))
48 (should (ert-equal-buffer
49 '(line-tabs)
50 "
51 * a\^@"
52 "
53 B a"
54 ))
55 (should (ert-equal-buffer
56 '(line-tabs)
57 "
58 * b\^@"
59 "
60 B a"
61 ))
62 (should (ert-equal-buffer
63 '(line-tabs)
64 "
65 XV. c\^@"
66 "
67 B a"
68 ))
69 (should (ert-equal-buffer
70 '(line-tabs)
71 "
72 * \^@"
73 "
74 A"
75 ))
76 (should (ert-equal-buffer
77 '(line-tabs)
78 "
79 *\tb\^@"
80 "
81 B a"
82 ))
83 (should (ert-equal-buffer
84 '(line-tabs)
85 "Some para\^@"
86 "
87 A"
88 ))
89 (should (ert-equal-buffer
90 '(line-tabs)
91 " A quoted block\^@"
92 "
93 A"
94 ))
95 (should (ert-equal-buffer
96 '(line-tabs)
97 "
98 :Field: Content on same line\^@"
99 "
100 C b a"
101 ))
102 (should (ert-equal-buffer
103 '(line-tabs)
104 "
105 :Field: \^@"
106 "
107 B a"
108 ))
109 (let ((rst-indent-field 0))
110 (should (ert-equal-buffer
111 '(line-tabs)
112 "
113 :Field: Content on same line\^@"
114 "
115 B a"
116 ))
117 (should (ert-equal-buffer
118 '(line-tabs)
119 "
120 :Field: \^@"
121 "
122 B a"
123 )))
124 (should (ert-equal-buffer
125 '(line-tabs)
126 "
127 .. dir:: Content on same line\^@"
128 "
129 C b a"
130 ))
131 (should (ert-equal-buffer
132 '(line-tabs)
133 "
134 .. dir:: \^@"
135 "
136 B a"
137 ))
138 (should (ert-equal-buffer
139 '(line-tabs)
140 "
141 .. |sub| dir:: Content on same line\^@"
142 "
143 D c b a"
144 ))
145 (should (ert-equal-buffer
146 '(line-tabs)
147 "
148 .. |sub| dir::\^@"
149 "
150 C b a"
151 ))
152 (should (ert-equal-buffer
153 '(line-tabs)
154 "
155 .. [CIT] citation\^@"
156 "
157 C b a"
158 ))
159 (should (ert-equal-buffer
160 '(line-tabs)
161 "
162 .. [#FN] Footnote\^@"
163 "
164 C b a"
165 ))
166 (should (ert-equal-buffer
167 '(line-tabs)
168 "
169 .. [CIT]\^@"
170 "
171 B a"
172 ))
173 (should (ert-equal-buffer
174 '(line-tabs)
175 "
176 Some text::\^@"
177 "
178 B a"
179 ))
180 (should (ert-equal-buffer
181 '(line-tabs)
182 "
183 ::\^@"
184 "
185 B a"
186 ))
187 (should (ert-equal-buffer
188 '(line-tabs)
189 "
190 ::\^@"
191 "
192 B a"
193 ))
194 (should (ert-equal-buffer
195 '(line-tabs)
196 "
197 .. First comment\^@"
198 "
199 B a"
200 ))
201 (should (ert-equal-buffer
202 '(line-tabs)
203 "
204 XV. c::\^@"
205 "
206 C b a"
207 ))
208 (should (ert-equal-buffer
209 '(line-tabs)
210 "
211 :f: val::\^@"
212 "
213 D c b a"
214 ))
215 ))
216
217 (defun compute-tabs ()
218 "Wrapper to call `rst-compute-tabs' creating a readable result."
219 (let ((tabs (rst-compute-tabs (point)))
220 (s "")
221 (cnt 0))
222 (delete-region (point-min) (point-max))
223 (dolist (tab tabs)
224 (setq s (string-insert s tab (+ ?A cnt)))
225 (setq cnt (1+ cnt)))
226 (insert "\n" s)))
227
228 (ert-deftest rst-compute-tabs ()
229 "Tests for `rst-compute-tabs'."
230 (let ((rst-indent-width 2)
231 (rst-indent-field 2)
232 (rst-indent-literal-normal 3)
233 (rst-indent-literal-minimized 2)
234 (rst-indent-comment 3))
235 (should (ert-equal-buffer
236 '(compute-tabs)
237 "\^@"
238 "
239 "
240 ))
241 (should (ert-equal-buffer
242 '(compute-tabs)
243 "
244 * a
245 \^@"
246 "
247 B A"
248 ))
249 (should (ert-equal-buffer
250 '(compute-tabs)
251 "
252 * a
253 * b
254 \^@"
255 "
256 C B A"
257 ))
258 (should (ert-equal-buffer
259 '(compute-tabs)
260 "
261 * a
262 * b
263 XV. c
264 \^@"
265 "
266 D C B A"
267 ))
268 (should (ert-equal-buffer
269 '(compute-tabs)
270 "
271 * a
272 XV. c
273 \^@"
274 "
275 D C B A"
276 ))
277 (should (ert-equal-buffer
278 '(compute-tabs)
279 "
280 *
281 XV. c
282 \^@"
283 "
284 C B A"
285 ))
286 (should (ert-equal-buffer
287 '(compute-tabs)
288 "
289 * a
290 * b
291 XV. c
292 * d
293 \^@"
294 "
295 C B A"
296 ))
297 (should (ert-equal-buffer
298 '(compute-tabs)
299 "
300 * a
301 * b
302 XV. c
303 * d
304 * e
305 \^@"
306 "
307 B A"
308 ))
309 (should (ert-equal-buffer
310 '(compute-tabs)
311 "
312 * a
313 * b
314 XV. c
315 \^@"
316 "
317 D C B A"
318 ))
319 (should (ert-equal-buffer
320 '(compute-tabs)
321 "
322 * a
323 *\tb
324 \^@"
325 "
326 C B A"
327 ))
328 (should (ert-equal-buffer
329 '(compute-tabs)
330 "* a
331 \^@"
332 "
333 B A"
334 ))
335 (should (ert-equal-buffer
336 '(compute-tabs)
337 " * a
338 * b
339 XV. c
340 \^@"
341 "
342 D C B A"
343 ))
344 (should (ert-equal-buffer
345 '(compute-tabs)
346 "Some para
347
348 A quoted block
349
350 Quoting again
351 \^@"
352 "
353 C B A"
354 ))
355 (should (ert-equal-buffer
356 '(compute-tabs)
357 "
358 :Field: Content on same line
359 \^@"
360 "
361 C B A"
362 ))
363 (should (ert-equal-buffer
364 '(compute-tabs)
365 "
366 :Field: Content on same line
367 but continued differently
368 \^@"
369 "
370 D CA B"
371 ))
372 (should (ert-equal-buffer
373 '(compute-tabs)
374 "
375 :Field: Content on same line
376 but continued differently
377 \^@"
378 "
379 D C B A"
380 ))
381 (should (ert-equal-buffer
382 '(compute-tabs)
383 "
384 :Field:
385
386 Content on next line
387 \^@"
388 "
389 C BA"
390 ))
391 (should (ert-equal-buffer
392 '(compute-tabs)
393 "
394 :Field: Starts on same line
395
396 Content on next line
397 \^@"
398 "
399 C A B"
400 ))
401 (should (ert-equal-buffer
402 '(compute-tabs)
403 "
404 .. dir:: Content on same line
405 \^@"
406 "
407 C B A"
408 ))
409 (should (ert-equal-buffer
410 '(compute-tabs)
411 "
412 .. dir::
413
414 Content on next line
415 \^@"
416 "
417 B A"
418 ))
419 (should (ert-equal-buffer
420 '(compute-tabs)
421 "
422 .. dir::
423
424 Content on next line
425 \^@"
426 "
427 C B A"
428 ))
429 (should (ert-equal-buffer
430 '(compute-tabs)
431 "
432 .. dir:: Same
433
434 Content on next line
435 \^@"
436 "
437 D C A B"
438 ))
439 (should (ert-equal-buffer
440 '(compute-tabs)
441 "
442 .. |sub| dir:: Content on same line
443 \^@"
444 "
445 D C B A"
446 ))
447 (should (ert-equal-buffer
448 '(compute-tabs)
449 "
450 .. |sub| dir::
451
452 Content on next line
453 \^@"
454 "
455 C A B"
456 ))
457 (should (ert-equal-buffer
458 '(compute-tabs)
459 "
460 .. |sub| dir::
461
462 Content on next line
463 \^@"
464 "
465 D C A B"
466 ))
467 (should (ert-equal-buffer
468 '(compute-tabs)
469 "
470 .. |sub| dir:: Same
471
472 Content on next line
473 \^@"
474 "
475 E D A C B"
476 ))
477 (should (ert-equal-buffer
478 '(compute-tabs)
479 "
480 .. |sub| dir:: Same
481
482 :par: val
483
484 Content on next line
485 \^@"
486 "
487 E DC A B"
488 ))
489 (should (ert-equal-buffer
490 '(compute-tabs)
491 "
492 .. |sub| dir::
493
494 :par: val
495
496 Content on next line
497 \^@"
498 "
499 C A B"
500 ))
501 (should (ert-equal-buffer
502 '(compute-tabs)
503 "
504 .. |sub| dir:: Same
505
506 :f: val
507
508 Content on next line
509 \^@"
510 "
511 E DAC B"
512 ))
513 (should (ert-equal-buffer
514 '(compute-tabs)
515 "
516 .. |sub| dir:: Same
517
518 :f: val
519
520 Content on next line
521 \^@"
522 "
523 D A C B"
524 ))
525 (should (ert-equal-buffer
526 '(compute-tabs)
527 "
528 .. |sub| dir:: Same
529
530 :f: val
531
532 * Item
533 \^@"
534 "
535 C B A"
536 ))
537 (should (ert-equal-buffer
538 '(compute-tabs)
539 "
540 .. |sub| dir:: Same
541
542 :f: val
543
544 * Item
545
546 1. Enumerated
547 \^@"
548 "
549 D C B A"
550 ))
551 (should (ert-equal-buffer
552 '(compute-tabs)
553 "
554 .. [CIT] citation
555 \^@"
556 "
557 C B A"
558 ))
559 (should (ert-equal-buffer
560 '(compute-tabs)
561 "
562 .. [#FN] Footnote
563 \^@"
564 "
565 C B A"
566 ))
567 (should (ert-equal-buffer
568 '(compute-tabs)
569 "
570 .. [CIT]
571
572 citation
573 \^@"
574 "
575 B A"
576 ))
577 (should (ert-equal-buffer
578 '(compute-tabs)
579 "
580 .. [CIT]
581
582 citation
583 \^@"
584 "
585 C B A"
586 ))
587 (should (ert-equal-buffer
588 '(compute-tabs)
589 "
590 .. [CIT]
591
592 citation
593
594 .. |sub| dir:: Same
595
596 :f: val
597
598 * Item
599
600 1. Enumerated
601 \^@"
602 "
603 E D C B A"
604 ))
605 (should (ert-equal-buffer
606 '(compute-tabs)
607 "
608 Some text::
609 \^@"
610 "
611 B A"
612 ))
613 (should (ert-equal-buffer
614 '(compute-tabs)
615 "
616 No text
617
618 ::
619 \^@"
620 "
621 B A"
622 ))
623 (should (ert-equal-buffer
624 '(compute-tabs)
625 "
626 No text
627
628 ::
629 \^@"
630 "
631 C B A"
632 ))
633 (should (ert-equal-buffer
634 '(compute-tabs)
635 "
636 .. [CIT]
637
638 citation
639
640 .. |sub| dir:: Same
641
642 :f: val
643
644 No text
645
646 ::
647 \^@"
648 "
649 E D C B A"
650 ))
651 (should (ert-equal-buffer
652 '(compute-tabs)
653 "
654 .. First comment
655 \^@"
656 "
657 B A"
658 ))
659 (should (ert-equal-buffer
660 '(compute-tabs)
661 "
662 * a
663 XV. c::
664 \^@"
665 "
666 E D C B A"
667 ))
668 (should (ert-equal-buffer
669 '(compute-tabs)
670 "
671 .. [CIT]
672
673 citation
674
675 .. |sub| dir:: Same
676
677 :f: val::
678 \^@"
679 "
680 F E D C B A"
681 ))
682 ))
683
684 (ert-deftest rst-shift-region-right ()
685 "Tests for `rst-shift-region' to the right."
686 (let ((rst-indent-width 2)) ; Set relevant variables
687 (should (ert-equal-buffer
688 '(rst-shift-region 1)
689 "
690 \^@a
691 \^?"
692 "
693 \^@ a
694 \^?"
695 t))
696 (should (ert-equal-buffer
697 '(rst-shift-region 1)
698 "
699 \^@ a
700 \^?"
701 "
702 \^@ a
703 \^?"
704 t))
705 (should (ert-equal-buffer
706 '(rst-shift-region 1)
707 "\^@
708 a
709 b
710 \^?"
711 "\^@
712 a
713 b
714 \^?"
715 t))
716 (should (ert-equal-buffer
717 '(rst-shift-region 1)
718 "* x
719 \^@
720 a
721 b
722 \^?"
723 "* x
724 \^@
725 a
726 b
727 \^?"
728 t))
729 (should (ert-equal-buffer
730 '(rst-shift-region 1)
731 "* x
732 \^@
733 a
734 b
735 \^?"
736 "* x
737 \^@
738 a
739 b
740 \^?"
741 t))
742 (should (ert-equal-buffer
743 '(rst-shift-region 1)
744 "* x
745 * y
746 \^@
747 a
748 b
749 \^?"
750 "* x
751 * y
752 \^@
753 a
754 b
755 \^?"
756 t))
757 (should (ert-equal-buffer
758 '(rst-shift-region 1)
759 "* x
760 \^?
761 a
762 b
763 \^@"
764 "* x
765 \^?
766 a
767 b
768 \^@"
769 t))
770 (should (ert-equal-buffer
771 '(rst-shift-region 2)
772 "* x
773 \^?
774 a
775 b
776 \^@"
777 "* x
778 \^?
779 a
780 b
781 \^@"
782 t))
783 ))
784
785 (ert-deftest rst-shift-region-left ()
786 "Tests for `rst-shift-region' to the left."
787 (let ((rst-indent-width 2)) ; Set relevant variables
788 (should (ert-equal-buffer
789 '(rst-shift-region -1)
790 "* x
791 \^@
792 a
793 b
794 \^?"
795 "* x
796 \^@
797 a
798 b
799 \^?"
800 t))
801 (should (ert-equal-buffer
802 '(rst-shift-region -1)
803 "
804 \^@ a
805 \^?"
806 "
807 \^@a
808 \^?"
809 t))
810 (should (ert-equal-buffer
811 '(rst-shift-region -1)
812 "
813 \^@ a
814 \^?"
815 "
816 \^@ a
817 \^?"
818 t))
819 (should (ert-equal-buffer
820 '(rst-shift-region -1)
821 "\^@
822 a
823 b
824 \^?"
825 "\^@
826 a
827 b
828 \^?"
829 t))
830 (should (ert-equal-buffer
831 '(rst-shift-region -1)
832 "* x
833 \^@
834 a
835 b
836 \^?"
837 "* x
838 \^@
839 a
840 b
841 \^?"
842 t))
843 (should (ert-equal-buffer
844 '(rst-shift-region -1)
845 "* x
846 * y
847 \^@
848 a
849 b
850 \^?"
851 "* x
852 * y
853 \^@
854 a
855 b
856 \^?"
857 t))
858 (should (ert-equal-buffer
859 '(rst-shift-region -1)
860 "* x
861 \^?
862 a
863 b
864 \^@"
865 "* x
866 \^?
867 a
868 b
869 \^@"
870 t))
871 (should (ert-equal-buffer
872 '(rst-shift-region 0)
873 "* x
874 * y
875 \^@
876 a
877 b
878 \^?"
879 "* x
880 * y
881 \^@
882 a
883 b
884 \^?"
885 t))
886 (should (ert-equal-buffer
887 '(rst-shift-region -1)
888 "\^@* x
889 * y
890
891 a
892 b
893 \^?"
894 "\^@* x
895 * y
896
897 a
898 b
899 \^?"
900 t))
901 (should (ert-equal-buffer
902 '(rst-shift-region -2)
903 "* x
904 * y
905 \^@
906 a
907 b
908 \^?"
909 "* x
910 * y
911 \^@
912 a
913 b
914 \^?"
915 t))
916 ))