Debian Codegraph @

tools/editors/emacs/tests/comment.el

raw
1 ;; Tests for comment handling -*- lexical-binding: t -*-
2
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
6
7 (ert-deftest comment-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
11 )
12
13 (defun cmnt-insert ()
14 "Wrapper to insert comment via `comment-dwim'.
15 Must be called on a line containing at most whitespace."
16 (let ((fc fill-column))
17 (rst-mode)
18 (setq fill-column fc)
19 (comment-dwim nil)))
20
21 (ert-deftest comment-insert ()
22 "Tests for inserting a comment."
23 (let ((rst-indent-width 2)
24 (rst-indent-comment 3)
25 (fill-column 20))
26 (should (ert-equal-buffer
27 '(cmnt-insert)
28 "\^@"
29 ".. \^@"
30 ))
31 (should (ert-equal-buffer
32 '(cmnt-insert)
33 "
34 \^@"
35 "
36 .. \^@"
37 ))
38 (should (ert-equal-buffer
39 '(cmnt-insert)
40 "
41 * bla
42
43 \^@"
44 "
45 * bla
46
47 .. \^@"
48 ))
49 (should (ert-equal-buffer
50 '(cmnt-insert)
51 "
52 :Field: Content
53
54 \^@"
55 "
56 :Field: Content
57
58 .. \^@"
59 ))
60 ))
61
62 (defun cmnt-indent (continue)
63 "Wrapper for `comment-indent'."
64 (let ((fc fill-column))
65 (rst-mode)
66 (setq fill-column fc)
67 (comment-indent continue)))
68
69 (ert-deftest comment-indent ()
70 "Tests for `comment-indent'."
71 (let ((rst-indent-width 2)
72 (rst-indent-comment 3)
73 (fill-column 20))
74 (should (ert-equal-buffer
75 '(cmnt-indent nil)
76 "\^@"
77 ".. \^@"
78 ))
79 (should (ert-equal-buffer
80 '(cmnt-indent nil)
81 "
82 \^@"
83 "
84 .. \^@"
85 ))
86 (should (ert-equal-buffer
87 '(cmnt-indent nil)
88 ".. comment\^@"
89 ".. \^@comment"
90 ))
91 (should (ert-equal-buffer
92 '(cmnt-indent nil)
93 "
94 * bla
95
96 .. comment\^@"
97 "
98 * bla
99
100 .. \^@comment"
101 ))
102 (should (ert-equal-buffer
103 '(cmnt-indent nil)
104 "
105 :Field: Content
106
107 \^@"
108 "
109 :Field: Content
110
111 .. \^@"
112 ))
113 (should (ert-equal-buffer
114 '(cmnt-indent nil)
115 "
116 :Field: Content
117
118 .. comment\^@"
119 "
120 :Field: Content
121
122 .. \^@comment"
123 ))
124 ))
125
126 (defun uncmnt-region ()
127 "Wrapper for `uncomment-region'."
128 (let ((fc fill-column))
129 (rst-mode)
130 (setq fill-column fc)
131 (call-interactively 'uncomment-region)))
132
133 (ert-deftest uncomment-region ()
134 "Tests for `uncomment-region'."
135 (let ((rst-indent-width 2)
136 (rst-indent-comment 3)
137 (fill-column 20))
138 (should (ert-equal-buffer
139 '(uncmnt-region)
140 "\^?..
141 com\^@ment"
142 "\^?com\^@ment"
143 ))
144 (should (ert-equal-buffer
145 '(uncmnt-region)
146 "\^?..
147 com\^@ment
148
149 bla
150 "
151 "\^?com\^@ment
152
153 bla
154 "
155 ))
156 (should (ert-equal-buffer
157 '(uncmnt-region)
158 "\^?..
159 comment
160
161 bl\^@a
162 "
163 "\^?comment
164
165 bl\^@a
166 "
167 ))
168 ))
169
170 (defun cmnt-region ()
171 "Wrapper for `comment-region'."
172 (let ((fc fill-column))
173 (rst-mode)
174 (setq fill-column fc)
175 (call-interactively 'comment-region)))
176
177 (ert-deftest comment-region ()
178 "Tests for `comment-region'."
179 (let ((rst-indent-width 2)
180 (rst-indent-comment 3)
181 (fill-column 20))
182 (should (ert-equal-buffer
183 '(cmnt-region)
184 "\^?com\^@ment"
185 "\^?..
186 com\^@ment"
187 ))
188 (should (ert-equal-buffer
189 '(cmnt-region)
190 "\^?com\^@ment
191
192 bla
193 "
194 "\^?..
195 com\^@ment
196
197 bla
198 "
199 ))
200 (should (ert-equal-buffer
201 '(cmnt-region)
202 "\^?comment
203
204 bl\^@a
205 "
206 "\^?..
207 comment
208
209 bl\^@a
210 "
211 ))
212 ))
213
214 ;; comment-kill could be tested but since there are no suffix comments in
215 ;; reStructuredText this makes little sense