emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob ffcfde56be607c0765cd7bf0d295d3a26121add2 22173 bytes (raw)
name: testing/lisp/test-org-fold.el 	 # note: path name is non-authoritative(*)

  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
 
;;; test-org.el --- tests for org.el  -*- lexical-binding: t; -*-

;; Authors: Ihor Radchenko

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;; Org folding tests.

;;; Code:

(eval-and-compile (require 'cl-lib))

\f

(ert-deftest test-org-fold/hide-drawer-toggle ()
  "Test `org-fold-hide-drawer-toggle' specifications."
  ;; Error when not at a drawer.
  (should-error
   (org-test-with-temp-text ":fake-drawer:\ncontents"
     (org-fold-hide-drawer-toggle 'off)
     (get-char-property (line-end-position) 'invisible)))
  (should-error
   (org-test-with-temp-text
       "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
     (org-fold-hide-drawer-toggle t)))
  ;; Hide drawer.
  (should
   (org-test-with-temp-text ":drawer:\ncontents\n:end:"
     (org-fold-show-all)
     (org-fold-hide-drawer-toggle)
     (get-char-property (line-end-position) 'invisible)))
  ;; Show drawer unconditionally when optional argument is `off'.
  (should-not
   (org-test-with-temp-text ":drawer:\ncontents\n:end:"
     (org-fold-hide-drawer-toggle)
     (org-fold-hide-drawer-toggle 'off)
     (get-char-property (line-end-position) 'invisible)))
  ;; Hide drawer unconditionally when optional argument is non-nil.
  (should
   (org-test-with-temp-text ":drawer:\ncontents\n:end:"
     (org-fold-hide-drawer-toggle t)
     (get-char-property (line-end-position) 'invisible)))
  ;; Do not hide drawer when called from final blank lines.
  (should-not
   (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
     (org-fold-show-all)
     (org-fold-hide-drawer-toggle)
     (goto-char (point-min))
     (get-char-property (line-end-position) 'invisible)))
  ;; Don't leave point in an invisible part of the buffer when hiding
  ;; a drawer away.
  (should-not
   (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
     (org-fold-hide-drawer-toggle)
     (get-char-property (point) 'invisible))))

(ert-deftest test-org/hide-block-toggle ()
  "Test `org-fold-hide-block-toggle' specifications."
  ;; Error when not at a block.
  (should-error
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
     (org-fold-hide-block-toggle 'off)
     (get-char-property (line-end-position) 'invisible)))
  ;; Hide block.
  (should
   (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
     (org-fold-hide-block-toggle)
     (get-char-property (line-end-position) 'invisible)))
  (should
   (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
     (org-fold-hide-block-toggle)
     (get-char-property (line-end-position) 'invisible)))
  ;; Show block unconditionally when optional argument is `off'.
  (should-not
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
     (org-fold-hide-block-toggle)
     (org-fold-hide-block-toggle 'off)
     (get-char-property (line-end-position) 'invisible)))
  (should-not
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
     (org-fold-hide-block-toggle 'off)
     (get-char-property (line-end-position) 'invisible)))
  ;; Hide block unconditionally when optional argument is non-nil.
  (should
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
     (org-fold-hide-block-toggle t)
     (get-char-property (line-end-position) 'invisible)))
  (should
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
     (org-fold-hide-block-toggle)
     (org-fold-hide-block-toggle t)
     (get-char-property (line-end-position) 'invisible)))
  ;; Do not hide block when called from final blank lines.
  (should-not
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
     (org-fold-hide-block-toggle)
     (goto-char (point-min))
     (get-char-property (line-end-position) 'invisible)))
  ;; Don't leave point in an invisible part of the buffer when hiding
  ;; a block away.
  (should-not
   (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
     (org-fold-hide-block-toggle)
     (get-char-property (point) 'invisible))))

(ert-deftest test-org-fold/hide-block-toggle-maybe ()
  "Test `org-fold-hide-block-toggle' specifications."
  (should
   (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
     (org-hide-block-toggle)))
  (should-error
   (org-test-with-temp-text "Paragraph" (org-hide-block-toggle))))

(ert-deftest test-org-fold/show-set-visibility ()
  "Test `org-fold-show-set-visibility' specifications."
  ;; Do not throw an error before first heading.
  (should
   (org-test-with-temp-text "Preamble\n* Headline"
     (org-fold-show-set-visibility 'tree)
     t))
  ;; Test all visibility spans, both on headline and in entry.
  (let ((list-visible-lines
	 (lambda (state headerp)
	   (org-test-with-temp-text "* Grandmother  (0)
** Uncle              (1)
*** Heir              (2)
** Father             (3)
   Ancestor text      (4)
*** Sister            (5)
    Sibling text      (6)
*** Self              (7)
    Match	      (8)
**** First born	      (9)
     Child text	      (10)
**** The other child  (11)
*** Brother	      (12)
** Aunt               (13)
"
	     (org-cycle t)
	     (search-forward (if headerp "Self" "Match"))
	     (org-fold-show-set-visibility state)
	     (goto-char (point-min))
	     (let (result (line 0))
	       (while (not (eobp))
		 (unless (org-invisible-p2) (push line result))
		 (cl-incf line)
		 (forward-line))
	       (nreverse result))))))
    (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
    (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
    (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
    (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
    (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
    (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
    (should (equal '(0 3 7 8 9 10 11)
                   (funcall list-visible-lines 'ancestors-full t)))
    (should (equal '(0 3 7 8 9 10 11)
                   (funcall list-visible-lines 'ancestors-full nil)))
    (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
    (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
    (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
    (should (equal '(0 1 3 5 7 8 9 11 12 13)
		   (funcall list-visible-lines 'tree nil)))
    (should (equal '(0 1 3 4 5 7 12 13)
		   (funcall list-visible-lines 'canonical t)))
    (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
		   (funcall list-visible-lines 'canonical nil))))
  ;; When point is hidden in a drawer or a block, make sure to make it
  ;; visible.
  (should-not
   (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
     (org-fold-hide-block-toggle)
     (search-forward "Text")
     (org-fold-show-set-visibility 'minimal)
     (org-invisible-p2)))
  (should-not
   (org-test-with-temp-text ":DRAWER:\nText\n:END:"
     (org-fold-hide-drawer-toggle)
     (search-forward "Text")
     (org-fold-show-set-visibility 'minimal)
     (org-invisible-p2)))
  (should-not
   (org-test-with-temp-text
       "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
     (org-fold-hide-drawer-toggle)
     (forward-line -1)
     (org-fold-hide-block-toggle)
     (search-forward "Text")
     (org-fold-show-set-visibility 'minimal)
     (org-invisible-p2))))

(ert-deftest test-org-fold/copy-visible ()
  "Test `org-copy-visible' specifications."
  ;;`org-unfontify-region', which is wired up to
  ;; `font-lock-unfontify-region-function', removes the invisible text
  ;; property, among other things.
  (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
    (should
     (equal "Foo"
	    (org-test-with-temp-text "Foo"
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Skip invisible characters by text property.
    (should
     (equal "Foo"
	    (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Skip invisible characters by overlay.
    (should
     (equal "Foo"
	    (org-test-with-temp-text "F<hidden>oo"
	      (let ((o (make-overlay 2 10)))
	        (overlay-put o 'invisible t))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Handle invisible characters at the beginning and the end of the
    ;; buffer.
    (should
     (equal "Foo"
	    (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    (should
     (equal "Foo"
	    (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Handle multiple visible parts.
    (should
     (equal "abc"
	    (org-test-with-temp-text
	        #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Handle adjacent invisible parts.
    (should
     (equal "ab"
	    (org-test-with-temp-text
	        #("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))
    ;; Copies text based on what's actually visible, as defined by
    ;; `buffer-invisibility-spec'.
    (should
     (equal "aYb"
	    (org-test-with-temp-text
	        #("aXYb"
                  1 2 (invisible t)
                  2 3 (invisible org-test-copy-visible))
	      (let ((kill-ring nil))
	        (org-copy-visible (point-min) (point-max))
	        (current-kill 0 t)))))))

(ert-deftest test-org-fold/set-visibility-according-to-property ()
  "Test `org-set-visibility-according-to-property' specifications."
  ;; "folded" state.
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: folded
:END:
** <point>b"
     (org-set-visibility-according-to-property)
     (invisible-p (point))))
  ;; "children" state.
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: children
:END:
** b
<point>Contents
** c"
     (org-set-visibility-according-to-property)
     (invisible-p (point))))
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: children
:END:
** b
Contents
*** <point>c"
     (org-set-visibility-according-to-property)
     (invisible-p (point))))
  ;; "content" state.
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: content
:END:
** b
<point>Contents
*** c"
     (org-set-visibility-according-to-property)
     (invisible-p (point))))
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: content
:END:
** b
Contents
*** <point>c"
     (org-set-visibility-according-to-property)
     (not (invisible-p (point)))))
  ;; "showall" state.
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: showall
:END:
** b
<point>Contents
*** c"
     (org-set-visibility-according-to-property)
     (not (invisible-p (point)))))
  (should
   (org-test-with-temp-text
       "
* a
:PROPERTIES:
:VISIBILITY: showall
:END:
** b
Contents
*** <point>c"
     (org-set-visibility-according-to-property)
     (not (invisible-p (point)))))
  ;; When VISIBILITY properties are nested, ignore inner ones.
  (should
   (org-test-with-temp-text
       "
* A
:PROPERTIES:
:VISIBILITY: folded
:END:
** <point>B
:PROPERTIES:
:VISIBILITY: folded
:END:"
     (org-set-visibility-according-to-property)
     (invisible-p (point)))))

(ert-deftest test-org-fold/visibility-show-branches ()
  "Test visibility of inline archived subtrees."
  (org-test-with-temp-text
      "* Foo<point>
** Bar :ARCHIVE:
*** Baz
"
    (org-kill-note-or-show-branches)
    (should (org-invisible-p (- (point-max) 2)))))

(ert-deftest test-org-fold/org-cycle-narrowed-subtree ()
  "Test cycling in narrowed buffer."
  (org-test-with-temp-text
      "* Heading 1<point>
** Child 1.1
** Child 1.2
some text
*** Sub-child 1.2.1
* Heading 2"
    (org-overview)
    (org-narrow-to-subtree)
    (org-cycle)
    (re-search-forward "Sub-child")
    (should (org-invisible-p))))

(ert-deftest test-org-fold/org-fold-reveal-broken-structure ()
  "Test unfolding broken elements."
  (let ((org-fold-core-style 'text-properties))
    (org-test-with-temp-text
        "<point>* Heading 1
Text here"
      (org-overview)
      (re-search-forward "Text")
      (should (org-invisible-p))
      (goto-char 1)
      (org-delete-char 1)
      (re-search-forward "Text")
      (should-not (org-invisible-p)))
    (org-test-with-temp-text
        "* Heading 1
<point>:PROPERTIES:
:ID: something
:END:
Text here"
      (org-cycle)
      (org-fold-hide-drawer-all)
      (re-search-forward "ID")
      (should (org-invisible-p))
      (re-search-backward ":PROPERTIES:")
      (delete-char 1)
      (re-search-forward "ID")
      (should-not (org-invisible-p)))
    (org-test-with-temp-text
        "* Heading 1
<point>:PROPERTIES:
:ID: something
:END:
Text here"
      (org-cycle)
      (org-fold-hide-drawer-all)
      (re-search-forward "ID")
      (should (org-invisible-p))
      (re-search-forward ":END:")
      (delete-char -1)
      (re-search-backward "ID")
      (should-not (org-invisible-p)))
    (org-test-with-temp-text
        "* Heading 1
<point>#+begin_src emacs-lisp
(+ 1 2)
#+end_src
Text here"
      (org-cycle)
      (org-fold-hide-drawer-all)
      (re-search-forward "end")
      (should (org-invisible-p))
      (delete-char -1)
      (re-search-backward "2")
      (should-not (org-invisible-p)))))

(ert-deftest test-org-fold/re-hide-edits-inside-fold ()
  "Test edits inside folded regions."
  (org-test-with-temp-text
      "<point>* Heading 1
Text here"
    (org-overview)
    (org-set-property "TEST" "1")
    (re-search-forward "TEST")
    (should (org-invisible-p)))
  (org-test-with-temp-text
      "* Heading 1<point>
Text here"
    (org-overview)
    (insert " and extra heading text")
    (re-search-backward "heading")
    (should-not (org-invisible-p)))
  (org-test-with-temp-text
      "* Heading 1
Text<point> here"
    (org-overview)
    (insert " and extra text")
    (re-search-backward "extra")
    (should (org-invisible-p))))


(defmacro test-org-fold-with-default-template (&rest body)
  "Run `org-test-with-temp-text' using default folded template."
  (declare (indent 0))
  `(let ((org-link-descriptive t))
     (org-test-with-temp-text
         "#+STARTUP: showeverything
* <point>Folded heading
Folded Paragraph inside heading.
* Unfolded heading
:FOLDED-DRAWER:
Folded Paragraph inside drawer.
:END:
Unfolded Paragraph.
#+begin_src emacs-lisp
(message \"Folded block\")
#+end_src
[[hiddenlink][link]]
"
       (org-cycle)
       (search-forward "FOLDED-DRAWER")
       (org-hide-drawer-toggle t)
       (search-forward "begin_src")
       (org-hide-block-toggle t)
       (goto-char 1)
       ,@body)))

(ert-deftest test-org-fold/org-catch-invisible-edits ()
  "Test invisible edits handling."
  ;; Disable delay in `org-fold-check-before-invisible-edit'.
  (cl-letf (((symbol-function 'sit-for) #'ignore))
    (dolist (org-fold-core-style '(text-properties overlays))
      (dolist (org-fold-catch-invisible-edits
               '(nil error smart show show-and-error))
        (dolist (kind '(insert delete-backward delete nil))
          (message "Testing invisible edits: %S:%S:%S"
                   org-fold-core-style
                   org-fold-catch-invisible-edits
                   kind)
          ;; Edits outside invisible.
          (test-org-fold-with-default-template
            (search-forward "Unfolded Paragraph")
            (message "Outside invisible")
            (org-fold-check-before-invisible-edit kind)
            (should-not (org-invisible-p)))
          ;; Edits inside invisible region.
          (test-org-fold-with-default-template
            (dolist (txt '("Folded Paragraph inside heading"
                           "Folded Paragraph inside drawer"
                           "Folded block"))
              (search-forward txt)
              (message "Inside invisible %S" txt)
              (pcase org-fold-catch-invisible-edits
                (`nil
                 (org-fold-check-before-invisible-edit kind)
                 (should (org-invisible-p)))
                (`show
                 (org-fold-check-before-invisible-edit kind)
                 (should-not (org-invisible-p)))
                ((or `smart `show-and-error)
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should-not (org-invisible-p)))
                (`error
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should (org-invisible-p)))))
            (search-forward "hiddenlink")
            (message "Inside hidden link")
            (org-fold-check-before-invisible-edit kind)
            (should (org-invisible-p)))
          ;; Edits at the left border.
          (test-org-fold-with-default-template
            (dolist (txt '("Folded heading"
                           ":FOLDED-DRAWER:"
                           "#+begin_src emacs-lisp"))
              (search-forward txt)
              (message "Left of folded %S" txt)
              (pcase org-fold-catch-invisible-edits
                (`nil
                 (org-fold-check-before-invisible-edit kind)
                 (should (org-invisible-p (1+ (point)))))
                (`show
                 (org-fold-check-before-invisible-edit kind)
                 (should-not (org-invisible-p (1+ (point)))))
                (`smart
                 (if (memq kind '(insert delete-backward))
                     (org-fold-check-before-invisible-edit kind)
                   (should-error (org-fold-check-before-invisible-edit kind)))
                 (should-not (org-invisible-p (1+ (point)))))
                (`show-and-error
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should-not (org-invisible-p (1+ (point)))))
                (`error
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should (org-invisible-p (1+ (point)))))))
            (search-forward "hiddenlink")
            (search-forward "lin")
            (message "Left border of ]] in link")
            (org-fold-check-before-invisible-edit kind)
            (should (org-invisible-p (1+ (point)))))
          ;; Edits at the right border.
          (test-org-fold-with-default-template
            (dolist (txt '("Folded Paragraph inside heading."
                           ":END:"
                           "#+end_src"))
              (search-forward txt)
              (message "After %S" txt)
              (pcase org-fold-catch-invisible-edits
                (`nil
                 (org-fold-check-before-invisible-edit kind)
                 (should (org-invisible-p (1- (point)))))
                (`show
                 (org-fold-check-before-invisible-edit kind)
                 (should-not (org-invisible-p (1- (point)))))
                ((or `smart `show-and-error)
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should-not (org-invisible-p (1- (point)))))
                (`error
                 (should-error (org-fold-check-before-invisible-edit kind))
                 (should (org-invisible-p (1- (point)))))))
            (search-forward "hiddenlink")
            (search-forward "link]]")
            (message "Right border of ]] in link")
            (org-fold-check-before-invisible-edit kind)
            (should (org-invisible-p (1- (point))))))))))

(ert-deftest test-org-fold/org-fold-display-inline-images ()
  "Test inline images displaying when cycling."
  (let* ((org-cycle-inline-images-display t)
         (images-dir (expand-file-name "examples/images/" org-test-dir))
         (org-logo-image (expand-file-name "Org mode logo mono-color.png" images-dir)))
    ;; `org-cycle' -(state)-> `'children' display child inline images.
    (org-test-with-temp-text
        (format "<point>* Heading 1
[[file:%s]]" org-logo-image)
      (org-overview)
      (org-cycle)
      (org-next-link)
      (should (overlays-at (point)))
      (org-toggle-inline-images)
      (should-not (overlays-at (point))))
    
    ;; `org-cycle' -(state)-> `'subtree' display subtrees inline images.
    (org-test-with-temp-text
        (format "<point>* Heading 1
[[file:%s]]
** Subheading 1
[[file:%s]]
** Subheading 2
[[file:%s]]" org-logo-image org-logo-image org-logo-image)
      (org-overview)
      (org-cycle)
      (org-cycle)
      (org-next-link)
      (org-next-link)
      (should (overlays-at (point)))
      (org-toggle-inline-images)
      (should-not (overlays-at (point))))
    
    ;; `org-cycle' -(state)-> `'folded' remove inline image overlays.
    ;; (org-test-with-temp-text
    ;;         (format "<point>* Heading 1
    ;; [[file:%s]]
    ;; ** Subheading 1
    ;; [[file:%s]]
    ;; ** Subheading 2
    ;; [[file:%s]]" org-logo-image org-logo-image org-logo-image)
    ;;       (org-overview)
    ;;       (org-cycle)
    ;;       (org-cycle)
    ;;       (org-cycle)
    ;;       ;; TODO: how to detect inline image overlays are deleted after folded?
    ;;       )
    ))

(provide 'test-org-fold)

;;; test-org-fold.el ends here

debug log:

solving ffcfde56b ...
found ffcfde56b in https://list.orgmode.org/orgmode/m2k05jyif4.fsf@numbchild@gmail.com/
found 0fa800dee in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 0fa800deefe81a4f3d95cbae86e73ceb3e1e4f63	testing/lisp/test-org-fold.el

applying [1/1] https://list.orgmode.org/orgmode/m2k05jyif4.fsf@numbchild@gmail.com/
diff --git a/testing/lisp/test-org-fold.el b/testing/lisp/test-org-fold.el
index 0fa800dee..ffcfde56b 100644

1:24: trailing whitespace.
    
1:41: trailing whitespace.
    
Checking patch testing/lisp/test-org-fold.el...
Applied patch testing/lisp/test-org-fold.el cleanly.
warning: 2 lines add whitespace errors.

index at:
100644 ffcfde56be607c0765cd7bf0d295d3a26121add2	testing/lisp/test-org-fold.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).