test-org.el: Actually test org-copy-visible

* testing/lisp/test-org.el (test-org/copy-visible): Switch defun to
ert-deftest so that the test is actually executed, and resolve
failures in test.

Make two adjustments so that the now executed test passes:

  - Correct the end value of the hidden part of the string for one
    test case.

  - Disable org-unfontify-region so that the invisible properties show
    up in the temporary buffer.

    I think org-unfontify-region should probably be changed to _not_
    remove the invisible property, but it's a longstanding behavior.
    Changing it would need more thought and isn't something that
    should be done on the bugfix branch.
This commit is contained in:
Kyle Meyer 2022-02-27 23:31:49 -05:00
parent 83c6eccaee
commit e85a872f3b
1 changed files with 49 additions and 45 deletions

View File

@ -8176,52 +8176,56 @@ CLOSED: %s
(org-show-set-visibility 'minimal) (org-show-set-visibility 'minimal)
(org-invisible-p2)))) (org-invisible-p2))))
(defun test-org/copy-visible () (ert-deftest test-org/copy-visible ()
"Test `org-copy-visible' specifications." "Test `org-copy-visible' specifications."
(should ;;`org-unfontify-region', which is wired up to
(equal "Foo" ;; `font-lock-unfontify-region-function', removes the invisible text
(org-test-with-temp-text "Foo" ;; property, among other things.
(let ((kill-ring nil)) (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
(org-copy-visible (point-min) (point-max)) (should
(current-kill 0 t))))) (equal "Foo"
;; Skip invisible characters by text property. (org-test-with-temp-text "Foo"
(should (let ((kill-ring nil))
(equal "Foo" (org-copy-visible (point-min) (point-max))
(org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t)) (current-kill 0 t)))))
(let ((kill-ring nil)) ;; Skip invisible characters by text property.
(org-copy-visible (point-min) (point-max)) (should
(current-kill 0 t))))) (equal "Foo"
;; Skip invisible characters by overlay. (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
(should (let ((kill-ring nil))
(equal "Foo" (org-copy-visible (point-min) (point-max))
(org-test-with-temp-text "F<hidden>oo" (current-kill 0 t)))))
(let ((o (make-overlay 2 10))) ;; Skip invisible characters by overlay.
(overlay-put o 'invisible t)) (should
(let ((kill-ring nil)) (equal "Foo"
(org-copy-visible (point-min) (point-max)) (org-test-with-temp-text "F<hidden>oo"
(current-kill 0 t))))) (let ((o (make-overlay 2 10)))
;; Handle invisible characters at the beginning and the end of the (overlay-put o 'invisible t))
;; buffer. (let ((kill-ring nil))
(should (org-copy-visible (point-min) (point-max))
(equal "Foo" (current-kill 0 t)))))
(org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t)) ;; Handle invisible characters at the beginning and the end of the
(let ((kill-ring nil)) ;; buffer.
(org-copy-visible (point-min) (point-max)) (should
(current-kill 0 t))))) (equal "Foo"
(should (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
(equal "Foo" (let ((kill-ring nil))
(org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t)) (org-copy-visible (point-min) (point-max))
(let ((kill-ring nil)) (current-kill 0 t)))))
(org-copy-visible (point-min) (point-max)) (should
(current-kill 0 t))))) (equal "Foo"
;; Handle multiple visible parts. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
(should (let ((kill-ring nil))
(equal "abc" (org-copy-visible (point-min) (point-max))
(org-test-with-temp-text (current-kill 0 t)))))
#("aXbXc" 1 2 (invisible t) 3 4 (invisible t)) ;; Handle multiple visible parts.
(let ((kill-ring nil)) (should
(org-copy-visible (point-min) (point-max)) (equal "abc"
(current-kill 0 t)))))) (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)))))))
(ert-deftest test-org/set-visibility-according-to-property () (ert-deftest test-org/set-visibility-according-to-property ()
"Test `org-set-visibility-according-to-property' specifications." "Test `org-set-visibility-according-to-property' specifications."