From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4FTCK7sOYGLQQQAAbAwnHQ (envelope-from ) for ; Wed, 20 Apr 2022 15:46:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id cLrIKrsOYGLmAgAAG6o9tA (envelope-from ) for ; Wed, 20 Apr 2022 15:46:35 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4A49D17DC8 for ; Wed, 20 Apr 2022 15:46:35 +0200 (CEST) Received: from localhost ([::1]:58810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhAfC-0001tE-Ak for larch@yhetil.org; Wed, 20 Apr 2022 09:46:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhAKs-0004YS-FI for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 09:25:35 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:43982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhAKq-00046C-77 for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 09:25:34 -0400 Received: by mail-pf1-x42f.google.com with SMTP id y14so1144183pfe.10 for ; Wed, 20 Apr 2022 06:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:in-reply-to:references:message-id:date:mime-version; bh=ErbEmWdMfTIMvMQCVnCmKePTRAJ7uCcdoaIfyXONol4=; b=WCFKM0v4xRGpz8d0EVQvuHfP2y3eYr+3FFX5H1smiG0l4L6v2mJRqs13SM/UNFf0L+ isX7KFqGVJa0aaFy3W9FHe3SgCv0l+DXQQpLpy7VsI4TiAqeerdx5uzD1Hh4KElOXrSa IZ5kFIzBTa68l/DQK8KzfdwhTxrWdGf76CK2bX7na93K2hAGRCvaGq1xYVqgMnaEhu3q 3+TF8SBhP+2Fq6hnZtlalT1yXtSV/fV0mG64w4vIG7YQa3jmOMcGZ7AOGUIQvc+QJ7g0 SqPw7VVapjVR/4rxkwPeMsqz1WuwDZd5gDsXe7N+Tka9cvLydGHR0eQ8fFnD5v8F9C4p mY1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references :message-id:date:mime-version; bh=ErbEmWdMfTIMvMQCVnCmKePTRAJ7uCcdoaIfyXONol4=; b=EU1GhEr9JEatp0uuCpwEx4lqshV1E0fbpeD8lM0a1XI5HJCPLpm5+4gumYgrEjkfPK QY0Yfo6/ZUB7PX9HvvB+mMftJGjDAAdpT/aqDAsdzMahOcRUUWt1YyQ6rUbVZjdaZGpA R25/zd7VAxUVjoP02awMvN1QbLUpokC5JbAKv+/slJoTamiXHfCNSab3NWZriQw7ECaW YYDLOgeEoEUgsGg3CmowWu0T1nCpPFoziUUqBEsmML5QW1TZ1zDGSh3EE78RD9OheNLb +qe73FQUR0kupNTp39WT/4RrQQS2h2Il/cj2e8wcv6dkg5XLJpZbPJ/4HGm263kubDB6 nZ7w== X-Gm-Message-State: AOAM533AflQbJvI+BU2WRuUzVT2bWWex8ujwLW33uU4E1cjMaXHVUPX4 C8zAFVut3AdpxwCrh/u+YfN1Dm4U+IBSxg== X-Google-Smtp-Source: ABdhPJx1/pMD2bxRjQtfw/BCxFB67fN/jRUDs+EkfKcOWf/kpg2ZkZp4HXEiEQ4LuhKTxDKhb9slNg== X-Received: by 2002:a05:6a00:1584:b0:50a:b6a1:6579 with SMTP id u4-20020a056a00158400b0050ab6a16579mr6094830pfk.80.1650461130134; Wed, 20 Apr 2022 06:25:30 -0700 (PDT) Received: from localhost ([64.32.23.62]) by smtp.gmail.com with ESMTPSA id r31-20020a63205f000000b0039db0514016sm19754766pgm.29.2022.04.20.06.25.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 06:25:29 -0700 (PDT) From: Ihor Radchenko To: emacs-orgmode@gnu.org Subject: [PATCH v2 20/38] Add org-fold-related tests--- In-Reply-To: References: Message-Id: <431f005db14d4aecd5ed59ad32dac5427f62cf92.1650460489.git.yantar92@gmail.com> Date: Wed, 20 Apr 2022 21:26:23 +0800 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=yantar92@gmail.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1650462395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=vPANFbKg0Fc1o0ihNn0IGgMnjH8UOUKkj5YmICHSzSk=; b=YnUQ7eQ/v0KsDpXcrDL83oFEtWGBAOVKqO/iLNNCWilkTgZkJfxO/kJ1fxx+mYck8gxXpa dKvUqkXuUwzZ1PYOxj2DlnkfS0yJi7xr6hitJd2xtaTVov6AIGjQwW+XyteL4zoQb80g+E 9ZVI917oWvnGm7i6mLro3dXdi1hpL51WPLNmzNefBiIpZp9iBJv9p8ArtagHjwH3X5yY8t Qg1mJ2CetPGGg/mKyIYU51dOggQNwVwihLe0rR626ERKaRRBFRBQDNuuWcfZXY1KADqYDA FuYN3wrWc8JQj/nYwPBY3srQ3bUZFMH6fBqJ4dVX8F5xvrNKdO+Ih+O9bg1o8Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1650462395; a=rsa-sha256; cv=none; b=YyKPIhpNyd3XcqJYtduAYIJ1JriIC4sE9HgYsWgLxkNbxvPukMXkunEn8v1EjHL56//xUk gorl/rre9FTUAq04J0e5u3QIblbDMZklBqzsypJemWszcWCBIYJsng43CCFQkfltr/SDPd ULoI4rP5rU9ed+JrIJXZCEERU6fe4F30+59+zjHK5AQwpdC+PTzHivZzNwSdM2X8ZD+GQR lpopHET2X2FsJSO+okJwUv8QIFQSsVihMuCLsfZynfXRFeYti723Wscee9BGwH4u5rLHj/ 3RDErNQFlX4Bcc3fl5U2DGvPi4DYuuQ2Xf2F01lEyQuf2omQzuS32HeeAWA8zQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=WCFKM0v4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.16 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=WCFKM0v4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 4A49D17DC8 X-Spam-Score: 7.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: /TXVsNFWfBZX --- testing/lisp/test-ol.el | 24 +++++ testing/lisp/test-org-list.el | 73 ++++++++++---- testing/lisp/test-org.el | 177 +++++++++++++++++++++++++++++++--- 3 files changed, 238 insertions(+), 36 deletions(-) diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el index ddcc570b3..343631623 100644 --- a/testing/lisp/test-ol.el +++ b/testing/lisp/test-ol.el @@ -50,6 +50,30 @@ (ert-deftest test-ol/encode-url-with-escaped-char () (org-link-encode "http://some.host.com/form?&id=blah%2Bblah25" '(?\s ?\[ ?\] ?%)))))) +(ert-deftest test-ol/org-toggle-link-display () + "Make sure that `org-toggle-link-display' is working. +See https://github.com/yantar92/org/issues/4." + (dolist (org-link-descriptive '(nil t)) + (org-test-with-temp-text "* Org link test +[[https://example.com][A link to a site]]" + (dotimes (_ 2) + (goto-char 1) + (re-search-forward "\\[") + (should-not (xor org-link-descriptive (org-invisible-p))) + (re-search-forward "example") + (should-not (xor org-link-descriptive (org-invisible-p))) + (re-search-forward "com") + (should-not (xor org-link-descriptive (org-invisible-p))) + (re-search-forward "]") + (should-not (xor org-link-descriptive (org-invisible-p))) + (re-search-forward "\\[") + (should-not (org-invisible-p)) + (re-search-forward "link") + (should-not (org-invisible-p)) + (re-search-forward "]") + (should-not (xor org-link-descriptive (org-invisible-p))) + (org-toggle-link-display))))) + ;;; Escape and Unescape Links diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index a9490692e..bc8faa672 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -580,22 +580,40 @@ (ert-deftest test-org-list/move-item-down () (let ((org-list-use-circular-motion t)) (org-move-item-down)) (buffer-string)))) ;; Preserve item visibility. + (should + (equal + (make-list 2 'org-fold-outline) + (let ((org-fold-core-style 'text-properties)) + (org-test-with-temp-text + "* Headline\n- item 1\n body 1\n- item 2\n body 2" + (let ((org-cycle-include-plain-lists t)) + (org-cycle) + (search-forward "- item 2") + (org-cycle)) + (search-backward "- item 1") + (org-move-item-down) + (forward-line) + (list (org-fold-get-folding-spec) + (progn + (search-backward " body 2") + (org-fold-get-folding-spec))))))) (should (equal '(outline outline) - (org-test-with-temp-text - "* Headline\n- item 1\n body 1\n- item 2\n body 2" - (let ((org-cycle-include-plain-lists t)) - (org-cycle) - (search-forward "- item 2") - (org-cycle)) - (search-backward "- item 1") - (org-move-item-down) - (forward-line) - (list (org-invisible-p2) - (progn - (search-backward " body 2") - (org-invisible-p2)))))) + (let ((org-fold-core-style 'overlays)) + (org-test-with-temp-text + "* Headline\n- item 1\n body 1\n- item 2\n body 2" + (let ((org-cycle-include-plain-lists t)) + (org-cycle) + (search-forward "- item 2") + (org-cycle)) + (search-backward "- item 1") + (org-move-item-down) + (forward-line) + (list (org-invisible-p2) + (progn + (search-backward " body 2") + (org-invisible-p2))))))) ;; Preserve children visibility. (org-test-with-temp-text "* Headline - item 1 @@ -869,17 +887,30 @@ (ert-deftest test-org-list/insert-item () (org-insert-item) (buffer-string)))) ;; Preserve list visibility when inserting an item. + (should + (equal + `(org-fold-outline org-fold-outline) + (let ((org-fold-core-style 'text-properties)) + (org-test-with-temp-text "- A\n - B\n- C\n - D" + (let ((org-cycle-include-plain-lists t)) + (org-cycle) + (forward-line 2) + (org-cycle) + (org-insert-item) + (list (org-fold-get-folding-spec nil (line-beginning-position 0)) + (org-fold-get-folding-spec nil (line-end-position 2)))))))) (should (equal '(outline outline) - (org-test-with-temp-text "- A\n - B\n- C\n - D" - (let ((org-cycle-include-plain-lists t)) - (org-cycle) - (forward-line 2) - (org-cycle) - (org-insert-item) - (list (get-char-property (line-beginning-position 0) 'invisible) - (get-char-property (line-end-position 2) 'invisible)))))) + (let ((org-fold-core-style 'overlays)) + (org-test-with-temp-text "- A\n - B\n- C\n - D" + (let ((org-cycle-include-plain-lists t)) + (org-cycle) + (forward-line 2) + (org-cycle) + (org-insert-item) + (list (get-char-property (line-beginning-position 0) 'invisible) + (get-char-property (line-end-position 2) 'invisible))))))) ;; Test insertion in area after a sub-list. In particular, if point ;; is right at the end of the previous sub-list, still insert ;; a sub-item in that list. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 0cc8df154..ca0dc676b 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -4462,7 +4462,9 @@ (ert-deftest test-org/drag-element-backward () ;; Preserve visibility of elements and their contents. (should (equal '((63 . 82) (26 . 48)) - (org-test-with-temp-text " + (let ((org-fold-core-style 'text-properties)) + (org-test-with-temp-text + " #+BEGIN_CENTER Text. #+END_CENTER @@ -4470,11 +4472,35 @@ (ert-deftest test-org/drag-element-backward () #+BEGIN_QUOTE Text. #+END_QUOTE" - (while (search-forward "BEGIN_" nil t) (org-cycle)) - (search-backward "- item 1") - (org-drag-element-backward) - (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov))) - (overlays-in (point-min) (point-max)))))) + (while (search-forward "BEGIN_" nil t) (org-cycle)) + (search-backward "- item 1") + (org-drag-element-backward) + (let (regions) + (goto-char (point-min)) + (while (< (point) (point-max)) + (let ((region (org-fold-get-region-at-point))) + (if (not region) + (goto-char (org-fold-next-folding-state-change)) + (goto-char (cdr region)) + (push region regions)))) + regions))))) + (should + (equal '((63 . 82) (26 . 48)) + (let ((org-fold-core-style 'overlays)) + (org-test-with-temp-text + " +#+BEGIN_CENTER +Text. +#+END_CENTER +- item 1 + #+BEGIN_QUOTE + Text. + #+END_QUOTE" + (while (search-forward "BEGIN_" nil t) (org-cycle)) + (search-backward "- item 1") + (org-drag-element-backward) + (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov))) + (overlays-in (point-min) (point-max))))))) ;; Pathological case: handle call with point in blank lines right ;; after a headline. (should @@ -4511,7 +4537,9 @@ (ert-deftest test-org/drag-element-forward () (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3")) (should (looking-at " 1"))) ;; 5. Preserve visibility of elements and their contents. - (org-test-with-temp-text " + (let ((org-fold-core-style 'text-properties)) + (org-test-with-temp-text + " #+BEGIN_CENTER Text. #+END_CENTER @@ -4519,14 +4547,39 @@ (ert-deftest test-org/drag-element-forward () #+BEGIN_QUOTE Text. #+END_QUOTE" - (while (search-forward "BEGIN_" nil t) (org-cycle)) - (search-backward "#+BEGIN_CENTER") - (org-drag-element-forward) - (should - (equal - '((63 . 82) (26 . 48)) - (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov))) - (overlays-in (point-min) (point-max))))))) + (while (search-forward "BEGIN_" nil t) (org-cycle)) + (search-backward "#+BEGIN_CENTER") + (org-drag-element-forward) + (should + (equal + '((63 . 82) (26 . 48)) + (let (regions) + (goto-char (point-min)) + (while (< (point) (point-max)) + (let ((region (org-fold-get-region-at-point))) + (if (not region) + (goto-char (org-fold-next-folding-state-change)) + (goto-char (cdr region)) + (push region regions)))) + regions))))) + (let ((org-fold-core-style 'overlays)) + (org-test-with-temp-text + " +#+BEGIN_CENTER +Text. +#+END_CENTER +- item 1 + #+BEGIN_QUOTE + Text. + #+END_QUOTE" + (while (search-forward "BEGIN_" nil t) (org-cycle)) + (search-backward "#+BEGIN_CENTER") + (org-drag-element-forward) + (should + (equal + '((63 . 82) (26 . 48)) + (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov))) + (overlays-in (point-min) (point-max)))))))) (ert-deftest test-org/next-block () "Test `org-next-block' specifications." @@ -8419,6 +8472,100 @@ (ert-deftest test-org/visibility-show-branches () (org-kill-note-or-show-branches) (should (org-invisible-p (- (point-max) 2))))) +(ert-deftest test-org/org-cycle-narrowed-subtree () + "Test cycling in narrowed buffer." + (org-test-with-temp-text + "* Heading 1 +** 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/org-fold-reveal-broken-structure () + "Test unfolding broken elements." + (let ((org-fold-core-style 'text-properties)) + (org-test-with-temp-text + "* Heading 1 +Text here" + (org-overview) + (re-search-forward "Text") + (should (org-invisible-p)) + (goto-char 1) + (delete-char 1) + (re-search-forward "Text") + (should-not (org-invisible-p))) + (org-test-with-temp-text + "* Heading 1 +: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 +: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 +#+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/re-hide-edits-inside-fold () + "Test edits inside folded regions." + (org-test-with-temp-text + "* 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 +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 here" + (org-overview) + (insert " and extra text") + (re-search-backward "extra") + (should (org-invisible-p)))) + ;;; Yank and Kill -- 2.35.1 -- Ihor Radchenko, PhD, Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg