From e85a872f3bc64826ebc51b4dafadd485a276ff4b Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 27 Feb 2022 23:31:49 -0500 Subject: [PATCH] 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. --- testing/lisp/test-org.el | 94 +++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 5b161315d..57daf4eeb 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -8176,52 +8176,56 @@ CLOSED: %s (org-show-set-visibility 'minimal) (org-invisible-p2)))) -(defun test-org/copy-visible () +(ert-deftest test-org/copy-visible () "Test `org-copy-visible' specifications." - (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 #("Foo" 1 7 (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 "Foo" - (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 #("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" 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)))))) + ;;`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 #("Foo" 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 "Foo" + (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 #("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" 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))))))) (ert-deftest test-org/set-visibility-according-to-property () "Test `org-set-visibility-according-to-property' specifications."