1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
;;; test-lint-org.el --- ERT tests for lint-org.el -*- lexical-binding: t; -*-
;;
;; Run from the repo root:
;; emacs --batch -q -L .ai/scripts -l ert \
;; -l .ai/scripts/tests/test-lint-org.el \
;; -f ert-run-tests-batch-and-exit
;;
;; or from .ai/scripts/tests/:
;; emacs --batch -q -L .. -l ert -l test-lint-org.el \
;; -f ert-run-tests-batch-and-exit
;;
;; Covers: mechanical auto-fixers (item-number, missing-language-in-src-block,
;; misplaced-planning-info, markdown-bold case of misplaced-heading) and
;; judgment-item emission (link-to-local-file, invalid-fuzzy-link,
;; verbatim-asterisk case of misplaced-heading, suspicious-language-in-src-block,
;; unhandled checkers).
(require 'ert)
(require 'cl-lib)
(defconst lo-test--dir
(file-name-directory (or load-file-name buffer-file-name default-directory))
"Directory of this test file, captured at load time.")
(add-to-list 'load-path (expand-file-name ".." lo-test--dir))
(require 'lint-org)
;;; ---------------------------------------------------------------------------
;;; Harness
(defun lo-test--reset (&optional check followups-file)
(setq lo-fixes 0 lo-issues nil
lo-check-only (and check t)
lo-current-file nil
lo-followups-file followups-file))
(defun lo-test--drop-buffer (file)
(let ((buf (find-buffer-visiting file)))
(when buf
(with-current-buffer buf (set-buffer-modified-p nil))
(kill-buffer buf))))
(defun lo-test--run (content &optional runs check)
"Write CONTENT to a temp .org file, run lint-org RUNS times (default 1).
Return a plist :result (final file contents) :fixes (last run)
:issues (last run). CHECK non-nil ⇒ --check (preview, no writes)."
(let ((file (make-temp-file "lo-test-" nil ".org"))
last-fixes last-issues)
(unwind-protect
(progn
(with-temp-file file (insert content))
(dotimes (_ (or runs 1))
(lo-test--reset check)
(lo-process-file file)
(setq last-fixes lo-fixes last-issues lo-issues)
(lo-test--drop-buffer file))
(list :result (with-temp-buffer (insert-file-contents file)
(buffer-string))
:fixes last-fixes
:issues last-issues))
(lo-test--drop-buffer file)
(delete-file file))))
(defun lo-test--judgments (issues)
"Return judgment items from ISSUES, in document order."
(reverse
(cl-remove-if-not (lambda (i) (eq (plist-get i :kind) 'judgment)) issues)))
(defun lo-test--mechanical (issues)
"Return mechanical-fixed items from ISSUES, in document order."
(reverse
(cl-remove-if-not (lambda (i) (eq (plist-get i :kind) 'mechanical-fixed))
issues)))
(defun lo-test--checkers (items)
(mapcar (lambda (i) (plist-get i :checker)) items))
(defun lo-test--has (string substring)
(and (string-match-p (regexp-quote substring) string) t))
;;; ---------------------------------------------------------------------------
;;; Fixtures
;; item-number — bullets 4. and 5. where org expects items 3 and 4.
(defconst lo-test--item-number "\
* Heading
1. first
2. second
4. out-of-order
5. and another
")
(defconst lo-test--item-number-already-tagged "\
* Heading
1. first
2. second
4. [@4] already tagged
5. [@5] also already tagged
")
;; missing-language-in-src-block — bare #+begin_src ... #+end_src.
(defconst lo-test--bare-src "\
* Heading
#+begin_src
some prose without a language
#+end_src
")
;; A src block with a language slug doesn't trip the missing-language checker.
(defconst lo-test--src-with-language "\
* Heading
#+begin_src text
some prose with a language
#+end_src
")
;; misplaced-planning-info — CLOSED and DEADLINE on separate lines.
(defconst lo-test--planning-split "\
* DONE Task
CLOSED: [2026-05-14]
DEADLINE: <2026-05-20>
Body.
")
;; misplaced-heading, markdown-bold case — **X.** at start of body paragraph.
(defconst lo-test--md-bold "\
* Heading
**Important.** Body continues here.
More body.
")
;; misplaced-heading, verbatim-asterisk case — =*** Foo= inside body prose.
(defconst lo-test--verbatim-asterisk "\
* Heading
A reference to =*** Foo= inside body prose.
")
;; link-to-local-file — broken file: link.
(defconst lo-test--broken-file-link "\
* Heading
See [[file:/tmp/does-not-exist-lo-test.org][a link]].
")
;; invalid-fuzzy-link — link to a heading that doesn't exist in this file.
(defconst lo-test--broken-fuzzy-link "\
* Heading
See [[*Nonexistent Heading]].
")
;; suspicious-language-in-src-block — #+begin_src markdown.
(defconst lo-test--suspicious-language "\
* Heading
#+begin_src markdown
content
#+end_src
")
;; cj-comment annotation block — Craig's convention #+begin_src cj: comment.
;; org-lint flags the language (cj:) as unknown and the comment header arg as
;; both missing-colon and empty-value. All three are false positives.
(defconst lo-test--cj-comment-block "\
* Heading
#+begin_src cj: comment
my annotation text
#+end_src
")
;; cj-comment block alongside a real suspicious-language warning — verifies
;; the cj suppression doesn't leak into other src blocks in the same file.
(defconst lo-test--cj-comment-with-real-warning "\
* Heading
#+begin_src cj: comment
my annotation
#+end_src
#+begin_src markdown
real suspicious-language warning here
#+end_src
")
;; Mixed fixture — each category once.
(defconst lo-test--mixed "\
* Mixed
1. first
2. second
4. out-of-order
** DONE Task
CLOSED: [2026-05-14]
DEADLINE: <2026-05-20>
**Important.** Body.
A reference to =*** Foo= inside body.
See [[file:/tmp/does-not-exist-lo-test.org][a link]].
See [[*Nonexistent Heading]].
#+begin_src
prose
#+end_src
#+begin_src markdown
content
#+end_src
")
;;; ---------------------------------------------------------------------------
;;; item-number tests
(ert-deftest lo-item-number-adds-counter-directive ()
(let* ((out (lo-test--run lo-test--item-number))
(res (plist-get out :result)))
(should (>= (plist-get out :fixes) 1))
(should (lo-test--has res "4. [@4] out-of-order"))
(should (lo-test--has res "5. [@5] and another"))
;; well-formed bullets above stay alone
(should (lo-test--has res "1. first"))
(should (lo-test--has res "2. second"))))
(ert-deftest lo-item-number-skips-already-tagged ()
(let ((out (lo-test--run lo-test--item-number-already-tagged)))
(should (= 0 (plist-get out :fixes)))
(should (equal lo-test--item-number-already-tagged (plist-get out :result)))))
(ert-deftest lo-item-number-is-idempotent ()
(let ((once (plist-get (lo-test--run lo-test--item-number 1) :result))
(twice (plist-get (lo-test--run lo-test--item-number 2) :result)))
(should (equal once twice))))
;;; ---------------------------------------------------------------------------
;;; missing-language-in-src-block tests
(ert-deftest lo-bare-src-becomes-example ()
(let* ((out (lo-test--run lo-test--bare-src))
(res (plist-get out :result)))
(should (= 1 (plist-get out :fixes)))
(should (lo-test--has res "#+begin_example"))
(should (lo-test--has res "#+end_example"))
(should-not (lo-test--has res "#+begin_src\n"))
(should-not (lo-test--has res "#+end_src"))
(should (lo-test--has res "some prose without a language"))))
(ert-deftest lo-src-with-language-stays ()
(let ((out (lo-test--run lo-test--src-with-language)))
(should (= 0 (plist-get out :fixes)))
(should (equal lo-test--src-with-language (plist-get out :result)))))
(ert-deftest lo-bare-src-is-idempotent ()
(let ((once (plist-get (lo-test--run lo-test--bare-src 1) :result))
(twice (plist-get (lo-test--run lo-test--bare-src 2) :result)))
(should (equal once twice))))
;;; ---------------------------------------------------------------------------
;;; misplaced-planning-info tests
(ert-deftest lo-planning-info-merges-onto-one-line ()
(let* ((out (lo-test--run lo-test--planning-split))
(res (plist-get out :result)))
(should (>= (plist-get out :fixes) 1))
;; Both keywords on the same line, exactly one blank space between values.
(should (string-match-p
"CLOSED: \\[2026-05-14\\][^\n]*DEADLINE: <2026-05-20"
res))
;; No stray DEADLINE: line on its own.
(should-not (string-match-p "^DEADLINE: <2026-05-20" res))))
(ert-deftest lo-planning-info-is-idempotent ()
(let ((once (plist-get (lo-test--run lo-test--planning-split 1) :result))
(twice (plist-get (lo-test--run lo-test--planning-split 2) :result)))
(should (equal once twice))))
;;; ---------------------------------------------------------------------------
;;; misplaced-heading tests
(ert-deftest lo-markdown-bold-becomes-single-asterisk ()
(let* ((out (lo-test--run lo-test--md-bold))
(res (plist-get out :result)))
(should (= 1 (plist-get out :fixes)))
(should (lo-test--has res "*Important.* Body continues here."))
(should-not (lo-test--has res "**Important.**"))))
(ert-deftest lo-markdown-bold-is-idempotent ()
(let ((once (plist-get (lo-test--run lo-test--md-bold 1) :result))
(twice (plist-get (lo-test--run lo-test--md-bold 2) :result)))
(should (equal once twice))))
(ert-deftest lo-verbatim-asterisk-is-suppressed ()
(let* ((out (lo-test--run lo-test--verbatim-asterisk))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues))))
;; File untouched.
(should (equal lo-test--verbatim-asterisk res))
(should (= 0 (plist-get out :fixes)))
;; Verbatim =*** Foo= inside prose is never a real misplaced heading, so it
;; is suppressed — no judgment emitted (compare the cj-comment suppression).
(should-not (member 'misplaced-heading (lo-test--checkers judgments)))))
;;; ---------------------------------------------------------------------------
;;; Judgment-category emission tests
(ert-deftest lo-broken-file-link-is-judgment ()
(let* ((out (lo-test--run lo-test--broken-file-link))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues))))
(should (equal lo-test--broken-file-link res))
(should (= 0 (plist-get out :fixes)))
(should (member 'link-to-local-file (lo-test--checkers judgments)))))
(ert-deftest lo-broken-fuzzy-link-is-judgment ()
(let* ((out (lo-test--run lo-test--broken-fuzzy-link))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues))))
(should (equal lo-test--broken-fuzzy-link res))
(should (= 0 (plist-get out :fixes)))
(should (member 'invalid-fuzzy-link (lo-test--checkers judgments)))))
(ert-deftest lo-suspicious-language-is-judgment ()
(let* ((out (lo-test--run lo-test--suspicious-language))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues))))
(should (equal lo-test--suspicious-language res))
(should (= 0 (plist-get out :fixes)))
(should (member 'suspicious-language-in-src-block
(lo-test--checkers judgments)))))
;; mu4e:msgid: links are registered by mu4e at runtime in a live Emacs; in
;; batch, org-lint parses them as fuzzy heading refs and reports "Unknown
;; fuzzy location" — a false positive (home's todo.org, 2026-06-11).
;; lint-org pre-registers known runtime link types so they parse as links.
(defconst lo-test--runtime-link "\
* Heading
See [[mu4e:msgid:abc123@mail.example.com][the thread with Jonathan]].
")
(ert-deftest lo-runtime-link-type-is-not-flagged ()
(let* ((out (lo-test--run lo-test--runtime-link))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues))))
(should (equal lo-test--runtime-link res))
(should (= 0 (plist-get out :fixes)))
(should-not (member 'invalid-fuzzy-link (lo-test--checkers judgments)))))
;;; ---------------------------------------------------------------------------
;;; cj-comment block — Craig's annotation convention is silently suppressed
(ert-deftest lo-cj-comment-block-emits-no-judgments ()
"Normal: a `#+begin_src cj: comment ...' block must not trigger the three
false-positive warnings org-lint emits for it (unknown language, empty
header-arg value, missing colon in header arg)."
(let* ((out (lo-test--run lo-test--cj-comment-block))
(res (plist-get out :result))
(judgments (lo-test--judgments (plist-get out :issues)))
(checkers (lo-test--checkers judgments)))
;; File untouched, no fixes applied.
(should (equal lo-test--cj-comment-block res))
(should (= 0 (plist-get out :fixes)))
;; None of the three false-positive checkers fired.
(should-not (member 'suspicious-language-in-src-block checkers))
(should-not (member 'empty-header-argument checkers))
(should-not (member 'wrong-header-argument checkers))))
(ert-deftest lo-cj-comment-suppression-does-not-mask-real-warnings ()
"Boundary: the cj-comment suppression is scoped to cj-comment block openers
only — a regular `#+begin_src markdown' in the same file still emits its
suspicious-language judgment."
(let* ((out (lo-test--run lo-test--cj-comment-with-real-warning))
(judgments (lo-test--judgments (plist-get out :issues)))
(suspicious (cl-count 'suspicious-language-in-src-block
(lo-test--checkers judgments))))
;; Exactly one suspicious-language judgment — from the markdown block,
;; not the cj-comment block.
(should (= 1 suspicious))))
;;; ---------------------------------------------------------------------------
;;; --check mode
(ert-deftest lo-check-mode-does-not-modify-file ()
(let* ((out (lo-test--run lo-test--mixed 1 t))
(res (plist-get out :result)))
(should (equal lo-test--mixed res))))
(ert-deftest lo-check-mode-reports-mechanical-and-judgment ()
(let* ((out (lo-test--run lo-test--mixed 1 t))
(issues (plist-get out :issues))
(kinds (cl-remove-duplicates
(mapcar (lambda (i) (plist-get i :kind)) issues))))
;; Both kinds appear — check mode reports would-fix entries as
;; mechanical-fixed and judgment items as judgment, no writes.
(should (member 'mechanical-fixed kinds))
(should (member 'judgment kinds))))
;;; ---------------------------------------------------------------------------
;;; Mixed-fixture integration
(ert-deftest lo-mixed-fixture-applies-all-mechanical-and-emits-judgment ()
(let* ((out (lo-test--run lo-test--mixed))
(res (plist-get out :result))
(judgment-checkers
(cl-remove-duplicates
(lo-test--checkers (lo-test--judgments (plist-get out :issues))))))
;; Mechanical: every flagged item-number, bare-src, planning, md-bold fixed.
(should (>= (plist-get out :fixes) 4))
(should (lo-test--has res "4. [@4] out-of-order"))
(should (lo-test--has res "#+begin_example"))
(should (lo-test--has res "*Important.* Body."))
(should (string-match-p
"CLOSED: \\[2026-05-14\\][^\n]*DEADLINE: <2026-05-20"
res))
;; Judgment: every flagged broken link and suspicious-language emitted untouched.
(should (member 'link-to-local-file judgment-checkers))
(should (member 'invalid-fuzzy-link judgment-checkers))
(should (member 'suspicious-language-in-src-block judgment-checkers))
;; The verbatim-asterisk misplaced-heading is suppressed, not surfaced.
(should-not (member 'misplaced-heading judgment-checkers))
;; Verbatim-asterisk untouched in the file.
(should (lo-test--has res "=*** Foo="))))
(ert-deftest lo-mixed-fixture-is-idempotent ()
(let ((once (plist-get (lo-test--run lo-test--mixed 1) :result))
(twice (plist-get (lo-test--run lo-test--mixed 2) :result)))
(should (equal once twice))))
;;; ---------------------------------------------------------------------------
;;; Backup file is created in /tmp
;;; ---------------------------------------------------------------------------
;;; Follow-ups file behavior
(ert-deftest lo-followups-records-judgments-by-content ()
"Each judgment is recorded under a per-file section, keyed by checker +
message with the line as a trailing annotation rather than the entry's identity."
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-" nil ".org")))
(unwind-protect
(progn
(with-temp-file file (insert lo-test--mixed))
(with-temp-file followups (insert ""))
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
(let ((content (with-temp-buffer
(insert-file-contents followups)
(buffer-string))))
;; Per-file section header naming the file.
(should (string-match-p "^\\* lint-org follow-ups — " content))
;; Entries lead with the checker (the content key); line is annotation.
(should (lo-test--has content "TODO link-to-local-file — "))
(should (lo-test--has content "TODO invalid-fuzzy-link — "))
(should (lo-test--has content "TODO suspicious-language-in-src-block — "))
(should (string-match-p "(line [0-9]+)" content))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-followups-dedupes-across-runs ()
"Running twice on the same file reconciles to one section, not two appended
sections."
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-ded-" nil ".org")))
(unwind-protect
(progn
(with-temp-file file (insert lo-test--mixed))
(with-temp-file followups (insert ""))
(dotimes (_ 2)
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file))
(let ((content (with-temp-buffer
(insert-file-contents followups)
(buffer-string)))
(n 0) (start 0))
(while (string-match "^\\* lint-org follow-ups — " content start)
(setq n (1+ n) start (match-end 0)))
(should (= n 1))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-followups-drops-resolved-finding ()
"A finding that no longer reproduces (its source was fixed) is dropped from the
followups file on the next run."
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-drop-" nil ".org")))
(unwind-protect
(progn
;; First run: a broken file link produces a judgment.
(with-temp-file file
(insert "#+TITLE: t\n* H\n[[file:does-not-exist-zzz.org][broken]]\n"))
(with-temp-file followups (insert ""))
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
(should (lo-test--has
(with-temp-buffer (insert-file-contents followups) (buffer-string))
"link-to-local-file"))
;; Fix the source, re-run: the finding no longer reproduces.
(with-temp-file file (insert "#+TITLE: t\n* H\nclean now\n"))
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
(let ((content (with-temp-buffer
(insert-file-contents followups)
(buffer-string))))
(should-not (lo-test--has content "link-to-local-file"))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-followups-preserves-other-files-sections ()
"Reconciling one file's section leaves other files' sections intact."
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-other-" nil ".org")))
(unwind-protect
(progn
(with-temp-file followups
(insert "* lint-org follow-ups — other-file.org (2026-01-01)\n"
"** TODO some-checker — a prior finding (line 5)\n"))
(with-temp-file file (insert lo-test--mixed))
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
(let ((content (with-temp-buffer
(insert-file-contents followups)
(buffer-string))))
;; The unrelated file's section survives.
(should (lo-test--has content "other-file.org"))
(should (lo-test--has content "a prior finding"))
;; This file's section was added alongside it.
(should (lo-test--has content "link-to-local-file"))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-followups-file-skipped-in-check-mode ()
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-check-" nil ".org")))
(unwind-protect
(progn
(with-temp-file file (insert lo-test--mixed))
(with-temp-file followups (insert ""))
(lo-test--reset t followups) ; check=t, followups set
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
;; followups untouched in check mode
(should (equal "" (with-temp-buffer
(insert-file-contents followups)
(buffer-string)))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-followups-file-noop-when-no-judgments ()
;; A fixture with only mechanical issues should leave the followups file empty.
(let ((followups (make-temp-file "lo-followups-" nil ".org"))
(file (make-temp-file "lo-test-fup-empty-" nil ".org")))
(unwind-protect
(progn
(with-temp-file file (insert lo-test--item-number))
(with-temp-file followups (insert ""))
(lo-test--reset nil followups)
(lo-process-file file)
(lo-emit-report)
(lo-test--drop-buffer file)
(should (equal "" (with-temp-buffer
(insert-file-contents followups)
(buffer-string)))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file))
(when (file-exists-p followups) (delete-file followups)))))
(ert-deftest lo-creates-backup-before-modifying ()
(let ((file (make-temp-file "lo-test-bak-" nil ".org")))
(unwind-protect
(progn
(with-temp-file file (insert lo-test--bare-src))
(lo-test--reset)
(lo-process-file file)
(lo-test--drop-buffer file)
;; Backup pattern in lint-org.el: /tmp/<basename>.before-lint-pass.<timestamp>
(let* ((basename (file-name-nondirectory file))
(backups (directory-files "/tmp" t
(concat (regexp-quote basename)
"\\.before-lint-pass\\."))))
(should (>= (length backups) 1))
;; Backup content matches pre-fix content.
(let ((backup (car backups)))
(with-temp-buffer
(insert-file-contents backup)
(should (equal lo-test--bare-src (buffer-string))))
(delete-file backup))))
(lo-test--drop-buffer file)
(when (file-exists-p file) (delete-file file)))))
;;; ---------------------------------------------------------------------------
;;; org-table-standard check (width budget + rules between rows)
(ert-deftest lo-table-over-budget-emits-judgment ()
"A table line rendering wider than 120 surfaces as an org-table-standard judgment."
(let* ((wide (make-string 130 ?x))
(run (lo-test--run (format "* H\n\n| a |\n|---|\n| %s |\n|---|\n" wide)))
(judgments (lo-test--judgments (plist-get run :issues))))
(should (memq 'org-table-standard (lo-test--checkers judgments)))
(should (cl-some (lambda (i) (lo-test--has (plist-get i :msg) "120"))
judgments))))
(ert-deftest lo-table-compliant-not-flagged ()
"A narrow table with rules under header and every row passes silently."
(let* ((run (lo-test--run "* H\n\n| a |\n|---|\n| ok |\n|---|\n"))
(judgments (lo-test--judgments (plist-get run :issues))))
(should-not (memq 'org-table-standard (lo-test--checkers judgments)))))
(ert-deftest lo-table-missing-interrow-rules-emits-judgment ()
"Data rows without a rule between them violate the standard."
(let* ((run (lo-test--run "* H\n\n| a | b |\n|---+---|\n| 1 | 2 |\n| 3 | 4 |\n"))
(judgments (lo-test--judgments (plist-get run :issues))))
(should (memq 'org-table-standard (lo-test--checkers judgments)))
(should (cl-some (lambda (i) (lo-test--has (plist-get i :msg) "rule"))
judgments))))
(ert-deftest lo-table-wide-link-source-measures-render-width ()
"A long link target doesn't trip the budget — width is render-measured."
(let* ((target (concat "https://example.com/" (make-string 120 ?p)))
(run (lo-test--run
(format "* H\n\n| [[%s][ok]] |\n|---|\n| x |\n|---|\n" target)))
(judgments (lo-test--judgments (plist-get run :issues))))
(should-not (memq 'org-table-standard (lo-test--checkers judgments)))))
(ert-deftest lo-table-conformant-wrapped-table-not-flagged ()
"Continuation rows inside a rule-delimited group are one logical row, not a
missing-rules violation."
(let* ((run (lo-test--run
"* H\n\n| Name | Notes |\n|-------+-------------------|\n| alpha | wrapped text that |\n| | continues here |\n|-------+-------------------|\n"))
(judgments (lo-test--judgments (plist-get run :issues))))
(should-not (memq 'org-table-standard (lo-test--checkers judgments)))))
(provide 'test-lint-org)
;;; test-lint-org.el ends here
|