From 4f5eda4e508ef9b6fa873ff420b4308d6d661188 Mon Sep 17 00:00:00 2001 From: galaunay Date: Sat, 18 Apr 2020 14:03:57 +0200 Subject: [PATCH 1/3] Better docstring detection when folding --- elpy.el | 33 ++++++++++--------- test/elpy-folding-fold-all-comments-test.el | 9 +++-- test/elpy-folding-fold-all-docstrings-test.el | 6 ++-- test/elpy-folding-fold-blocks-test.el | 15 ++++++--- test/elpy-folding-fold-comments-test.el | 3 +- test/elpy-folding-fold-docstrings-test.el | 27 ++++++++------- test/elpy-folding-fold-leafs-test.el | 7 ++-- test/elpy-folding-fold-on-click-test.el | 6 ++-- ...folding-should-mark-foldable-lines-test.el | 9 +++-- test/test-helper.el | 6 ++++ 10 files changed, 76 insertions(+), 45 deletions(-) diff --git a/elpy.el b/elpy.el index 2ca69e123..8e39ad25c 100644 --- a/elpy.el +++ b/elpy.el @@ -3260,15 +3260,6 @@ display the current class and method instead." "^\\s-*[uU]?[rR]?\"\"\"\n?\\s-*" "Version of `hs-block-start-regexp' for docstrings.") -;; Herlpers -(defun elpy-info-docstring-p (&optional syntax-ppss) - "Return non-nil if point is in a docstring." - (save-excursion - (and (progn (python-nav-beginning-of-statement) - (looking-at "\\(\"\\|'\\)")) - (progn (forward-line -1) - (beginning-of-line) - (python-info-looking-at-beginning-of-defun))))) ;; Indicators (defun elpy-folding--display-code-line-counts (ov) "Display a folded region indicator with the number of folded lines. @@ -3415,11 +3406,11 @@ docstring body." "Hide the docstring at point." (hs-life-goes-on (let ((hs-block-start-regexp elpy-docstring-block-start-regexp)) - (when (and (elpy-info-docstring-p) (not (hs-already-hidden-p))) + (when (and (python-info-docstring-p) (not (hs-already-hidden-p))) (let (beg end line-beg line-end) ;; Get first doc line (if (not (save-excursion (forward-line -1) - (elpy-info-docstring-p))) + (python-info-docstring-p))) (setq beg (line-beginning-position)) (forward-line -1) (end-of-line) @@ -3432,7 +3423,7 @@ docstring body." (setq line-beg (line-number-at-pos)) ;; Get last line (if (not (save-excursion (forward-line 1) - (elpy-info-docstring-p))) + (python-info-docstring-p))) (progn (setq end (line-end-position)) (setq line-end (line-number-at-pos))) @@ -3447,7 +3438,7 @@ docstring body." "Show docstring at point." (hs-life-goes-on (let ((hs-block-start-regexp elpy-docstring-block-start-regexp)) - (when (elpy-info-docstring-p) + (when (python-info-docstring-p) (hs-show-block))))) (defvar-local elpy-folding-docstrings-hidden nil @@ -3464,7 +3455,7 @@ docstring body." (while (python-nav-forward-defun) (search-forward-regexp ")\\s-*:" nil t) (forward-line) - (when (and (elpy-info-docstring-p) + (when (and (python-info-docstring-p) (progn (beginning-of-line) (search-forward-regexp elpy-folding-docstring-regex @@ -3577,14 +3568,14 @@ If a region is selected, fold that region." (elpy-folding--hide-region (region-beginning) (region-end)) ;; Adapt starting regexp if on a docstring (let ((hs-block-start-regexp - (if (elpy-info-docstring-p) + (if (python-info-docstring-p) elpy-docstring-block-start-regexp hs-block-start-regexp))) ;; Hide or fold (cond ((hs-already-hidden-p) (hs-show-block)) - ((elpy-info-docstring-p) + ((python-info-docstring-p) (elpy-folding--hide-docstring-at-point)) (t (hs-hide-block)))))))) @@ -4029,5 +4020,15 @@ which we're looking." (rx eos)) output))) +(unless (fboundp 'python-info-docstring-p) + (defun python-info-docstring-p (&optional syntax-ppss) + "Return non-nil if point is in a docstring." + (save-excursion + (and (progn (python-nav-beginning-of-statement) + (looking-at "\\(\"\\|'\\)")) + (progn (forward-line -1) + (beginning-of-line) + (python-info-looking-at-beginning-of-defun)))))) + (provide 'elpy) ;;; elpy.el ends here diff --git a/test/elpy-folding-fold-all-comments-test.el b/test/elpy-folding-fold-all-comments-test.el index 517525bc5..dadc605c5 100644 --- a/test/elpy-folding-fold-all-comments-test.el +++ b/test/elpy-folding-fold-all-comments-test.el @@ -28,17 +28,20 @@ overlay) (should (= 6 (length overlays))) ;; first two lines comment - (setq overlay (nth 5 overlays)) + (setq overlay (elpy-get-overlay-at 49 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 49)) (should (= (overlay-end overlay) 83)) ;; second three lines comment - (setq overlay (nth 2 overlays)) + (setq overlay (elpy-get-overlay-at 184 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 184)) (should (= (overlay-end overlay) 229)) ;; third two lines comment - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 340 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 340)) (should (= (overlay-end overlay) 354))) diff --git a/test/elpy-folding-fold-all-docstrings-test.el b/test/elpy-folding-fold-all-docstrings-test.el index 5db8589e2..932437791 100644 --- a/test/elpy-folding-fold-all-docstrings-test.el +++ b/test/elpy-folding-fold-all-docstrings-test.el @@ -36,12 +36,14 @@ overlay) (should (= 6 (length overlays))) ;; First docstring - (setq overlay (nth 3 overlays)) + (setq overlay (elpy-get-overlay-at 97 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 97)) (should (= (overlay-end overlay) 124)) ;; Second docstring - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 206 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 206)) (should (= (overlay-end overlay) 280))) diff --git a/test/elpy-folding-fold-blocks-test.el b/test/elpy-folding-fold-blocks-test.el index 18c99fa0f..ee391d818 100644 --- a/test/elpy-folding-fold-blocks-test.el +++ b/test/elpy-folding-fold-blocks-test.el @@ -12,7 +12,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -40,7 +41,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -90,7 +92,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 3 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 54 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 54)) (should (or (= (overlay-end overlay) 100) @@ -124,7 +127,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 150) @@ -158,7 +162,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 29 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 29)) (should (or (= (overlay-end overlay) 150) diff --git a/test/elpy-folding-fold-comments-test.el b/test/elpy-folding-fold-comments-test.el index b96c0fcda..89d5b29a9 100644 --- a/test/elpy-folding-fold-comments-test.el +++ b/test/elpy-folding-fold-comments-test.el @@ -21,7 +21,8 @@ (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 111 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 111)) (should (= (overlay-end overlay) 156))) diff --git a/test/elpy-folding-fold-docstrings-test.el b/test/elpy-folding-fold-docstrings-test.el index 3235b03ee..d11a57eb7 100644 --- a/test/elpy-folding-fold-docstrings-test.el +++ b/test/elpy-folding-fold-docstrings-test.el @@ -30,7 +30,8 @@ ;; (buffer-substring (overlay-start overlay) ;; (overlay-end overlay)))) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 138 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 138)) (should (= (overlay-end overlay) 212))) @@ -70,7 +71,8 @@ (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 142 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 142)) (should (= (overlay-end overlay) 216))) @@ -114,8 +116,8 @@ " self.a = a" " self.b = b" " def bar(mess):" - " \" This is just _|_a string\"" " mess *= 2" + " \" This is just _|_a string\"" " print(mess)" " return mess" "var2 = foo(var1, 4)") @@ -143,12 +145,13 @@ "var2 = foo(var1, 4)") (python-mode) (elpy-mode) - (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 4 (length overlays))) - (dolist (overlay overlays) - (should-not (eq (overlay-get overlay 'hs) 'docstring)))))) + (let ((nmb-overlays (length (overlays-in (point-min) (point-max))))) + (elpy-folding-toggle-at-point) + (let* ((overlays (overlays-in (point-min) (point-max))) + overlay) + (should (= nmb-overlays (length overlays))) + (dolist (overlay overlays) + (should-not (eq (overlay-get overlay 'hs) 'docstring))))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings-3 () (elpy-testcase () @@ -171,7 +174,8 @@ (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 190) @@ -203,7 +207,8 @@ (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 229) diff --git a/test/elpy-folding-fold-leafs-test.el b/test/elpy-folding-fold-leafs-test.el index 6c6957cc3..9acb7a715 100644 --- a/test/elpy-folding-fold-leafs-test.el +++ b/test/elpy-folding-fold-leafs-test.el @@ -20,12 +20,15 @@ (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 6 (length overlays))) - (setq overlay (nth 3 overlays)) + + (setq overlay (elpy-get-overlay-at 57 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 57)) (should (or (= (overlay-end overlay) 87) (= (overlay-end overlay) 88))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 138 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 138)) (should (or (= (overlay-end overlay) 156) diff --git a/test/elpy-folding-fold-on-click-test.el b/test/elpy-folding-fold-on-click-test.el index cd3ef8769..6ac7ff28d 100644 --- a/test/elpy-folding-fold-on-click-test.el +++ b/test/elpy-folding-fold-on-click-test.el @@ -13,7 +13,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -43,7 +44,8 @@ (let* ((overlays (apply 'nconc (overlay-lists))) overlay) (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) diff --git a/test/elpy-folding-should-mark-foldable-lines-test.el b/test/elpy-folding-should-mark-foldable-lines-test.el index cc13116c1..6d1691095 100644 --- a/test/elpy-folding-should-mark-foldable-lines-test.el +++ b/test/elpy-folding-should-mark-foldable-lines-test.el @@ -24,17 +24,20 @@ overlay) (should (= 3 (length overlays))) ;; Second mark - (setq overlay (nth 2 overlays)) + (setq overlay (elpy-get-overlay-at 11 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 11)) (should (= (overlay-end overlay) 29)) ;; Second mark - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 30 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 30)) (should (= (overlay-end overlay) 57)) ;; Third mark - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 88 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 88)) (should (= (overlay-end overlay) 104))))) diff --git a/test/test-helper.el b/test/test-helper.el index e9f681017..82aa1622e 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -223,5 +223,11 @@ for that file." ,(buffer-string-with-point))) (put 'buffer-be 'ert-explainer 'buffer-be-explainer) +(defun elpy-get-overlay-at (start kind) + (dolist (tmp-overlay overlays overlay) + (when (and (= (overlay-start tmp-overlay) start) + (eq (overlay-get tmp-overlay 'hs) kind)) + (setq overlay tmp-overlay)))) + (setq yas-verbosity 0) (setq yas-snippet-dirs ()) From 8522bb7af5a286919e899f889453a8b99b70ff19 Mon Sep 17 00:00:00 2001 From: galaunay Date: Sun, 19 Apr 2020 17:55:06 +0200 Subject: [PATCH 2/3] Fix tests --- test/elpy-folding-fold-all-comments-test.el | 4 --- test/elpy-folding-fold-blocks-test.el | 22 ---------------- test/elpy-folding-fold-comments-test.el | 7 ----- test/elpy-folding-fold-docstrings-test.el | 29 +++++---------------- test/elpy-folding-fold-leafs-test.el | 4 --- test/elpy-folding-fold-on-click-test.el | 8 ------ 6 files changed, 6 insertions(+), 68 deletions(-) diff --git a/test/elpy-folding-fold-all-comments-test.el b/test/elpy-folding-fold-all-comments-test.el index dadc605c5..d5a00b74e 100644 --- a/test/elpy-folding-fold-all-comments-test.el +++ b/test/elpy-folding-fold-all-comments-test.el @@ -26,7 +26,6 @@ (elpy-folding-toggle-comments) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 6 (length overlays))) ;; first two lines comment (setq overlay (elpy-get-overlay-at 49 'comment)) (should overlay) @@ -49,8 +48,5 @@ (should (= (point) 177)) ;; Unfold all comments (elpy-folding-toggle-comments) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 177)))) diff --git a/test/elpy-folding-fold-blocks-test.el b/test/elpy-folding-fold-blocks-test.el index ee391d818..6afd37113 100644 --- a/test/elpy-folding-fold-blocks-test.el +++ b/test/elpy-folding-fold-blocks-test.el @@ -11,7 +11,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) (setq overlay (elpy-get-overlay-at 25 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -21,9 +20,6 @@ (should (= (point) 14)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -40,7 +36,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) (setq overlay (elpy-get-overlay-at 25 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -50,9 +45,6 @@ (should (= (point) 14)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -69,8 +61,6 @@ (python-mode) (elpy-mode) (elpy-folding-toggle-at-point) - (let ((overlays (apply 'nconc (overlay-lists)))) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 49)))) @@ -91,7 +81,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 3 (length overlays))) (setq overlay (elpy-get-overlay-at 54 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -101,9 +90,6 @@ (should (= (point) 43)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 2 (length overlays)))) ;; Position (should (= (point) 43)))) @@ -126,7 +112,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 104 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -136,9 +121,6 @@ (should (= (point) 93)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 93)))) @@ -161,7 +143,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 29 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -171,8 +152,5 @@ (should (= (point) 16)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 16)))) diff --git a/test/elpy-folding-fold-comments-test.el b/test/elpy-folding-fold-comments-test.el index 89d5b29a9..19ba11864 100644 --- a/test/elpy-folding-fold-comments-test.el +++ b/test/elpy-folding-fold-comments-test.el @@ -20,7 +20,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 111 'comment)) (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) @@ -29,9 +28,6 @@ (should (= (point) 92)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 92)))) @@ -53,7 +49,4 @@ (python-mode) (elpy-mode) (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) (should (= (point) 112)))) diff --git a/test/elpy-folding-fold-docstrings-test.el b/test/elpy-folding-fold-docstrings-test.el index d11a57eb7..acaa8c20f 100644 --- a/test/elpy-folding-fold-docstrings-test.el +++ b/test/elpy-folding-fold-docstrings-test.el @@ -23,13 +23,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - ;; (dolist (overlay overlays) - ;; (message "overlay from %s to %s on: %s" - ;; (overlay-start overlay) - ;; (overlay-end overlay) - ;; (buffer-substring (overlay-start overlay) - ;; (overlay-end overlay)))) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 138 'docstring)) (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) @@ -38,9 +31,6 @@ (should (= (point) 109)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 109)))) @@ -70,7 +60,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 142 'docstring)) (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) @@ -79,9 +68,6 @@ (should (= (point) 117)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 117)))) @@ -103,9 +89,9 @@ (python-mode) (elpy-mode) (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))))) + (let* ((overlays (overlays-in (point-min) (point-max)))) + (dolist (overlay overlays) + (should-not (overlay-get overlay 'hs)))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings () (elpy-testcase () @@ -124,9 +110,9 @@ (python-mode) (elpy-mode) (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))))) + (let* ((overlays (overlays-in (point-min) (point-max)))) + (dolist (overlay overlays) + (should-not (overlay-get overlay 'hs)))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings-2 () (elpy-testcase () @@ -149,7 +135,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= nmb-overlays (length overlays))) (dolist (overlay overlays) (should-not (eq (overlay-get overlay 'hs) 'docstring))))))) @@ -173,7 +158,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 104 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -206,7 +190,6 @@ (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) (setq overlay (elpy-get-overlay-at 104 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) diff --git a/test/elpy-folding-fold-leafs-test.el b/test/elpy-folding-fold-leafs-test.el index 9acb7a715..ddceed0ce 100644 --- a/test/elpy-folding-fold-leafs-test.el +++ b/test/elpy-folding-fold-leafs-test.el @@ -19,7 +19,6 @@ (elpy-folding-hide-leafs) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 6 (length overlays))) (setq overlay (elpy-get-overlay-at 57 'code)) (should overlay) @@ -37,8 +36,5 @@ (should (= (point) 151)) ;; Unfold (hs-show-all) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 4 (length overlays)))) ;; Position (should (= (point) 151)))) diff --git a/test/elpy-folding-fold-on-click-test.el b/test/elpy-folding-fold-on-click-test.el index 6ac7ff28d..15ac01593 100644 --- a/test/elpy-folding-fold-on-click-test.el +++ b/test/elpy-folding-fold-on-click-test.el @@ -12,7 +12,6 @@ (elpy-folding--click-fringe nil)) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) (setq overlay (elpy-get-overlay-at 25 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -23,9 +22,6 @@ ;; Unfold (mletf* ((mouse-set-point (event) (goto-char (point)))) (elpy-folding--click-fringe nil)) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -43,7 +39,6 @@ (elpy-folding--click-fringe nil)) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) (setq overlay (elpy-get-overlay-at 25 'code)) (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) @@ -57,8 +52,5 @@ (posn-point (position) (point)) (window-buffer (window) (current-buffer))) (elpy-folding--click-text nil)) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 25)))) From eb46e8e1b45c0277f615951c2d1a8ddc6d749020 Mon Sep 17 00:00:00 2001 From: galaunay Date: Fri, 1 May 2020 23:17:22 +0200 Subject: [PATCH 3/3] FIx-tests for emacs 24 --- test/elpy-folding-fold-docstrings-test.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/elpy-folding-fold-docstrings-test.el b/test/elpy-folding-fold-docstrings-test.el index acaa8c20f..979d366d2 100644 --- a/test/elpy-folding-fold-docstrings-test.el +++ b/test/elpy-folding-fold-docstrings-test.el @@ -95,6 +95,7 @@ (ert-deftest elpy-fold-at-point-should-NOT-fold-strings () (elpy-testcase () + (add-to-list 'elpy-modules 'elpy-module-folding) (set-buffer-string-with-point "var1 = 45" "class foo(object):" @@ -109,10 +110,12 @@ "var2 = foo(var1, 4)") (python-mode) (elpy-mode) - (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max)))) - (dolist (overlay overlays) - (should-not (overlay-get overlay 'hs)))))) + (let ((nmb-overlays (length (overlays-in (point-min) (point-max))))) + (elpy-folding-toggle-at-point) + (let* ((overlays (overlays-in (point-min) (point-max))) + overlay) + (dolist (overlay overlays) + (should-not (eq (overlay-get overlay 'hs) 'docstring))))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings-2 () (elpy-testcase () @@ -125,7 +128,7 @@ " self.b = b" " def bar(mess):" " mess *= 2" - " \" This is just _|_a string\"" + " \"\"\" This is just _|_a string\"\"\"" " print(mess)" " return mess" "var2 = foo(var1, 4)")