From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sebastian Miele Newsgroups: gmane.emacs.bugs Subject: bug#65734: [BUG] kill-whole-line on folded subtrees [9.6.8 (release_9.6.8-3-g21171d @ /home/w/usr/emacs/0/29/0/lisp/org/)] Date: Sun, 10 Sep 2023 18:31:20 +0200 Message-ID: <87zg1u0yrp.fsf@whxvd.name> References: <87il8pao4l.fsf@whxvd.name> <87tts8vrpb.fsf@localhost> <83h6o84yz1.fsf@gnu.org> <875y4oaban.fsf@whxvd.name> <83bkeg4o1u.fsf@gnu.org> <87o7ifu2v8.fsf@localhost> <838r9j339x.fsf@gnu.org> <87tts78lve.fsf@whxvd.name> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22293"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Ihor Radchenko To: 65734@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 10 18:39:15 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qfNSt-0005bc-CB for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Sep 2023 18:39:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfNSe-0001ZD-Pt; Sun, 10 Sep 2023 12:39:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qfNSd-0001Z5-3g for bug-gnu-emacs@gnu.org; Sun, 10 Sep 2023 12:38:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfNSc-00068g-Ru for bug-gnu-emacs@gnu.org; Sun, 10 Sep 2023 12:38:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qfNSg-0000WW-55 for bug-gnu-emacs@gnu.org; Sun, 10 Sep 2023 12:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sebastian Miele Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Sep 2023 16:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65734 X-GNU-PR-Package: emacs Original-Received: via spool by 65734-submit@debbugs.gnu.org id=B65734.16943639181981 (code B ref 65734); Sun, 10 Sep 2023 16:39:02 +0000 Original-Received: (at 65734) by debbugs.gnu.org; 10 Sep 2023 16:38:38 +0000 Original-Received: from localhost ([127.0.0.1]:51173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfNSH-0000Vs-Ip for submit@debbugs.gnu.org; Sun, 10 Sep 2023 12:38:38 -0400 Original-Received: from mout-p-102.mailbox.org ([80.241.56.152]:52484) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfNSC-0000Va-ES for 65734@debbugs.gnu.org; Sun, 10 Sep 2023 12:38:36 -0400 Original-Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RkFs81zFnz9sSs; Sun, 10 Sep 2023 18:38:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whxvd.name; s=MBO0001; t=1694363900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Jx/Q54lAMlQqUaijOmeotsXwXaPnZSb6yBKxWstt4R4=; b=PslZeeIa851q7GkZT+Da3ctAqiM2DtmH89Xv9Y3Pp343U69tqYhKt8fUzrkZ76o/0FQqK+ RhaFhJD1F23nEcQViTCRbjyCh8A8J8BwgB5VAYBIHSWXzSZr4s3Ra8aX1+l2t8yvDUXkdy kFP0EP47PA3M8o6bcdKw7z/ZtOicKeffTyXQ1QVj7FZNXY0gGPZ4RX9PDMHzUwwhLF3JA5 ihJKhxpVmyZIzuXn1QaCRkKVXdQNnwQx+io0QaPbONhXQKAC9L1ViM/nqAMljBDu/8rI2a rYgFQHmfiX4LE2+OFUBZd5BPeLiXB10SjhiOMoneMkm7a6Je0CRl0kwC2YpLVA== In-reply-to: <87tts78lve.fsf@whxvd.name> X-Rspamd-Queue-Id: 4RkFs81zFnz9sSs X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269979 Archived-At: I removed emacs-orgmode@gnu.org from CC. > From: Sebastian Miele > Date: Wed, 2023-09-06 15:30 +0200 > > I will write the tests. And I will probably come up with an updated > version of the original patch. There is at least one cosmetic change. > And something else that I want to have tried. May take some time. Please have a look at the following patch. For now it contains three tests, two of them with :expected-result :failed. (They do not fail on the bug-fixed version of `kill-whole-line'.) There probably will be more tests and further questions. But for now, I would like to basically have a statement of whether the style of writing the tests goes in an acceptable direction. diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 28d8120f143..c15b0059536 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -22,6 +22,7 @@ ;;; Code: (require 'ert) +(require 'ert-x) (eval-when-compile (require 'cl-lib)) (defun simple-test--buffer-substrings () @@ -40,6 +41,112 @@ simple-test--dummy-buffer ,@body (with-no-warnings (simple-test--buffer-substrings)))) +(defconst simple-tests-point-tag "") +(defconst simple-tests-mark-tag "") + +(defun simple-tests--set-buffer-text-point-mark (description) + "Set the current buffers text, point and mark according to DESCRIPTION. + +Erase current buffer and insert DESCRIPTION. Set point to the +first occurrence of `simple-tests-point-tag' (\"\") in the +buffer, removing it. If there is no `simple-tests-point-tag', +set point to the beginning of the buffer. Similar for the active +mark (`simple-tests-mark-tag', \"\")." + (erase-buffer) + (insert description) + (goto-char (point-min)) + (when (search-forward simple-tests-mark-tag nil t) + (delete-char (- (length simple-tests-mark-tag))) + (push-mark (point) nil 'activate)) + (goto-char (point-min)) + (when (search-forward simple-tests-point-tag nil t) + (delete-char (- (length simple-tests-point-tag))))) + +(defun simple-tests--get-buffer-text-point-mark () + "Inverse of `simple-tests--set-buffer-text-point-mark'." + (if (not mark-active) + (concat (buffer-substring-no-properties (point-min) (point)) + simple-tests-point-tag + (buffer-substring-no-properties (point) (point-max))) + (if (< (mark) (point)) + (concat (buffer-substring-no-properties (point-min) (mark)) + simple-tests-mark-tag + (buffer-substring-no-properties (mark) (point)) + simple-tests-point-tag + (buffer-substring-no-properties (point) (point-max))) + (concat (buffer-substring-no-properties (point-min) (point)) + simple-tests-point-tag + (buffer-substring-no-properties (point) (mark)) + simple-tests-mark-tag + (buffer-substring-no-properties (mark) (point-max)))))) + +(ert-deftest simple-tests--buffer-text-point-mark-helpers () + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "") + (should (equal "" (buffer-substring-no-properties + (point-min) (point-max)))) + (should-not mark-active) + (should (equal 1 (point))) + (should (equal "" (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "") + (should (equal "" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 1 (point))) + (should (equal 1 (mark))) + (should (equal "" (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "") + (should (equal "" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 1 (point))) + (should (equal 1 (mark))) + (should (equal "" (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "AB") + (should (equal "AB" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 2 (point))) + (should (equal 2 (mark))) + (should (equal "AB" + (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "AB") + (should (equal "AB" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 2 (point))) + (should (equal 2 (mark))) + (should (equal "AB" + (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "AXB") + (should (equal "AXB" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 2 (point))) + (should (equal 3 (mark))) + (should (equal "AXB" + (simple-tests--get-buffer-text-point-mark)))) + + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "AXB") + (should (equal "AXB" (buffer-substring-no-properties + (point-min) (point-max)))) + (should mark-active) + (should (equal 3 (point))) + (should (equal 2 (mark))) + (should (equal "AXB" + (simple-tests--get-buffer-text-point-mark))))) + ;;; `count-words' (ert-deftest simple-test-count-words-bug-41761 () @@ -1046,5 +1153,109 @@ simple-tests-zap-to-char (with-zap-to-char-test "abcdeCXYZ" "XYZ" (zap-to-char 1 ?C 'interactive)))) + +;;; Tests for `kill-whole-line' + +(ert-deftest kill-whole-line-invisible () + :expected-result :failed + (cl-macrolet ((test (kill-whole-line-arg &rest expected-lines) + `(ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark + (string-join + '("* -2" "hidden" + "* -1" "hidden" + "* AB" "hidden" + "* 1" "hidden" + "* 2" "hidden" + "") + "\n")) + (ert-simulate-command '(org-mode)) + (ert-simulate-command '(org-fold-hide-sublevels 1)) + (ert-simulate-command + '(kill-whole-line ,kill-whole-line-arg)) + (should + (equal (string-join ',expected-lines "\n") + (simple-tests--get-buffer-text-point-mark)))))) + (test 0 + "* -2" "hidden" + "* -1" "hidden" + "" + "* 1" "hidden" + "* 2" "hidden" + "") + (test 1 + "* -2" "hidden" + "* -1" "hidden" + "* 1" "hidden" + "* 2" "hidden" + "") + (test 2 + "* -2" "hidden" + "* -1" "hidden" + "* 2" "hidden" + "") + (test 3 + "* -2" "hidden" + "* -1" "hidden" + "") + (test 9 + "* -2" "hidden" + "* -1" "hidden" + "") + (test -1 + "* -2" "hidden" + "* -1" "hidden" + "* 1" "hidden" + "* 2" "hidden" + "") + (test -2 + "* -2" "hidden" + "* 1" "hidden" + "* 2" "hidden" + "") + (test -3 + "" + "* 1" "hidden" + "* 2" "hidden" + "") + (test -9 + "" + "* 1" "hidden" + "* 2" "hidden" + ""))) + +(ert-deftest kill-whole-line-read-only () + :expected-result :failed + (cl-macrolet + ((test (kill-whole-line-arg expected-kill-lines expected-buffer-lines) + `(ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark + (string-join '("-2" "-1" "AB" "1" "2" "") "\n")) + (ert-simulate-command '(read-only-mode 1)) + (should-error (ert-simulate-command + '(kill-whole-line ,kill-whole-line-arg))) + (should (equal (string-join ,expected-kill-lines "\n") + (car kill-ring))) + (should (equal (string-join ,expected-buffer-lines "\n") + (simple-tests--get-buffer-text-point-mark)))))) + (test 0 '("AB") '("-2" "-1" "AB" "1" "2" "")) + (test 1 '("AB" "") '("-2" "-1" "AB" "1" "2" "")) + (test 2 '("AB" "1" "") '("-2" "-1" "AB" "1" "2" "")) + (test 3 '("AB" "1" "2" "") '("-2" "-1" "AB" "1" "2" "")) + (test 9 '("AB" "1" "2" "") '("-2" "-1" "AB" "1" "2" "")) + (test -1 '("" "AB") '("-2" "-1" "AB" "1" "2" "")) + (test -2 '("" "-1" "AB") '("-2" "-1" "AB" "1" "2" "")) + (test -3 '("-2" "-1" "AB") '("-2" "-1" "AB" "1" "2" "")) + (test -9 '("-2" "-1" "AB") '("-2" "-1" "AB" "1" "2" "")))) + +(ert-deftest kill-whole-line-after-other-kill () + (ert-with-test-buffer-selected nil + (simple-tests--set-buffer-text-point-mark "AXB") + (ert-simulate-command '(kill-region (mark) (point) 'region)) + (ert-simulate-command '(kill-whole-line)) + (should (equal "AXB" (car kill-ring))) + (should (equal "" + (simple-tests--get-buffer-text-point-mark))))) + (provide 'simple-test) ;;; simple-tests.el ends here