aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/progmodes/python-tests.el
diff options
context:
space:
mode:
authorkobarity2022-08-17 12:44:56 +0200
committerLars Ingebrigtsen2022-08-17 12:44:56 +0200
commitaf4cfb519415ed3c1d6d036aac908e4f9ee383eb (patch)
treeaa03cf5584fee7e15fa62743ee5852caac6d88b3 /test/lisp/progmodes/python-tests.el
parent8f784a27667fbebdf320388ef2ec46ae67f69230 (diff)
downloademacs-af4cfb519415ed3c1d6d036aac908e4f9ee383eb.tar.gz
emacs-af4cfb519415ed3c1d6d036aac908e4f9ee383eb.zip
Add Python blocks support for hideshow
* lisp/progmodes/python.el (python-nav-beginning-of-block-regexp): New variable. (python-hideshow-forward-sexp-function): Change to call `python-nav-end-of-block'. (python-hideshow-find-next-block): New function to be used as FIND-NEXT-BLOCK-FUNC in `hs-special-modes-alist'. (python-info-looking-at-beginning-of-block): New function to be used as LOOKING-AT-BLOCK-START-P-FUNC in `hs-special-modes-alist'. (python-mode): Change settings of `hs-special-modes-alist'. * test/lisp/progmodes/python-tests.el (python-hideshow-hide-levels-1): Fix to keep empty lines. (python-info-looking-at-beginning-of-block-1) (python-hideshow-hide-levels-3, python-hideshow-hide-levels-4) (python-hideshow-hide-all-1, python-hideshow-hide-all-2) (python-hideshow-hide-all-3, python-hideshow-hide-block-1): New tests (bug#56635).
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
-rw-r--r--test/lisp/progmodes/python-tests.el197
1 files changed, 196 insertions, 1 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 9e8fa7f5520..608ce548e78 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -5598,6 +5598,39 @@ def \\
5598 (should (not (python-info-looking-at-beginning-of-defun))) 5598 (should (not (python-info-looking-at-beginning-of-defun)))
5599 (should (not (python-info-looking-at-beginning-of-defun nil t))))) 5599 (should (not (python-info-looking-at-beginning-of-defun nil t)))))
5600 5600
5601(ert-deftest python-info-looking-at-beginning-of-block-1 ()
5602 (python-tests-with-temp-buffer
5603 "
5604def f():
5605 if True:
5606 pass
5607 l = [x * 2
5608 for x in range(5)
5609 if x < 3]
5610# if False:
5611\"\"\"
5612if 0:
5613\"\"\"
5614"
5615 (python-tests-look-at "def f():")
5616 (should (python-info-looking-at-beginning-of-block))
5617 (forward-char)
5618 (should (not (python-info-looking-at-beginning-of-block)))
5619 (python-tests-look-at "if True:")
5620 (should (python-info-looking-at-beginning-of-block))
5621 (forward-char)
5622 (should (not (python-info-looking-at-beginning-of-block)))
5623 (beginning-of-line)
5624 (should (python-info-looking-at-beginning-of-block))
5625 (python-tests-look-at "for x")
5626 (should (not (python-info-looking-at-beginning-of-block)))
5627 (python-tests-look-at "if x < 3")
5628 (should (not (python-info-looking-at-beginning-of-block)))
5629 (python-tests-look-at "if False:")
5630 (should (not (python-info-looking-at-beginning-of-block)))
5631 (python-tests-look-at "if 0:")
5632 (should (not (python-info-looking-at-beginning-of-block)))))
5633
5601(ert-deftest python-info-current-line-comment-p-1 () 5634(ert-deftest python-info-current-line-comment-p-1 ()
5602 (python-tests-with-temp-buffer 5635 (python-tests-with-temp-buffer
5603 " 5636 "
@@ -6051,8 +6084,11 @@ class SomeClass:
6051class SomeClass: 6084class SomeClass:
6052 6085
6053 def __init__(self, arg, kwarg=1): 6086 def __init__(self, arg, kwarg=1):
6087
6054 def filter(self, nums): 6088 def filter(self, nums):
6055 def __str__(self):")))) 6089
6090 def __str__(self):
6091"))))
6056 (or enabled (hs-minor-mode -1))))) 6092 (or enabled (hs-minor-mode -1)))))
6057 6093
6058(ert-deftest python-hideshow-hide-levels-2 () 6094(ert-deftest python-hideshow-hide-levels-2 ()
@@ -6098,6 +6134,165 @@ class SomeClass:
6098")))) 6134"))))
6099 (or enabled (hs-minor-mode -1))))) 6135 (or enabled (hs-minor-mode -1)))))
6100 6136
6137(ert-deftest python-hideshow-hide-levels-3 ()
6138 "Should hide all blocks."
6139 (python-tests-with-temp-buffer
6140 "
6141def f():
6142 if 0:
6143 l = [i for i in range(5)
6144 if i < 3]
6145 abc = o.match(1, 2, 3)
6146
6147def g():
6148 pass
6149"
6150 (hs-minor-mode 1)
6151 (hs-hide-level 1)
6152 (should
6153 (string=
6154 (python-tests-visible-string)
6155 "
6156def f():
6157
6158def g():
6159"))))
6160
6161(ert-deftest python-hideshow-hide-levels-4 ()
6162 "Should hide 2nd level block."
6163 (python-tests-with-temp-buffer
6164 "
6165def f():
6166 if 0:
6167 l = [i for i in range(5)
6168 if i < 3]
6169 abc = o.match(1, 2, 3)
6170
6171def g():
6172 pass
6173"
6174 (hs-minor-mode 1)
6175 (hs-hide-level 2)
6176 (should
6177 (string=
6178 (python-tests-visible-string)
6179 "
6180def f():
6181 if 0:
6182
6183def g():
6184 pass
6185"))))
6186
6187(ert-deftest python-hideshow-hide-all-1 ()
6188 "Should hide all blocks."
6189 (python-tests-with-temp-buffer
6190 "if 0:
6191
6192 aaa
6193 l = [i for i in range(5)
6194 if i < 3]
6195 ccc
6196 abc = o.match(1, 2, 3)
6197 ddd
6198
6199def f():
6200 pass
6201"
6202 (hs-minor-mode 1)
6203 (hs-hide-all)
6204 (should
6205 (string=
6206 (python-tests-visible-string)
6207 "if 0:
6208
6209def f():
6210"))))
6211
6212(ert-deftest python-hideshow-hide-all-2 ()
6213 "Should hide comments."
6214 (python-tests-with-temp-buffer
6215 "
6216# Multi line
6217# comment
6218
6219\"\"\"
6220# Multi line
6221# string
6222\"\"\"
6223"
6224 (hs-minor-mode 1)
6225 (hs-hide-all)
6226 (should
6227 (string=
6228 (python-tests-visible-string)
6229 "
6230# Multi line
6231
6232\"\"\"
6233# Multi line
6234# string
6235\"\"\"
6236"))))
6237
6238(ert-deftest python-hideshow-hide-all-3 ()
6239 "Should not hide comments when `hs-hide-comments-when-hiding-all' is nil."
6240 (python-tests-with-temp-buffer
6241 "
6242# Multi line
6243# comment
6244
6245\"\"\"
6246# Multi line
6247# string
6248\"\"\"
6249"
6250 (hs-minor-mode 1)
6251 (let ((hs-hide-comments-when-hiding-all nil))
6252 (hs-hide-all))
6253 (should
6254 (string=
6255 (python-tests-visible-string)
6256 "
6257# Multi line
6258# comment
6259
6260\"\"\"
6261# Multi line
6262# string
6263\"\"\"
6264"))))
6265
6266(ert-deftest python-hideshow-hide-block-1 ()
6267 "Should hide current block."
6268 (python-tests-with-temp-buffer
6269 "
6270if 0:
6271
6272 aaa
6273 l = [i for i in range(5)
6274 if i < 3]
6275 ccc
6276 abc = o.match(1, 2, 3)
6277 ddd
6278
6279def f():
6280 pass
6281"
6282 (hs-minor-mode 1)
6283 (python-tests-look-at "ddd")
6284 (forward-line)
6285 (hs-hide-block)
6286 (should
6287 (string=
6288 (python-tests-visible-string)
6289 "
6290if 0:
6291
6292def f():
6293 pass
6294"))))
6295
6101 6296
6102(ert-deftest python-tests--python-nav-end-of-statement--infloop () 6297(ert-deftest python-tests--python-nav-end-of-statement--infloop ()
6103 "Checks that `python-nav-end-of-statement' doesn't infloop in a 6298 "Checks that `python-nav-end-of-statement' doesn't infloop in a