1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-06 11:50:51 -08:00

; * lisp/progmodes/hideshow.el (hs-cycle): Fix regression. (Bug#79983)

* test/lisp/progmodes/hideshow-tests.el
(hideshow-cycle-with-delimiters)
(hideshow-cycle-without-delimiters)
(hideshow-check-unbalanced-parens): Add new tests.
This commit is contained in:
Elías Gabriel Pérez 2025-12-10 10:05:44 -06:00 committed by Juri Linkov
parent cc4f23302c
commit ef73f5c254
2 changed files with 87 additions and 2 deletions

View file

@ -1425,7 +1425,7 @@ only blocks which are that many levels below the level of point."
(message "Hide %d level" level))
(t
(let* (hs-allow-nesting
(block (hs-block-positions nil :ad-end))
(block (hs-block-positions :ad-beg :ad-end))
(ov (seq-find
(lambda (o)
(and (eq (overlay-get o 'invisible) 'hs)))
@ -1436,7 +1436,8 @@ only blocks which are that many levels below the level of point."
(hs-hide-block)
(message "Hide block and nested blocks"))
;; Hide the children blocks if the parent block is hidden
((= (overlay-end ov) (cadr block))
((and (= (overlay-start ov) (car block))
(= (overlay-end ov) (cadr block)))
(apply #'hs-hide-level-recursive 1 block)
(message "Hide first nested blocks"))
;; Otherwise show all in the parent block, we cannot use

View file

@ -342,6 +342,90 @@ main()
(funcall call-at "}")
(should (string= (hideshow-tests-visible-string) contents)))))
(ert-deftest hideshow-cycle-with-delimiters ()
"Should cycle the visibility of a block with delimiters."
(let ((contents "
int
main ()
{
{
{
}
}
}
"))
(hideshow-tests-with-temp-buffer
c-mode
contents
(hideshow-tests-look-at "{")
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
"
int
main ()
{}
"))
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
"
int
main ()
{
{}
}
"))
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
contents)))))
(ert-deftest hideshow-cycle-without-delimiters ()
"Should cycle the visibility of a block without delimiters."
(let ((contents "
def test1 ():
def test2 ():
def test3():
"))
(hideshow-tests-with-temp-buffer
python-mode
contents
(hideshow-tests-look-at "test1")
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
"
def test1 ():
"))
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
"
def test1 ():
def test2 ():
"))
(hs-cycle 1)
(should (string=
(hideshow-tests-visible-string)
contents)))))
(ert-deftest hideshow-check-unbalanced-parens ()
(let ((contents "
(defun test1 ())
(defun test2
"))
(hideshow-tests-with-temp-buffer
c-mode
contents
(hideshow-tests-look-at "test1")
(beginning-of-line)
(should (hs-block-positions))
(hideshow-tests-look-at "test2")
(beginning-of-line)
(should-not (hs-block-positions)))))
(provide 'hideshow-tests)
;;; hideshow-tests.el ends here