diff options
| author | Fabián Ezequiel Gallina | 2013-12-12 02:37:09 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2013-12-12 02:37:09 -0300 |
| commit | 09faee72dd0743a5b46444b5e917ee1259843788 (patch) | |
| tree | 13f65f15d978b036b9fca79cd3803220f1fcf1dd /test/automated/python-tests.el | |
| parent | 139f528442726be5160120fb13e68240982de92f (diff) | |
| download | emacs-09faee72dd0743a5b46444b5e917ee1259843788.tar.gz emacs-09faee72dd0743a5b46444b5e917ee1259843788.zip | |
* lisp/progmodes/python.el (python-indent-context)
(python-indent-calculate-indentation): Fix auto-identation
behavior for comment blocks.
* test/automated/python-tests.el (python-indent-after-comment-1)
(python-indent-after-comment-2): New tests.
Fixes: debbugs:15916
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 58a839a5500..84be598b6dd 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -199,6 +199,83 @@ foo = long_function_name( | |||
| 199 | (should (eq (car (python-indent-context)) 'inside-paren)) | 199 | (should (eq (car (python-indent-context)) 'inside-paren)) |
| 200 | (should (= (python-indent-calculate-indentation) 4)))) | 200 | (should (= (python-indent-calculate-indentation) 4)))) |
| 201 | 201 | ||
| 202 | (ert-deftest python-indent-after-comment-1 () | ||
| 203 | "The most simple after-comment case that shouldn't fail." | ||
| 204 | (python-tests-with-temp-buffer | ||
| 205 | "# Contents will be modified to correct indentation | ||
| 206 | class Blag(object): | ||
| 207 | def _on_child_complete(self, child_future): | ||
| 208 | if self.in_terminal_state(): | ||
| 209 | pass | ||
| 210 | # We only complete when all our async children have entered a | ||
| 211 | # terminal state. At that point, if any child failed, we fail | ||
| 212 | # with the exception with which the first child failed. | ||
| 213 | " | ||
| 214 | (python-tests-look-at "# We only complete") | ||
| 215 | (should (eq (car (python-indent-context)) 'after-line)) | ||
| 216 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 217 | (python-tests-look-at "# terminal state") | ||
| 218 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 219 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 220 | (python-tests-look-at "# with the exception") | ||
| 221 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 222 | ;; This one indents relative to previous block, even given the fact | ||
| 223 | ;; that it was under-indented. | ||
| 224 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 225 | (python-tests-look-at "# terminal state" -1) | ||
| 226 | ;; It doesn't hurt to check again. | ||
| 227 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 228 | (python-indent-line) | ||
| 229 | (should (= (current-indentation) 8)) | ||
| 230 | (python-tests-look-at "# with the exception") | ||
| 231 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 232 | ;; Now everything should be lined up. | ||
| 233 | (should (= (python-indent-calculate-indentation) 8)))) | ||
| 234 | |||
| 235 | (ert-deftest python-indent-after-comment-2 () | ||
| 236 | "Test after-comment in weird cases." | ||
| 237 | (python-tests-with-temp-buffer | ||
| 238 | "# Contents will be modified to correct indentation | ||
| 239 | def func(arg): | ||
| 240 | # I don't do much | ||
| 241 | return arg | ||
| 242 | # This comment is badly indented just because. | ||
| 243 | # But we won't mess with the user in this line. | ||
| 244 | |||
| 245 | now_we_do_mess_cause_this_is_not_a_comment = 1 | ||
| 246 | |||
| 247 | # yeah, that. | ||
| 248 | " | ||
| 249 | (python-tests-look-at "# I don't do much") | ||
| 250 | (should (eq (car (python-indent-context)) 'after-beginning-of-block)) | ||
| 251 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 252 | (python-tests-look-at "return arg") | ||
| 253 | ;; Comment here just gets ignored, this line is not a comment so | ||
| 254 | ;; the rules won't apply here. | ||
| 255 | (should (eq (car (python-indent-context)) 'after-beginning-of-block)) | ||
| 256 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 257 | (python-tests-look-at "# This comment is badly") | ||
| 258 | (should (eq (car (python-indent-context)) 'after-line)) | ||
| 259 | ;; The return keyword moves indentation backwards 4 spaces, but | ||
| 260 | ;; let's assume this comment was placed there because the user | ||
| 261 | ;; wanted to (manually adding spaces or whatever). | ||
| 262 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 263 | (python-tests-look-at "# but we won't mess") | ||
| 264 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 265 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 266 | ;; Behave the same for blank lines: potentially a comment. | ||
| 267 | (forward-line 1) | ||
| 268 | (should (eq (car (python-indent-context)) 'after-comment)) | ||
| 269 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 270 | (python-tests-look-at "now_we_do_mess") | ||
| 271 | ;; Here is where comment indentation starts to get ignored and | ||
| 272 | ;; where the user can't freely indent anymore. | ||
| 273 | (should (eq (car (python-indent-context)) 'after-line)) | ||
| 274 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 275 | (python-tests-look-at "# yeah, that.") | ||
| 276 | (should (eq (car (python-indent-context)) 'after-line)) | ||
| 277 | (should (= (python-indent-calculate-indentation) 0)))) | ||
| 278 | |||
| 202 | (ert-deftest python-indent-inside-paren-1 () | 279 | (ert-deftest python-indent-inside-paren-1 () |
| 203 | "The most simple inside-paren case that shouldn't fail." | 280 | "The most simple inside-paren case that shouldn't fail." |
| 204 | (python-tests-with-temp-buffer | 281 | (python-tests-with-temp-buffer |