diff options
| author | Fabián Ezequiel Gallina | 2015-01-30 00:19:55 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2015-01-30 00:19:55 -0300 |
| commit | 41c3b9241cd78a1eaeb159572b6f4e546b1f8d7b (patch) | |
| tree | 1a1f80fc9e095acaf9ae2ffa969ddddb17ade7f9 /test/automated/python-tests.el | |
| parent | 868df451530c294cff3d4ccb98873626aa8105df (diff) | |
| download | emacs-41c3b9241cd78a1eaeb159572b6f4e546b1f8d7b.tar.gz emacs-41c3b9241cd78a1eaeb159572b6f4e546b1f8d7b.zip | |
* lisp/progmodes/python.el (python-indent-context): Respect user
indentation after comment.
* test/automated/python-tests.el (python-indent-pep8-1)
(python-indent-pep8-2, python-indent-pep8-3)
(python-indent-after-comment-2): Fix tests.
(python-indent-after-comment-3): New test.
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 5bddfe845ed..4972731d0d2 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -177,7 +177,7 @@ foo = long_function_name(var_one, var_two, | |||
| 177 | (should (eq (car (python-indent-context)) :no-indent)) | 177 | (should (eq (car (python-indent-context)) :no-indent)) |
| 178 | (should (= (python-indent-calculate-indentation) 0)) | 178 | (should (= (python-indent-calculate-indentation) 0)) |
| 179 | (python-tests-look-at "foo = long_function_name(var_one, var_two,") | 179 | (python-tests-look-at "foo = long_function_name(var_one, var_two,") |
| 180 | (should (eq (car (python-indent-context)) :after-line)) | 180 | (should (eq (car (python-indent-context)) :after-comment)) |
| 181 | (should (= (python-indent-calculate-indentation) 0)) | 181 | (should (= (python-indent-calculate-indentation) 0)) |
| 182 | (python-tests-look-at "var_three, var_four)") | 182 | (python-tests-look-at "var_three, var_four)") |
| 183 | (should (eq (car (python-indent-context)) :inside-paren)) | 183 | (should (eq (car (python-indent-context)) :inside-paren)) |
| @@ -195,7 +195,7 @@ def long_function_name( | |||
| 195 | (should (eq (car (python-indent-context)) :no-indent)) | 195 | (should (eq (car (python-indent-context)) :no-indent)) |
| 196 | (should (= (python-indent-calculate-indentation) 0)) | 196 | (should (= (python-indent-calculate-indentation) 0)) |
| 197 | (python-tests-look-at "def long_function_name(") | 197 | (python-tests-look-at "def long_function_name(") |
| 198 | (should (eq (car (python-indent-context)) :after-line)) | 198 | (should (eq (car (python-indent-context)) :after-comment)) |
| 199 | (should (= (python-indent-calculate-indentation) 0)) | 199 | (should (= (python-indent-calculate-indentation) 0)) |
| 200 | (python-tests-look-at "var_one, var_two, var_three,") | 200 | (python-tests-look-at "var_one, var_two, var_three,") |
| 201 | (should (eq (car (python-indent-context)) | 201 | (should (eq (car (python-indent-context)) |
| @@ -221,7 +221,7 @@ foo = long_function_name( | |||
| 221 | (should (eq (car (python-indent-context)) :no-indent)) | 221 | (should (eq (car (python-indent-context)) :no-indent)) |
| 222 | (should (= (python-indent-calculate-indentation) 0)) | 222 | (should (= (python-indent-calculate-indentation) 0)) |
| 223 | (python-tests-look-at "foo = long_function_name(") | 223 | (python-tests-look-at "foo = long_function_name(") |
| 224 | (should (eq (car (python-indent-context)) :after-line)) | 224 | (should (eq (car (python-indent-context)) :after-comment)) |
| 225 | (should (= (python-indent-calculate-indentation) 0)) | 225 | (should (= (python-indent-calculate-indentation) 0)) |
| 226 | (python-tests-look-at "var_one, var_two,") | 226 | (python-tests-look-at "var_one, var_two,") |
| 227 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 227 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| @@ -286,10 +286,10 @@ class Blag(object): | |||
| 286 | def func(arg): | 286 | def func(arg): |
| 287 | # I don't do much | 287 | # I don't do much |
| 288 | return arg | 288 | return arg |
| 289 | # This comment is badly indented just because. | 289 | # This comment is badly indented because the user forced so. |
| 290 | # But we won't mess with the user in this line. | 290 | # At this line python.el wont dedent, user is always right. |
| 291 | 291 | ||
| 292 | now_we_do_mess_cause_this_is_not_a_comment = 1 | 292 | comment_wins_over_ender = True |
| 293 | 293 | ||
| 294 | # yeah, that. | 294 | # yeah, that. |
| 295 | " | 295 | " |
| @@ -301,28 +301,49 @@ now_we_do_mess_cause_this_is_not_a_comment = 1 | |||
| 301 | ;; the rules won't apply here. | 301 | ;; the rules won't apply here. |
| 302 | (should (eq (car (python-indent-context)) :after-block-start)) | 302 | (should (eq (car (python-indent-context)) :after-block-start)) |
| 303 | (should (= (python-indent-calculate-indentation) 4)) | 303 | (should (= (python-indent-calculate-indentation) 4)) |
| 304 | (python-tests-look-at "# This comment is badly") | 304 | (python-tests-look-at "# This comment is badly indented") |
| 305 | (should (eq (car (python-indent-context)) :after-block-end)) | 305 | (should (eq (car (python-indent-context)) :after-block-end)) |
| 306 | ;; The return keyword moves indentation backwards 4 spaces, but | 306 | ;; The return keyword do make indentation lose a level... |
| 307 | ;; let's assume this comment was placed there because the user | ||
| 308 | ;; wanted to (manually adding spaces or whatever). | ||
| 309 | (should (= (python-indent-calculate-indentation) 0)) | 307 | (should (= (python-indent-calculate-indentation) 0)) |
| 310 | (python-tests-look-at "# but we won't mess") | 308 | ;; ...but the current indentation was forced by the user. |
| 309 | (python-tests-look-at "# At this line python.el wont dedent") | ||
| 311 | (should (eq (car (python-indent-context)) :after-comment)) | 310 | (should (eq (car (python-indent-context)) :after-comment)) |
| 312 | (should (= (python-indent-calculate-indentation) 4)) | 311 | (should (= (python-indent-calculate-indentation) 4)) |
| 313 | ;; Behave the same for blank lines: potentially a comment. | 312 | ;; Should behave the same for blank lines: potentially a comment. |
| 314 | (forward-line 1) | 313 | (forward-line 1) |
| 315 | (should (eq (car (python-indent-context)) :after-comment)) | 314 | (should (eq (car (python-indent-context)) :after-comment)) |
| 316 | (should (= (python-indent-calculate-indentation) 4)) | 315 | (should (= (python-indent-calculate-indentation) 4)) |
| 317 | (python-tests-look-at "now_we_do_mess") | 316 | (python-tests-look-at "comment_wins_over_ender") |
| 318 | ;; Here is where comment indentation starts to get ignored and | 317 | ;; The comment won over the ender because the user said so. |
| 319 | ;; where the user can't freely indent anymore. | 318 | (should (eq (car (python-indent-context)) :after-comment)) |
| 320 | (should (eq (car (python-indent-context)) :after-block-end)) | 319 | (should (= (python-indent-calculate-indentation) 4)) |
| 321 | (should (= (python-indent-calculate-indentation) 0)) | 320 | ;; The indentation calculated fine for the assignment, but the user |
| 321 | ;; choose to force it back to the first column. Next line should | ||
| 322 | ;; be aware of that. | ||
| 322 | (python-tests-look-at "# yeah, that.") | 323 | (python-tests-look-at "# yeah, that.") |
| 323 | (should (eq (car (python-indent-context)) :after-line)) | 324 | (should (eq (car (python-indent-context)) :after-line)) |
| 324 | (should (= (python-indent-calculate-indentation) 0)))) | 325 | (should (= (python-indent-calculate-indentation) 0)))) |
| 325 | 326 | ||
| 327 | (ert-deftest python-indent-after-comment-3 () | ||
| 328 | "Test after-comment in buggy case." | ||
| 329 | (python-tests-with-temp-buffer | ||
| 330 | " | ||
| 331 | class A(object): | ||
| 332 | |||
| 333 | def something(self, arg): | ||
| 334 | if True: | ||
| 335 | return arg | ||
| 336 | |||
| 337 | # A comment | ||
| 338 | |||
| 339 | @adecorator | ||
| 340 | def method(self, a, b): | ||
| 341 | pass | ||
| 342 | " | ||
| 343 | (python-tests-look-at "@adecorator") | ||
| 344 | (should (eq (car (python-indent-context)) :after-comment)) | ||
| 345 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 346 | |||
| 326 | (ert-deftest python-indent-inside-paren-1 () | 347 | (ert-deftest python-indent-inside-paren-1 () |
| 327 | "The most simple inside-paren case that shouldn't fail." | 348 | "The most simple inside-paren case that shouldn't fail." |
| 328 | (python-tests-with-temp-buffer | 349 | (python-tests-with-temp-buffer |