From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aPQuJNUs9WGFDQAAgWs5BA (envelope-from ) for ; Sat, 29 Jan 2022 13:02:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CLR3IdUs9WGRjwAA9RJhRA (envelope-from ) for ; Sat, 29 Jan 2022 13:02:29 +0100 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 CCAF22953B for ; Sat, 29 Jan 2022 13:02:28 +0100 (CET) Received: from localhost ([::1]:58010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nDmR1-0003fB-Uz for larch@yhetil.org; Sat, 29 Jan 2022 07:02:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nDm2T-0004CQ-NK for emacs-orgmode@gnu.org; Sat, 29 Jan 2022 06:37:06 -0500 Received: from [2607:f8b0:4864:20::530] (port=35373 helo=mail-pg1-x530.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nDm2R-0000lD-EO; Sat, 29 Jan 2022 06:37:05 -0500 Received: by mail-pg1-x530.google.com with SMTP id p125so7633763pga.2; Sat, 29 Jan 2022 03:37:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xuwr3m4t6HhU7oUsbUkjbPyEWIHROHe6ZviiTMY6JXA=; b=FJan1UMyOcP7X3cflNjBq9jSqqXBYG9WVkb5agb5iiBJ0D1rdhzcqB2j1lxslNUC1R gd+Q7yE/TJS3DEJNOKO1D1d9/zqjF41wtFfmyWDSpJaKCjd7t4C11McyWxOndJkAEils tcnvJhBsa/3C82Omq2bbrXN97mo+LyLU3ntxsDetXMnp01lYOnI5c64o71wrJMw4pgiH vtuTDlEh3YpTkyHXYeB2N5lkzhRZq1Zp2eW1FMzdRscH96UIIXfwBD+BIsRgz8mUzQiv kP2FSl4GCaJFnH2gCbPMu1FhXkQm8SSfJ8o0teaIxYIDL/CExlZ0wWwhLQdaaPlMl5T7 oKCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xuwr3m4t6HhU7oUsbUkjbPyEWIHROHe6ZviiTMY6JXA=; b=77yFcAqoQ+Cl1au/HqnGv6j7zuJZ5Sp7RCHSlxoEOFf7O4UULDZCuZsb4C3vBSR1ol czaDhVMAwCKK1ZPpB0hY77t8vCLM2DmA1DJXFklmWKM8PVULQ3Z/CqfdBav2myb1/lUm EkcM0/hF+kk0oYPZUwnEiiRjqz86BN+hGzWSirOyyZ7OxBIGazrvPxWW2p0bMbFaaoW+ N7lsYT43s7fvKQzb6mOBIvR3SwuEzcKAFrWwL/BKw9KUc6mAe4IbhFIrnBS3QJSoP5r1 GzMyCngkBapjdgZGATuFuaS/2BIIRmG75DWaL1ubHSqe4/vIVxhhF80qkcWBNnD0iYAT y21Q== X-Gm-Message-State: AOAM533rIqrxY+Aj84gz37TS0nEsyQOY8hsqkGRaePqbE/9C9iW1tNhw 3S9xOCRujnmwoMARMyrx654v6FujkGRniWYV X-Google-Smtp-Source: ABdhPJwoPUc4zArKcjVa3AwHJDMsWntl56VXfPcNohjYmAG5CauHGGybXCkl4wJB+bTjPKPCr4aY/w== X-Received: by 2002:a63:6b8a:: with SMTP id g132mr9863889pgc.540.1643456220892; Sat, 29 Jan 2022 03:37:00 -0800 (PST) Received: from localhost ([209.95.60.92]) by smtp.gmail.com with ESMTPSA id q16sm12645844pfu.194.2022.01.29.03.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 03:37:00 -0800 (PST) From: Ihor Radchenko To: Bastien , Kyle Meyer , Nicolas Goaziou , Karl Voit , Christian Heinrich , emacs-orgmode@gnu.org Subject: [PATCH 20/35] Add org-fold-related tests Date: Sat, 29 Jan 2022 19:38:12 +0800 Message-Id: <2cd98bb1ced0e32e0bf72b017404d29a5e612d4f.1643454546.git.yantar92@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: <87y2cvloay.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.34.1" Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::530 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=yantar92@gmail.com; helo=mail-pg1-x530.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Ihor Radchenko Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643457748; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=pCVp6qOiZkrdrxjHc/U21emkmNJBnx0FWgvEnL03SD4=; b=Y023cVRnkhrOX1yfZeoziIhNaigWbVTrjOlkIuG69Iq+19s6yuPDTwmdH03MaeDehL5E2b rCsr8ncJ39s6GYEU+h9/TbLp2MV4Jb0gykwMZg7pkgEqTrv852sI/kwGfAXOnckJCQNB/9 HLvjnHpkpPEbOdeANUl44SJfAfdUBK5VD8DpDws7N453e79Lh3MCtUmbPQTSd7P6XtjTGn PvOjCqSJg3eOiXJ9dwWUVwmERRReTlZnuFXQrxh/+JHVaIhrlXBPN+zhBKxvT/QMVee3Ht N32Ls9s0BIv3aq3lRR69Nsfg+1tGnKOjDWZDcSY69Rgj5xZVjrKZ9ISKOCdg4g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643457748; a=rsa-sha256; cv=none; b=WlckSQ5/6tKzD5W+eYHJfQqAtONgxJ6KL6IOvxbEaVT5hvsUAPvxrNoF22CnvY0dRk5OuL RkNjZK26mM81bnTo+kbSZdB8kgbxpdlmMpKrt5s4bU8zDKvok6gIHhUNem85SCifORj+no j9lkJvqLQfrT6XxxK3MZzZHWuMoBl1VQpbaMpQFCvtKiJi9wDHGU+WcUxUvSN93QzHwvp6 VgLOEMB62F8UCD1PN7/OmV+Zu6WW+mRBQY8DDT1aL82u8KTsjs+85EzJpwe3wjlHH+T18u krtmX+A03+GrvXyLKQh7l5JzuIgmlQ6pOAHfgm8M7EHEc3qp/If8IrRCEyZJEQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=FJan1UMy; 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: -0.93 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=FJan1UMy; 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: CCAF22953B X-Spam-Score: -0.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: SKjMT5L7DMNV This is a multi-part message in MIME format. --------------2.34.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit --- 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(-) --------------2.34.1 Content-Type: text/x-patch; name="0020-Add-org-fold-related-tests.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0020-Add-org-fold-related-tests.patch" 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 24d96e58b..66ec97b49 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 364d783ee..3a1f213c1 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." @@ -8396,6 +8449,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.34.1--