blob: fff1610fe171a666647b9a95855d9657a9a493aa (
plain)
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
|
;;; test-org-drill-hide-drawers-missing-end.el --- Regression for missing :END: -*- lexical-binding: t; -*-
;;; Commentary:
;; `org-drill-hide-drawers' captured drawer-end as
;; (save-excursion (re-search-forward ":END:" end t) (point))
;; which always returns a number — `(point)' is always defined. The
;; subsequent `(when drawer-end ...)' guard was dead code, so a
;; malformed drawer without `:END:' would either no-op silently or
;; create a zero/negative-width overlay (depending on point state).
;;
;; The user-visible failure mode: a drawer with a typo or
;; mid-edit truncation gets the body kept visible during the drill
;; (which is intended), but the function does junk overlay work to
;; get there. Captured the search result and gate on that.
;;; Code:
(require 'ert)
(require 'cl-lib)
(require 'org)
(require 'org-drill)
;;;; Regression
(ert-deftest test-hide-drawers-malformed-drawer-without-end-creates-no-overlay ()
"A drawer that opens but never closes should not produce a hidden-text
overlay (and should not error)."
(with-temp-buffer
(let ((org-startup-folded nil))
;; Note: no :END:. Just :NOTANEND: as a near-miss.
(insert "* Question :drill:\n:PROPERTIES:\n:ID: x\n:NOTANEND:\nbody\n")
(org-mode)
(goto-char (point-min))
(org-drill-hide-drawers)
;; Count overlays — there should be none from the malformed drawer.
(let ((n 0))
(dolist (ovl (overlays-in (point-min) (point-max)))
(when (eql 'org-drill-hidden-text-overlay (overlay-get ovl 'category))
(cl-incf n)))
;; Either no overlays at all (drawer skipped entirely), or only
;; well-formed drawers were hidden. No malformed-drawer overlay.
(should (= 0 n))))))
(ert-deftest test-hide-drawers-malformed-followed-by-wellformed-still-hides-good ()
"Even after encountering a malformed drawer, well-formed drawers still hide."
(with-temp-buffer
(let ((org-startup-folded nil))
(insert "* Question :drill:
:LOGBOOK:
note one
:END:
body line
")
(org-mode)
(goto-char (point-min))
(org-drill-hide-drawers)
;; The LOGBOOK drawer is well-formed → 1 overlay expected.
(let ((n 0))
(dolist (ovl (overlays-in (point-min) (point-max)))
(when (eql 'org-drill-hidden-text-overlay (overlay-get ovl 'category))
(cl-incf n)))
(should (>= n 1))))))
(provide 'test-org-drill-hide-drawers-missing-end)
;;; test-org-drill-hide-drawers-missing-end.el ends here
|