Debian Codegraph @

tools/editors/emacs/tests/fill.el

raw
1 ;; Tests for functions around filling -*- lexical-binding: t -*-
2
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
6
7 (ert-deftest fill-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
11 )
12
13 (defun auto-fill ()
14 "Wrapper to do auto fill."
15 (let ((fc fill-column))
16 (rst-mode)
17 (setq fill-column fc)
18 (auto-fill-mode 1)
19 (funcall auto-fill-function)))
20
21 (ert-deftest auto-fill ()
22 "Tests for auto fill."
23 (let ((rst-indent-width 2)
24 (rst-indent-field 2)
25 (rst-indent-literal-normal 3)
26 (rst-indent-literal-minimized 2)
27 (rst-indent-comment 3)
28 (fill-column 20))
29 (should (ert-equal-buffer
30 '(auto-fill)
31 "
32 * This is a test with a fill column of 20\^@"
33 "
34 * This is a test
35 with a fill column
36 of 20\^@"
37 ))
38 (should (ert-equal-buffer
39 '(auto-fill)
40 "
41 * This is a test
42 with a fill column of 20\^@"
43 "
44 * This is a test
45 with a fill column
46 of 20\^@"
47 ))
48 (should (ert-equal-buffer
49 '(auto-fill)
50 "
51 :Field: Does this work for fields?\^@"
52 "
53 :Field: Does this
54 work for
55 fields?\^@"
56 ))
57 (should (ert-equal-buffer
58 '(auto-fill)
59 "
60 :Field: Does this
61 work for fields?\^@"
62 "
63 :Field: Does this
64 work for
65 fields?\^@"
66 ))
67 (should (ert-equal-buffer
68 '(auto-fill)
69 "
70 .. dir:: Yes, quite fine\^@"
71 "
72 .. dir:: Yes, quite
73 fine\^@"
74 ))
75 (should (ert-equal-buffer
76 '(auto-fill)
77 "
78 .. dir:: Yes, quite fine\^@
79 :f: Field"
80 "
81 .. dir:: Yes, quite
82 fine\^@
83 :f: Field"
84 ))
85 (should (ert-equal-buffer
86 '(auto-fill)
87 "
88 .. |s| r:: Dir ectives had problems\^@"
89 "
90 .. |s| r:: Dir
91 ectives
92 had
93 problems\^@"
94 ))
95 (should (ert-equal-buffer
96 '(auto-fill)
97 "
98 .. |s| r:: Dir
99 ectives
100 had problems\^@"
101 "
102 .. |s| r:: Dir
103 ectives
104 had
105 problems\^@"
106 ))
107 (should (ert-equal-buffer
108 '(auto-fill)
109 "
110 .. [CIT] X cit is citations are also filled\^@"
111 "
112 .. [CIT] X cit is
113 citations
114 are also
115 filled\^@"
116 ))
117 (should (ert-equal-buffer
118 '(auto-fill)
119 "
120 .. [CIT] X cit is
121 citations
122 are also filled\^@"
123 "
124 .. [CIT] X cit is
125 citations
126 are also
127 filled\^@"
128 ))
129 (should (ert-equal-buffer
130 '(auto-fill)
131 "
132 .. Comments should also fill nicely\^@"
133 "
134 .. Comments should
135 also fill nicely\^@"
136 ))
137 (should (ert-equal-buffer
138 '(auto-fill)
139 "
140 Normal text should also fill as expected\^@"
141 "
142 Normal text should
143 also fill as
144 expected\^@"
145 ))
146 (should (ert-equal-buffer
147 '(auto-fill)
148 "
149 Normal text should also fill as expected\^@"
150 "
151 Normal text should
152 also fill as
153 expected\^@"
154 ))
155 (should (ert-equal-buffer
156 '(auto-fill)
157 "
158 Normal text should also fill \^@as expected"
159 "
160 Normal text should
161 also fill \^@as expected"
162 ))
163 ))
164
165 (defun explicit-fill ()
166 "Wrapper for `fill-paragraph'."
167 (let ((fc fill-column))
168 (rst-mode)
169 (setq fill-column fc)
170 (fill-paragraph)
171 (untabify (point-min) (point-max))))
172
173 (ert-deftest fill-paragraph ()
174 "Tests for `fill-paragraph'."
175 (let ((rst-indent-width 2)
176 (rst-indent-field 2)
177 (rst-indent-literal-normal 3)
178 (rst-indent-literal-minimized 2)
179 (rst-indent-comment 3)
180 (fill-column 20))
181 (should (ert-equal-buffer
182 '(explicit-fill)
183 "
184 * This is a test with a fill column of 20\^@
185 "
186 "
187 * This is a test
188 with a fill column
189 of 20\^@
190 "
191 ))
192 (should (ert-equal-buffer
193 '(explicit-fill)
194 "
195 * This is a test \^@with a fill column
196 of 20
197 "
198 "
199 * This is a test
200 \^@with a fill column
201 of 20
202 "
203 ))
204 (should (ert-equal-buffer
205 '(explicit-fill)
206 "
207 :Field: Does this work for fields?\^@
208 "
209 "
210 :Field: Does this
211 work for
212 fields?\^@
213 "
214 ))
215 (should (ert-equal-buffer
216 '(explicit-fill)
217 "
218 :Field: Does this work\^@ for
219 fields?
220 "
221 "
222 :Field: Does this
223 work\^@ for
224 fields?
225 "
226 ))
227 (should (ert-equal-buffer
228 '(explicit-fill)
229 "
230 .. dir:: Yes, quite fine\^@
231 "
232 "
233 .. dir:: Yes, quite
234 fine\^@
235 "
236 ))
237 (should (ert-equal-buffer
238 '(explicit-fill)
239 "
240 \^@.. dir:: Yes, quite
241 fine
242 "
243 "
244 \^@.. dir:: Yes, quite
245 fine
246 "
247 ))
248 (should (ert-equal-buffer
249 '(explicit-fill)
250 "
251 .. dir:: Yes, quite fine\^@
252 :f: Field
253 "
254 "
255 .. dir:: Yes, quite
256 fine\^@
257 :f: Field
258 "
259 ))
260 (should (ert-equal-buffer
261 '(explicit-fill)
262 "
263 .. [CIT] X cit is citations are also filled\^@
264 "
265 "
266 .. [CIT] X cit is
267 citations
268 are also
269 filled\^@
270 "
271 ))
272 (should (ert-equal-buffer
273 '(explicit-fill)
274 "
275 .. [CIT] X cit is
276 citations are also filled\^@
277 "
278 "
279 .. [CIT] X cit is
280 citations are
281 also filled\^@
282 "
283 ))
284 (should (ert-equal-buffer
285 '(explicit-fill)
286 "
287 .. [CIT] X cit is
288 citations are also filled\^@
289 "
290 "
291 .. [CIT] X cit is
292 citations are
293 also filled\^@
294 "
295 ))
296 (should (ert-equal-buffer
297 '(explicit-fill)
298 "
299 .. |s| r:: Dir ectives had problems\^@
300 "
301 "
302 .. |s| r:: Dir
303 ectives
304 had
305 problems\^@
306 "
307 ))
308 (should (ert-equal-buffer
309 '(explicit-fill)
310 "
311 \^@.. |s| r:: Dir ectives had problems
312 "
313 "
314 \^@.. |s| r:: Dir
315 ectives
316 had
317 problems
318 "
319 ))
320 (should (ert-equal-buffer
321 '(explicit-fill)
322 "
323 .. |s| r:: Dir
324 ectives had problems\^@
325 "
326 "
327 .. |s| r:: Dir
328 ectives had
329 problems\^@
330 "
331 ))
332 (should (ert-equal-buffer
333 '(explicit-fill)
334 "
335 Normal \^@text should also fill as expected
336 "
337 "
338 Normal \^@text should
339 also fill as
340 expected
341 "
342 ))
343 (should (ert-equal-buffer
344 '(explicit-fill)
345 "
346 \^@Normal text should also fill as expected
347 "
348 "
349 \^@Normal text should
350 also fill as
351 expected
352 "
353 ))
354 (should (ert-equal-buffer
355 '(explicit-fill)
356 "
357 Normal text should also fill as expected\^@
358 "
359 "
360 Normal text should
361 also fill as
362 expected\^@
363 "
364 ))
365 (should (ert-equal-buffer
366 '(explicit-fill)
367 "
368 Normal text should also fill as expected
369
370 Normal text should also fill as expected\^@
371 "
372 "
373 Normal text should also fill as expected
374
375 Normal text should
376 also fill as
377 expected\^@
378 "
379 ))
380 (should (ert-equal-buffer
381 '(explicit-fill)
382 "
383 \^@Normal text should
384 also fill as
385 expected
386 "
387 "
388 \^@Normal text should
389 also fill as
390 expected
391 "
392 ))
393 ))
394
395 (ert-deftest fill-paragraph-fixme ()
396 "Tests for `fill-paragraph'."
397 :expected-result :failed
398 (let ((rst-indent-width 2)
399 (rst-indent-field 2)
400 (rst-indent-literal-normal 3)
401 (rst-indent-literal-minimized 2)
402 (rst-indent-comment 3)
403 (fill-column 20))
404 (should (ert-equal-buffer
405 '(explicit-fill)
406 "
407 \^@Normal text should
408 also fill as
409 expected
410 "
411 "
412 \^@Normal text should
413 also fill as
414 expected
415 "
416 ))
417 ))
418
419 (defun explicit-fill-region ()
420 "Wrapper for `fill-region'."
421 (let ((fc fill-column))
422 (rst-mode)
423 (setq fill-column fc)
424 (call-interactively 'fill-region)
425 (untabify (point-min) (point-max))))
426
427 (ert-deftest fill-region ()
428 "Tests for `fill-region'."
429 (let ((rst-indent-width 2)
430 (rst-indent-field 2)
431 (rst-indent-literal-normal 3)
432 (rst-indent-literal-minimized 2)
433 (rst-indent-comment 3)
434 (fill-column 20))
435 (should (ert-equal-buffer
436 '(explicit-fill-region)
437 "\^@
438 * This is a test with a fill column of 20
439
440 * This is a test with a fill column
441 of 20
442
443 :Field: Does this work for fields?
444
445 :Field: Does this work for
446 fields?
447
448 .. dir:: Yes, quite fine
449
450 .. dir:: Yes, quite
451 fine
452
453 .. dir:: Yes, quite fine
454 :f: Field for a directive
455
456 .. [CIT] X cit is citations are also filled
457
458 .. |s| r:: Dir ectives had problems
459
460 .. |s| r:: Dir ectives had problems
461
462 Normal text should also fill as expected
463
464 Normal text should also fill as expected
465 \^?"
466 "\^@
467 * This is a test
468 with a fill column
469 of 20
470
471 * This is a test
472 with a fill column
473 of 20
474
475 :Field: Does this
476 work for
477 fields?
478
479 :Field: Does this
480 work for
481 fields?
482
483 .. dir:: Yes, quite
484 fine
485
486 .. dir:: Yes, quite
487 fine
488
489 .. dir:: Yes, quite
490 fine
491 :f: Field for a
492 directive
493
494 .. [CIT] X cit is
495 citations
496 are also
497 filled
498
499 .. |s| r:: Dir
500 ectives
501 had
502 problems
503
504 .. |s| r:: Dir
505 ectives
506 had
507 problems
508
509 Normal text should
510 also fill as
511 expected
512
513 Normal text should
514 also fill as
515 expected
516 \^?"
517 ))
518 (should (ert-equal-buffer
519 '(explicit-fill-region)
520 "\^@
521 * This is a test with a fill column of 20
522 * This is a test with a fill column
523 of 20
524 :Field: Does this work for fields?
525 :Field: Does this work for
526 fields?
527 .. dir:: Yes, quite fine
528 .. dir:: Yes, quite
529 fine
530 .. dir:: Yes, quite fine
531 :f: Field for a directive
532 .. [CIT] X cit is citations are also filled
533 .. |s| r:: Dir ectives had problems
534 .. |s| r:: Dir ectives had problems
535
536 Normal text should also fill as expected
537
538 Normal text should also fill as expected
539 \^?"
540 "\^@
541 * This is a test
542 with a fill column
543 of 20
544 * This is a test
545 with a fill column
546 of 20
547 :Field: Does this
548 work for
549 fields?
550 :Field: Does this
551 work for
552 fields?
553 .. dir:: Yes, quite
554 fine
555 .. dir:: Yes, quite
556 fine
557 .. dir:: Yes, quite
558 fine
559 :f: Field for a
560 directive
561 .. [CIT] X cit is
562 citations
563 are also
564 filled
565 .. |s| r:: Dir
566 ectives
567 had
568 problems
569 .. |s| r:: Dir
570 ectives
571 had
572 problems
573
574 Normal text should
575 also fill as
576 expected
577
578 Normal text should
579 also fill as
580 expected
581 \^?"
582 ))
583 ))