aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJoakim Verona2015-02-01 00:37:46 +0100
committerJoakim Verona2015-02-01 00:37:46 +0100
commit69815dfe3704f8a8c733843f1fd04546cbb0f4d0 (patch)
treecee6910753a51b9a5ee88e2431c9bcad099e8ba8 /test
parent4edad429cafb2f0b1fda028be58367286ab04f1c (diff)
parenta2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e (diff)
downloademacs-69815dfe3704f8a8c733843f1fd04546cbb0f4d0.tar.gz
emacs-69815dfe3704f8a8c733843f1fd04546cbb0f4d0.zip
Merge branch 'master' into xwidget
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog40
-rw-r--r--test/automated/core-elisp-tests.el7
-rw-r--r--test/automated/eieio-tests.el5
-rw-r--r--test/automated/python-tests.el582
-rw-r--r--test/automated/regexp-tests.el2
5 files changed, 492 insertions, 144 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 61ab8b6595a..a9834cc0f3f 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,38 @@
12015-01-31 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * automated/eieio-tests.el (eieio-test-23-inheritance-check): Simplify.
4
52015-01-30 Stefan Monnier <monnier@iro.umontreal.ca>
6
7 * automated/core-elisp-tests.el (core-elisp-tests-3-backquote): New test.
8
92015-01-28 Fabián Ezequiel Gallina <fgallina@gnu.org>
10
11 * automated/python-tests.el (python-indent-pep8-1)
12 (python-indent-pep8-2, python-indent-pep8-3)
13 (python-indent-after-comment-1, python-indent-after-comment-2)
14 (python-indent-inside-paren-1, python-indent-inside-paren-2)
15 (python-indent-after-block-1, python-indent-after-block-2)
16 (python-indent-after-backslash-1, python-indent-after-backslash-2)
17 (python-indent-after-backslash-3, python-indent-block-enders-1)
18 (python-indent-block-enders-2, python-indent-block-enders-3)
19 (python-indent-block-enders-4, python-indent-block-enders-5)
20 (python-indent-dedenters-1, python-indent-dedenters-2)
21 (python-indent-dedenters-3, python-indent-dedenters-4)
22 (python-indent-dedenters-5, python-indent-dedenters-6)
23 (python-indent-dedenters-7, python-indent-dedenters-8): Fix tests.
24 (python-indent-base-case, python-indent-after-block-3)
25 (python-indent-after-backslash-5, python-indent-inside-paren-3)
26 (python-indent-inside-paren-4, python-indent-inside-paren-5)
27 (python-indent-inside-paren-6, python-indent-inside-string-1)
28 (python-indent-inside-string-2, python-indent-inside-string-3)
29 (python-indent-dedent-line-backspace-1): New Tests.
30
312015-01-28 Glenn Morris <rgm@gnu.org>
32
33 * automated/regexp-tests.el: Require regexp-opt, which is
34 not preloaded --without-x.
35
12015-01-26 Stefan Monnier <monnier@iro.umontreal.ca> 362015-01-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 37
3 * automated/cl-generic-tests.el: Try and make sure cl-lib is not 38 * automated/cl-generic-tests.el: Try and make sure cl-lib is not
@@ -33,6 +68,11 @@
33 * automated/cl-generic-tests.el (setf cl--generic-2): Make sure 68 * automated/cl-generic-tests.el (setf cl--generic-2): Make sure
34 the setf can be used already in the body of the method. 69 the setf can be used already in the body of the method.
35 70
712015-01-20 Jorgen Schaefer <contact@jorgenschaefer.de>
72
73 * automated/package-test.el (package-test-install-prioritized):
74 Remove test due to unreproducible failures.
75
362015-01-20 Michal Nazarewicz <mina86@mina86.com> 762015-01-20 Michal Nazarewicz <mina86@mina86.com>
37 77
38 * automated/descr-text-test.el: New file with tests for 78 * automated/descr-text-test.el: New file with tests for
diff --git a/test/automated/core-elisp-tests.el b/test/automated/core-elisp-tests.el
index 1b76c767b95..c31ecef4a32 100644
--- a/test/automated/core-elisp-tests.el
+++ b/test/automated/core-elisp-tests.el
@@ -24,7 +24,7 @@
24 24
25;;; Code: 25;;; Code:
26 26
27(ert-deftest core-elisp-tests () 27(ert-deftest core-elisp-tests-1-defvar-in-let ()
28 "Test some core Elisp rules." 28 "Test some core Elisp rules."
29 (with-temp-buffer 29 (with-temp-buffer
30 ;; Check that when defvar is run within a let-binding, the toplevel default 30 ;; Check that when defvar is run within a let-binding, the toplevel default
@@ -36,7 +36,7 @@
36 c-e-x) 36 c-e-x)
37 '(1 2))))) 37 '(1 2)))))
38 38
39(ert-deftest core-elisp-test-window-configurations () 39(ert-deftest core-elisp-tests-2-window-configurations ()
40 "Test properties of window-configurations." 40 "Test properties of window-configurations."
41 (let ((wc (current-window-configuration))) 41 (let ((wc (current-window-configuration)))
42 (with-current-buffer (window-buffer (frame-selected-window)) 42 (with-current-buffer (window-buffer (frame-selected-window))
@@ -45,5 +45,8 @@
45 (set-window-configuration wc) 45 (set-window-configuration wc)
46 (should (or (not mark-active) (mark))))) 46 (should (or (not mark-active) (mark)))))
47 47
48(ert-deftest core-elisp-tests-3-backquote ()
49 (should (eq 3 (eval ``,,'(+ 1 2)))))
50
48(provide 'core-elisp-tests) 51(provide 'core-elisp-tests)
49;;; core-elisp-tests.el ends here 52;;; core-elisp-tests.el ends here
diff --git a/test/automated/eieio-tests.el b/test/automated/eieio-tests.el
index 847aefd63fc..7532609c4c3 100644
--- a/test/automated/eieio-tests.el
+++ b/test/automated/eieio-tests.el
@@ -537,9 +537,8 @@ METHOD is the method that was attempting to be called."
537 (should (object-of-class-p eitest-ab 'class-b)) 537 (should (object-of-class-p eitest-ab 'class-b))
538 (should (object-of-class-p eitest-ab 'class-ab)) 538 (should (object-of-class-p eitest-ab 'class-ab))
539 (should (eq (eieio-class-parents 'class-a) nil)) 539 (should (eq (eieio-class-parents 'class-a) nil))
540 ;; FIXME: eieio-class-parents now returns class objects! 540 (should (equal (eieio-class-parents 'class-ab)
541 (should (equal (mapcar #'eieio-class-object (eieio-class-parents 'class-ab)) 541 (mapcar #'find-class '(class-a class-b))))
542 (mapcar #'eieio-class-object '(class-a class-b))))
543 (should (same-class-p eitest-a 'class-a)) 542 (should (same-class-p eitest-a 'class-a))
544 (should (class-a-p eitest-a)) 543 (should (class-a-p eitest-a))
545 (should (not (class-a-p eitest-ab))) 544 (should (not (class-a-p eitest-ab)))
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index e989ccb6792..672b05c39de 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -174,13 +174,13 @@ aliqua."
174foo = long_function_name(var_one, var_two, 174foo = long_function_name(var_one, var_two,
175 var_three, var_four) 175 var_three, var_four)
176" 176"
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-line))
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))
184 (should (= (python-indent-calculate-indentation) 25)))) 184 (should (= (python-indent-calculate-indentation) 25))))
185 185
186(ert-deftest python-indent-pep8-2 () 186(ert-deftest python-indent-pep8-2 ()
@@ -192,19 +192,22 @@ def long_function_name(
192 var_four): 192 var_four):
193 print (var_one) 193 print (var_one)
194" 194"
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-line))
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)) 'inside-paren)) 201 (should (eq (car (python-indent-context))
202 :inside-paren-newline-start-from-block))
202 (should (= (python-indent-calculate-indentation) 8)) 203 (should (= (python-indent-calculate-indentation) 8))
203 (python-tests-look-at "var_four):") 204 (python-tests-look-at "var_four):")
204 (should (eq (car (python-indent-context)) 'inside-paren)) 205 (should (eq (car (python-indent-context))
206 :inside-paren-newline-start-from-block))
205 (should (= (python-indent-calculate-indentation) 8)) 207 (should (= (python-indent-calculate-indentation) 8))
206 (python-tests-look-at "print (var_one)") 208 (python-tests-look-at "print (var_one)")
207 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 209 (should (eq (car (python-indent-context))
210 :after-block-start))
208 (should (= (python-indent-calculate-indentation) 4)))) 211 (should (= (python-indent-calculate-indentation) 4))))
209 212
210(ert-deftest python-indent-pep8-3 () 213(ert-deftest python-indent-pep8-3 ()
@@ -215,18 +218,34 @@ foo = long_function_name(
215 var_one, var_two, 218 var_one, var_two,
216 var_three, var_four) 219 var_three, var_four)
217" 220"
218 (should (eq (car (python-indent-context)) 'no-indent)) 221 (should (eq (car (python-indent-context)) :no-indent))
219 (should (= (python-indent-calculate-indentation) 0)) 222 (should (= (python-indent-calculate-indentation) 0))
220 (python-tests-look-at "foo = long_function_name(") 223 (python-tests-look-at "foo = long_function_name(")
221 (should (eq (car (python-indent-context)) 'after-line)) 224 (should (eq (car (python-indent-context)) :after-line))
222 (should (= (python-indent-calculate-indentation) 0)) 225 (should (= (python-indent-calculate-indentation) 0))
223 (python-tests-look-at "var_one, var_two,") 226 (python-tests-look-at "var_one, var_two,")
224 (should (eq (car (python-indent-context)) 'inside-paren)) 227 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
225 (should (= (python-indent-calculate-indentation) 4)) 228 (should (= (python-indent-calculate-indentation) 4))
226 (python-tests-look-at "var_three, var_four)") 229 (python-tests-look-at "var_three, var_four)")
227 (should (eq (car (python-indent-context)) 'inside-paren)) 230 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
228 (should (= (python-indent-calculate-indentation) 4)))) 231 (should (= (python-indent-calculate-indentation) 4))))
229 232
233(ert-deftest python-indent-base-case ()
234 "Check base case does not trigger errors."
235 (python-tests-with-temp-buffer
236 "
237
238"
239 (goto-char (point-min))
240 (should (eq (car (python-indent-context)) :no-indent))
241 (should (= (python-indent-calculate-indentation) 0))
242 (forward-line 1)
243 (should (eq (car (python-indent-context)) :after-line))
244 (should (= (python-indent-calculate-indentation) 0))
245 (forward-line 1)
246 (should (eq (car (python-indent-context)) :after-line))
247 (should (= (python-indent-calculate-indentation) 0))))
248
230(ert-deftest python-indent-after-comment-1 () 249(ert-deftest python-indent-after-comment-1 ()
231 "The most simple after-comment case that shouldn't fail." 250 "The most simple after-comment case that shouldn't fail."
232 (python-tests-with-temp-buffer 251 (python-tests-with-temp-buffer
@@ -240,23 +259,23 @@ class Blag(object):
240# with the exception with which the first child failed. 259# with the exception with which the first child failed.
241" 260"
242 (python-tests-look-at "# We only complete") 261 (python-tests-look-at "# We only complete")
243 (should (eq (car (python-indent-context)) 'after-line)) 262 (should (eq (car (python-indent-context)) :after-block-end))
244 (should (= (python-indent-calculate-indentation) 8)) 263 (should (= (python-indent-calculate-indentation) 8))
245 (python-tests-look-at "# terminal state") 264 (python-tests-look-at "# terminal state")
246 (should (eq (car (python-indent-context)) 'after-comment)) 265 (should (eq (car (python-indent-context)) :after-comment))
247 (should (= (python-indent-calculate-indentation) 8)) 266 (should (= (python-indent-calculate-indentation) 8))
248 (python-tests-look-at "# with the exception") 267 (python-tests-look-at "# with the exception")
249 (should (eq (car (python-indent-context)) 'after-comment)) 268 (should (eq (car (python-indent-context)) :after-comment))
250 ;; This one indents relative to previous block, even given the fact 269 ;; This one indents relative to previous block, even given the fact
251 ;; that it was under-indented. 270 ;; that it was under-indented.
252 (should (= (python-indent-calculate-indentation) 4)) 271 (should (= (python-indent-calculate-indentation) 4))
253 (python-tests-look-at "# terminal state" -1) 272 (python-tests-look-at "# terminal state" -1)
254 ;; It doesn't hurt to check again. 273 ;; It doesn't hurt to check again.
255 (should (eq (car (python-indent-context)) 'after-comment)) 274 (should (eq (car (python-indent-context)) :after-comment))
256 (python-indent-line) 275 (python-indent-line)
257 (should (= (current-indentation) 8)) 276 (should (= (current-indentation) 8))
258 (python-tests-look-at "# with the exception") 277 (python-tests-look-at "# with the exception")
259 (should (eq (car (python-indent-context)) 'after-comment)) 278 (should (eq (car (python-indent-context)) :after-comment))
260 ;; Now everything should be lined up. 279 ;; Now everything should be lined up.
261 (should (= (python-indent-calculate-indentation) 8)))) 280 (should (= (python-indent-calculate-indentation) 8))))
262 281
@@ -275,33 +294,33 @@ now_we_do_mess_cause_this_is_not_a_comment = 1
275# yeah, that. 294# yeah, that.
276" 295"
277 (python-tests-look-at "# I don't do much") 296 (python-tests-look-at "# I don't do much")
278 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 297 (should (eq (car (python-indent-context)) :after-block-start))
279 (should (= (python-indent-calculate-indentation) 4)) 298 (should (= (python-indent-calculate-indentation) 4))
280 (python-tests-look-at "return arg") 299 (python-tests-look-at "return arg")
281 ;; Comment here just gets ignored, this line is not a comment so 300 ;; Comment here just gets ignored, this line is not a comment so
282 ;; the rules won't apply here. 301 ;; the rules won't apply here.
283 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 302 (should (eq (car (python-indent-context)) :after-block-start))
284 (should (= (python-indent-calculate-indentation) 4)) 303 (should (= (python-indent-calculate-indentation) 4))
285 (python-tests-look-at "# This comment is badly") 304 (python-tests-look-at "# This comment is badly")
286 (should (eq (car (python-indent-context)) 'after-line)) 305 (should (eq (car (python-indent-context)) :after-block-end))
287 ;; The return keyword moves indentation backwards 4 spaces, but 306 ;; The return keyword moves indentation backwards 4 spaces, but
288 ;; let's assume this comment was placed there because the user 307 ;; let's assume this comment was placed there because the user
289 ;; wanted to (manually adding spaces or whatever). 308 ;; wanted to (manually adding spaces or whatever).
290 (should (= (python-indent-calculate-indentation) 0)) 309 (should (= (python-indent-calculate-indentation) 0))
291 (python-tests-look-at "# but we won't mess") 310 (python-tests-look-at "# but we won't mess")
292 (should (eq (car (python-indent-context)) 'after-comment)) 311 (should (eq (car (python-indent-context)) :after-comment))
293 (should (= (python-indent-calculate-indentation) 4)) 312 (should (= (python-indent-calculate-indentation) 4))
294 ;; Behave the same for blank lines: potentially a comment. 313 ;; Behave the same for blank lines: potentially a comment.
295 (forward-line 1) 314 (forward-line 1)
296 (should (eq (car (python-indent-context)) 'after-comment)) 315 (should (eq (car (python-indent-context)) :after-comment))
297 (should (= (python-indent-calculate-indentation) 4)) 316 (should (= (python-indent-calculate-indentation) 4))
298 (python-tests-look-at "now_we_do_mess") 317 (python-tests-look-at "now_we_do_mess")
299 ;; Here is where comment indentation starts to get ignored and 318 ;; Here is where comment indentation starts to get ignored and
300 ;; where the user can't freely indent anymore. 319 ;; where the user can't freely indent anymore.
301 (should (eq (car (python-indent-context)) 'after-line)) 320 (should (eq (car (python-indent-context)) :after-block-end))
302 (should (= (python-indent-calculate-indentation) 0)) 321 (should (= (python-indent-calculate-indentation) 0))
303 (python-tests-look-at "# yeah, that.") 322 (python-tests-look-at "# yeah, that.")
304 (should (eq (car (python-indent-context)) 'after-line)) 323 (should (eq (car (python-indent-context)) :after-line))
305 (should (= (python-indent-calculate-indentation) 0)))) 324 (should (= (python-indent-calculate-indentation) 0))))
306 325
307(ert-deftest python-indent-inside-paren-1 () 326(ert-deftest python-indent-inside-paren-1 ()
@@ -325,49 +344,53 @@ data = {
325} 344}
326" 345"
327 (python-tests-look-at "data = {") 346 (python-tests-look-at "data = {")
328 (should (eq (car (python-indent-context)) 'after-line)) 347 (should (eq (car (python-indent-context)) :after-line))
329 (should (= (python-indent-calculate-indentation) 0)) 348 (should (= (python-indent-calculate-indentation) 0))
330 (python-tests-look-at "'key':") 349 (python-tests-look-at "'key':")
331 (should (eq (car (python-indent-context)) 'inside-paren)) 350 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
332 (should (= (python-indent-calculate-indentation) 4)) 351 (should (= (python-indent-calculate-indentation) 4))
333 (python-tests-look-at "{") 352 (python-tests-look-at "{")
334 (should (eq (car (python-indent-context)) 'inside-paren)) 353 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
335 (should (= (python-indent-calculate-indentation) 4)) 354 (should (= (python-indent-calculate-indentation) 4))
336 (python-tests-look-at "'objlist': [") 355 (python-tests-look-at "'objlist': [")
337 (should (eq (car (python-indent-context)) 'inside-paren)) 356 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
338 (should (= (python-indent-calculate-indentation) 8)) 357 (should (= (python-indent-calculate-indentation) 8))
339 (python-tests-look-at "{") 358 (python-tests-look-at "{")
340 (should (eq (car (python-indent-context)) 'inside-paren)) 359 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
341 (should (= (python-indent-calculate-indentation) 12)) 360 (should (= (python-indent-calculate-indentation) 12))
342 (python-tests-look-at "'pk': 1,") 361 (python-tests-look-at "'pk': 1,")
343 (should (eq (car (python-indent-context)) 'inside-paren)) 362 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
344 (should (= (python-indent-calculate-indentation) 16)) 363 (should (= (python-indent-calculate-indentation) 16))
345 (python-tests-look-at "'name': 'first',") 364 (python-tests-look-at "'name': 'first',")
346 (should (eq (car (python-indent-context)) 'inside-paren)) 365 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
347 (should (= (python-indent-calculate-indentation) 16)) 366 (should (= (python-indent-calculate-indentation) 16))
348 (python-tests-look-at "},") 367 (python-tests-look-at "},")
349 (should (eq (car (python-indent-context)) 'inside-paren)) 368 (should (eq (car (python-indent-context))
369 :inside-paren-at-closing-nested-paren))
350 (should (= (python-indent-calculate-indentation) 12)) 370 (should (= (python-indent-calculate-indentation) 12))
351 (python-tests-look-at "{") 371 (python-tests-look-at "{")
352 (should (eq (car (python-indent-context)) 'inside-paren)) 372 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
353 (should (= (python-indent-calculate-indentation) 12)) 373 (should (= (python-indent-calculate-indentation) 12))
354 (python-tests-look-at "'pk': 2,") 374 (python-tests-look-at "'pk': 2,")
355 (should (eq (car (python-indent-context)) 'inside-paren)) 375 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
356 (should (= (python-indent-calculate-indentation) 16)) 376 (should (= (python-indent-calculate-indentation) 16))
357 (python-tests-look-at "'name': 'second',") 377 (python-tests-look-at "'name': 'second',")
358 (should (eq (car (python-indent-context)) 'inside-paren)) 378 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
359 (should (= (python-indent-calculate-indentation) 16)) 379 (should (= (python-indent-calculate-indentation) 16))
360 (python-tests-look-at "}") 380 (python-tests-look-at "}")
361 (should (eq (car (python-indent-context)) 'inside-paren)) 381 (should (eq (car (python-indent-context))
382 :inside-paren-at-closing-nested-paren))
362 (should (= (python-indent-calculate-indentation) 12)) 383 (should (= (python-indent-calculate-indentation) 12))
363 (python-tests-look-at "]") 384 (python-tests-look-at "]")
364 (should (eq (car (python-indent-context)) 'inside-paren)) 385 (should (eq (car (python-indent-context))
386 :inside-paren-at-closing-nested-paren))
365 (should (= (python-indent-calculate-indentation) 8)) 387 (should (= (python-indent-calculate-indentation) 8))
366 (python-tests-look-at "}") 388 (python-tests-look-at "}")
367 (should (eq (car (python-indent-context)) 'inside-paren)) 389 (should (eq (car (python-indent-context))
390 :inside-paren-at-closing-nested-paren))
368 (should (= (python-indent-calculate-indentation) 4)) 391 (should (= (python-indent-calculate-indentation) 4))
369 (python-tests-look-at "}") 392 (python-tests-look-at "}")
370 (should (eq (car (python-indent-context)) 'inside-paren)) 393 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
371 (should (= (python-indent-calculate-indentation) 0)))) 394 (should (= (python-indent-calculate-indentation) 0))))
372 395
373(ert-deftest python-indent-inside-paren-2 () 396(ert-deftest python-indent-inside-paren-2 ()
@@ -384,43 +407,121 @@ data = {'key': {
384}} 407}}
385" 408"
386 (python-tests-look-at "data = {") 409 (python-tests-look-at "data = {")
387 (should (eq (car (python-indent-context)) 'after-line)) 410 (should (eq (car (python-indent-context)) :after-line))
388 (should (= (python-indent-calculate-indentation) 0)) 411 (should (= (python-indent-calculate-indentation) 0))
389 (python-tests-look-at "'objlist': [") 412 (python-tests-look-at "'objlist': [")
390 (should (eq (car (python-indent-context)) 'inside-paren)) 413 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
391 (should (= (python-indent-calculate-indentation) 4)) 414 (should (= (python-indent-calculate-indentation) 4))
392 (python-tests-look-at "{'pk': 1,") 415 (python-tests-look-at "{'pk': 1,")
393 (should (eq (car (python-indent-context)) 'inside-paren)) 416 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
394 (should (= (python-indent-calculate-indentation) 8)) 417 (should (= (python-indent-calculate-indentation) 8))
395 (python-tests-look-at "'name': 'first'},") 418 (python-tests-look-at "'name': 'first'},")
396 (should (eq (car (python-indent-context)) 'inside-paren)) 419 (should (eq (car (python-indent-context)) :inside-paren))
397 (should (= (python-indent-calculate-indentation) 9)) 420 (should (= (python-indent-calculate-indentation) 9))
398 (python-tests-look-at "{'pk': 2,") 421 (python-tests-look-at "{'pk': 2,")
399 (should (eq (car (python-indent-context)) 'inside-paren)) 422 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
400 (should (= (python-indent-calculate-indentation) 8)) 423 (should (= (python-indent-calculate-indentation) 8))
401 (python-tests-look-at "'name': 'second'}") 424 (python-tests-look-at "'name': 'second'}")
402 (should (eq (car (python-indent-context)) 'inside-paren)) 425 (should (eq (car (python-indent-context)) :inside-paren))
403 (should (= (python-indent-calculate-indentation) 9)) 426 (should (= (python-indent-calculate-indentation) 9))
404 (python-tests-look-at "]") 427 (python-tests-look-at "]")
405 (should (eq (car (python-indent-context)) 'inside-paren)) 428 (should (eq (car (python-indent-context))
429 :inside-paren-at-closing-nested-paren))
406 (should (= (python-indent-calculate-indentation) 4)) 430 (should (= (python-indent-calculate-indentation) 4))
407 (python-tests-look-at "}}") 431 (python-tests-look-at "}}")
408 (should (eq (car (python-indent-context)) 'inside-paren)) 432 (should (eq (car (python-indent-context))
433 :inside-paren-at-closing-nested-paren))
409 (should (= (python-indent-calculate-indentation) 0)) 434 (should (= (python-indent-calculate-indentation) 0))
410 (python-tests-look-at "}") 435 (python-tests-look-at "}")
411 (should (eq (car (python-indent-context)) 'inside-paren)) 436 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
412 (should (= (python-indent-calculate-indentation) 0)))) 437 (should (= (python-indent-calculate-indentation) 0))))
413 438
439(ert-deftest python-indent-inside-paren-3 ()
440 "The simplest case possible."
441 (python-tests-with-temp-buffer
442 "
443data = ('these',
444 'are',
445 'the',
446 'tokens')
447"
448 (python-tests-look-at "data = ('these',")
449 (should (eq (car (python-indent-context)) :after-line))
450 (should (= (python-indent-calculate-indentation) 0))
451 (forward-line 1)
452 (should (eq (car (python-indent-context)) :inside-paren))
453 (should (= (python-indent-calculate-indentation) 8))
454 (forward-line 1)
455 (should (eq (car (python-indent-context)) :inside-paren))
456 (should (= (python-indent-calculate-indentation) 8))
457 (forward-line 1)
458 (should (eq (car (python-indent-context)) :inside-paren))
459 (should (= (python-indent-calculate-indentation) 8))))
460
461(ert-deftest python-indent-inside-paren-4 ()
462 "Respect indentation of first column."
463 (python-tests-with-temp-buffer
464 "
465data = [ [ 'these', 'are'],
466 ['the', 'tokens' ] ]
467"
468 (python-tests-look-at "data = [ [ 'these', 'are'],")
469 (should (eq (car (python-indent-context)) :after-line))
470 (should (= (python-indent-calculate-indentation) 0))
471 (forward-line 1)
472 (should (eq (car (python-indent-context)) :inside-paren))
473 (should (= (python-indent-calculate-indentation) 9))))
474
475(ert-deftest python-indent-inside-paren-5 ()
476 "Test when :inside-paren initial parens are skipped in context start."
477 (python-tests-with-temp-buffer
478 "
479while ((not some_condition) and
480 another_condition):
481 do_something_interesting(
482 with_some_arg)
483"
484 (python-tests-look-at "while ((not some_condition) and")
485 (should (eq (car (python-indent-context)) :after-line))
486 (should (= (python-indent-calculate-indentation) 0))
487 (forward-line 1)
488 (should (eq (car (python-indent-context)) :inside-paren))
489 (should (= (python-indent-calculate-indentation) 7))
490 (forward-line 1)
491 (should (eq (car (python-indent-context)) :after-block-start))
492 (should (= (python-indent-calculate-indentation) 4))
493 (forward-line 1)
494 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
495 (should (= (python-indent-calculate-indentation) 8))))
496
497(ert-deftest python-indent-inside-paren-6 ()
498 "This should be aligned.."
499 (python-tests-with-temp-buffer
500 "
501CHOICES = (('some', 'choice'),
502 ('another', 'choice'),
503 ('more', 'choices'))
504"
505 (python-tests-look-at "CHOICES = (('some', 'choice'),")
506 (should (eq (car (python-indent-context)) :after-line))
507 (should (= (python-indent-calculate-indentation) 0))
508 (forward-line 1)
509 (should (eq (car (python-indent-context)) :inside-paren))
510 (should (= (python-indent-calculate-indentation) 11))
511 (forward-line 1)
512 (should (eq (car (python-indent-context)) :inside-paren))
513 (should (= (python-indent-calculate-indentation) 11))))
514
414(ert-deftest python-indent-after-block-1 () 515(ert-deftest python-indent-after-block-1 ()
415 "The most simple after-block case that shouldn't fail." 516 "The most simple after-block case that shouldn't fail."
416 (python-tests-with-temp-buffer 517 (python-tests-with-temp-buffer
417 " 518 "
418def foo(a, b, c=True): 519def foo(a, b, c=True):
419" 520"
420 (should (eq (car (python-indent-context)) 'no-indent)) 521 (should (eq (car (python-indent-context)) :no-indent))
421 (should (= (python-indent-calculate-indentation) 0)) 522 (should (= (python-indent-calculate-indentation) 0))
422 (goto-char (point-max)) 523 (goto-char (point-max))
423 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 524 (should (eq (car (python-indent-context)) :after-block-start))
424 (should (= (python-indent-calculate-indentation) 4)))) 525 (should (= (python-indent-calculate-indentation) 4))))
425 526
426(ert-deftest python-indent-after-block-2 () 527(ert-deftest python-indent-after-block-2 ()
@@ -432,9 +533,28 @@ def foo(a, b, c={
432}): 533}):
433" 534"
434 (goto-char (point-max)) 535 (goto-char (point-max))
435 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 536 (should (eq (car (python-indent-context)) :after-block-start))
436 (should (= (python-indent-calculate-indentation) 4)))) 537 (should (= (python-indent-calculate-indentation) 4))))
437 538
539(ert-deftest python-indent-after-block-3 ()
540 "A weird (malformed) sample, usually found in python shells."
541 (python-tests-with-temp-buffer
542 "
543In [1]:
544def func():
545pass
546
547In [2]:
548something
549"
550 (python-tests-look-at "pass")
551 (should (eq (car (python-indent-context)) :after-block-start))
552 (should (= (python-indent-calculate-indentation) 4))
553 (python-tests-look-at "something")
554 (end-of-line)
555 (should (eq (car (python-indent-context)) :after-line))
556 (should (= (python-indent-calculate-indentation) 0))))
557
438(ert-deftest python-indent-after-backslash-1 () 558(ert-deftest python-indent-after-backslash-1 ()
439 "The most common case." 559 "The most common case."
440 (python-tests-with-temp-buffer 560 (python-tests-with-temp-buffer
@@ -444,16 +564,16 @@ from foo.bar.baz import something, something_1 \\\\
444 something_4, something_5 564 something_4, something_5
445" 565"
446 (python-tests-look-at "from foo.bar.baz import something, something_1") 566 (python-tests-look-at "from foo.bar.baz import something, something_1")
447 (should (eq (car (python-indent-context)) 'after-line)) 567 (should (eq (car (python-indent-context)) :after-line))
448 (should (= (python-indent-calculate-indentation) 0)) 568 (should (= (python-indent-calculate-indentation) 0))
449 (python-tests-look-at "something_2 something_3,") 569 (python-tests-look-at "something_2 something_3,")
450 (should (eq (car (python-indent-context)) 'after-backslash)) 570 (should (eq (car (python-indent-context)) :after-backslash-first-line))
451 (should (= (python-indent-calculate-indentation) 4)) 571 (should (= (python-indent-calculate-indentation) 4))
452 (python-tests-look-at "something_4, something_5") 572 (python-tests-look-at "something_4, something_5")
453 (should (eq (car (python-indent-context)) 'after-backslash)) 573 (should (eq (car (python-indent-context)) :after-backslash))
454 (should (= (python-indent-calculate-indentation) 4)) 574 (should (= (python-indent-calculate-indentation) 4))
455 (goto-char (point-max)) 575 (goto-char (point-max))
456 (should (eq (car (python-indent-context)) 'after-line)) 576 (should (eq (car (python-indent-context)) :after-line))
457 (should (= (python-indent-calculate-indentation) 0)))) 577 (should (= (python-indent-calculate-indentation) 0))))
458 578
459(ert-deftest python-indent-after-backslash-2 () 579(ert-deftest python-indent-after-backslash-2 ()
@@ -471,40 +591,104 @@ objects = Thing.objects.all() \\\\
471 .values_list() 591 .values_list()
472" 592"
473 (python-tests-look-at "objects = Thing.objects.all()") 593 (python-tests-look-at "objects = Thing.objects.all()")
474 (should (eq (car (python-indent-context)) 'after-line)) 594 (should (eq (car (python-indent-context)) :after-line))
475 (should (= (python-indent-calculate-indentation) 0)) 595 (should (= (python-indent-calculate-indentation) 0))
476 (python-tests-look-at ".filter(") 596 (python-tests-look-at ".filter(")
477 (should (eq (car (python-indent-context)) 'after-backslash)) 597 (should (eq (car (python-indent-context))
598 :after-backslash-dotted-continuation))
478 (should (= (python-indent-calculate-indentation) 23)) 599 (should (= (python-indent-calculate-indentation) 23))
479 (python-tests-look-at "type='toy',") 600 (python-tests-look-at "type='toy',")
480 (should (eq (car (python-indent-context)) 'inside-paren)) 601 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
481 (should (= (python-indent-calculate-indentation) 27)) 602 (should (= (python-indent-calculate-indentation) 27))
482 (python-tests-look-at "status='bought'") 603 (python-tests-look-at "status='bought'")
483 (should (eq (car (python-indent-context)) 'inside-paren)) 604 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
484 (should (= (python-indent-calculate-indentation) 27)) 605 (should (= (python-indent-calculate-indentation) 27))
485 (python-tests-look-at ") \\\\") 606 (python-tests-look-at ") \\\\")
486 (should (eq (car (python-indent-context)) 'inside-paren)) 607 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
487 (should (= (python-indent-calculate-indentation) 23)) 608 (should (= (python-indent-calculate-indentation) 23))
488 (python-tests-look-at ".aggregate(") 609 (python-tests-look-at ".aggregate(")
489 (should (eq (car (python-indent-context)) 'after-backslash)) 610 (should (eq (car (python-indent-context))
611 :after-backslash-dotted-continuation))
490 (should (= (python-indent-calculate-indentation) 23)) 612 (should (= (python-indent-calculate-indentation) 23))
491 (python-tests-look-at "Sum('amount')") 613 (python-tests-look-at "Sum('amount')")
492 (should (eq (car (python-indent-context)) 'inside-paren)) 614 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
493 (should (= (python-indent-calculate-indentation) 27)) 615 (should (= (python-indent-calculate-indentation) 27))
494 (python-tests-look-at ") \\\\") 616 (python-tests-look-at ") \\\\")
495 (should (eq (car (python-indent-context)) 'inside-paren)) 617 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
496 (should (= (python-indent-calculate-indentation) 23)) 618 (should (= (python-indent-calculate-indentation) 23))
497 (python-tests-look-at ".values_list()") 619 (python-tests-look-at ".values_list()")
498 (should (eq (car (python-indent-context)) 'after-backslash)) 620 (should (eq (car (python-indent-context))
621 :after-backslash-dotted-continuation))
499 (should (= (python-indent-calculate-indentation) 23)) 622 (should (= (python-indent-calculate-indentation) 23))
500 (forward-line 1) 623 (forward-line 1)
501 (should (eq (car (python-indent-context)) 'after-line)) 624 (should (eq (car (python-indent-context)) :after-line))
502 (should (= (python-indent-calculate-indentation) 0)))) 625 (should (= (python-indent-calculate-indentation) 0))))
503 626
627(ert-deftest python-indent-after-backslash-3 ()
628 "Backslash continuation from block start."
629 (python-tests-with-temp-buffer
630 "
631with open('/path/to/some/file/you/want/to/read') as file_1, \\\\
632 open('/path/to/some/file/being/written', 'w') as file_2:
633 file_2.write(file_1.read())
634"
635 (python-tests-look-at
636 "with open('/path/to/some/file/you/want/to/read') as file_1, \\\\")
637 (should (eq (car (python-indent-context)) :after-line))
638 (should (= (python-indent-calculate-indentation) 0))
639 (python-tests-look-at
640 "open('/path/to/some/file/being/written', 'w') as file_2")
641 (should (eq (car (python-indent-context))
642 :after-backslash-block-continuation))
643 (should (= (python-indent-calculate-indentation) 5))
644 (python-tests-look-at "file_2.write(file_1.read())")
645 (should (eq (car (python-indent-context)) :after-block-start))
646 (should (= (python-indent-calculate-indentation) 4))))
647
648(ert-deftest python-indent-after-backslash-4 ()
649 "Backslash continuation from assignment."
650 (python-tests-with-temp-buffer
651 "
652super_awful_assignment = some_calculation() and \\\\
653 another_calculation() and \\\\
654 some_final_calculation()
655"
656 (python-tests-look-at
657 "super_awful_assignment = some_calculation() and \\\\")
658 (should (eq (car (python-indent-context)) :after-line))
659 (should (= (python-indent-calculate-indentation) 0))
660 (python-tests-look-at "another_calculation() and \\\\")
661 (should (eq (car (python-indent-context))
662 :after-backslash-assignment-continuation))
663 (should (= (python-indent-calculate-indentation) 25))
664 (python-tests-look-at "some_final_calculation()")
665 (should (eq (car (python-indent-context)) :after-backslash))
666 (should (= (python-indent-calculate-indentation) 25))))
667
668(ert-deftest python-indent-after-backslash-5 ()
669 "Dotted continuation bizarre example."
670 (python-tests-with-temp-buffer
671 "
672def delete_all_things():
673 Thing \\\\
674 .objects.all() \\\\
675 .delete()
676"
677 (python-tests-look-at "Thing \\\\")
678 (should (eq (car (python-indent-context)) :after-block-start))
679 (should (= (python-indent-calculate-indentation) 4))
680 (python-tests-look-at ".objects.all() \\\\")
681 (should (eq (car (python-indent-context)) :after-backslash-first-line))
682 (should (= (python-indent-calculate-indentation) 8))
683 (python-tests-look-at ".delete()")
684 (should (eq (car (python-indent-context))
685 :after-backslash-dotted-continuation))
686 (should (= (python-indent-calculate-indentation) 16))))
687
504(ert-deftest python-indent-block-enders-1 () 688(ert-deftest python-indent-block-enders-1 ()
505 "Test de-indentation for pass keyword." 689 "Test de-indentation for pass keyword."
506 (python-tests-with-temp-buffer 690 (python-tests-with-temp-buffer
507 " 691 "
508Class foo(object): 692Class foo(object):
509 693
510 def bar(self): 694 def bar(self):
@@ -516,17 +700,18 @@ Class foo(object):
516 else: 700 else:
517 pass 701 pass
518" 702"
519 (python-tests-look-at "3)") 703 (python-tests-look-at "3)")
520 (forward-line 1) 704 (forward-line 1)
521 (should (= (python-indent-calculate-indentation) 8)) 705 (should (= (python-indent-calculate-indentation) 8))
522 (python-tests-look-at "pass") 706 (python-tests-look-at "pass")
523 (forward-line 1) 707 (forward-line 1)
524 (should (= (python-indent-calculate-indentation) 8)))) 708 (should (eq (car (python-indent-context)) :after-block-end))
709 (should (= (python-indent-calculate-indentation) 8))))
525 710
526(ert-deftest python-indent-block-enders-2 () 711(ert-deftest python-indent-block-enders-2 ()
527 "Test de-indentation for return keyword." 712 "Test de-indentation for return keyword."
528 (python-tests-with-temp-buffer 713 (python-tests-with-temp-buffer
529 " 714 "
530Class foo(object): 715Class foo(object):
531 '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 716 '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
532 717
@@ -539,64 +724,68 @@ Class foo(object):
539 2, 724 2,
540 3) 725 3)
541" 726"
542 (python-tests-look-at "def") 727 (python-tests-look-at "def")
543 (should (= (python-indent-calculate-indentation) 4)) 728 (should (= (python-indent-calculate-indentation) 4))
544 (python-tests-look-at "if") 729 (python-tests-look-at "if")
545 (should (= (python-indent-calculate-indentation) 8)) 730 (should (= (python-indent-calculate-indentation) 8))
546 (python-tests-look-at "return") 731 (python-tests-look-at "return")
547 (should (= (python-indent-calculate-indentation) 12)) 732 (should (= (python-indent-calculate-indentation) 12))
548 (goto-char (point-max)) 733 (goto-char (point-max))
549 (should (= (python-indent-calculate-indentation) 8)))) 734 (should (eq (car (python-indent-context)) :after-block-end))
735 (should (= (python-indent-calculate-indentation) 8))))
550 736
551(ert-deftest python-indent-block-enders-3 () 737(ert-deftest python-indent-block-enders-3 ()
552 "Test de-indentation for continue keyword." 738 "Test de-indentation for continue keyword."
553 (python-tests-with-temp-buffer 739 (python-tests-with-temp-buffer
554 " 740 "
555for element in lst: 741for element in lst:
556 if element is None: 742 if element is None:
557 continue 743 continue
558" 744"
559 (python-tests-look-at "if") 745 (python-tests-look-at "if")
560 (should (= (python-indent-calculate-indentation) 4)) 746 (should (= (python-indent-calculate-indentation) 4))
561 (python-tests-look-at "continue") 747 (python-tests-look-at "continue")
562 (should (= (python-indent-calculate-indentation) 8)) 748 (should (= (python-indent-calculate-indentation) 8))
563 (forward-line 1) 749 (forward-line 1)
564 (should (= (python-indent-calculate-indentation) 4)))) 750 (should (eq (car (python-indent-context)) :after-block-end))
751 (should (= (python-indent-calculate-indentation) 4))))
565 752
566(ert-deftest python-indent-block-enders-4 () 753(ert-deftest python-indent-block-enders-4 ()
567 "Test de-indentation for break keyword." 754 "Test de-indentation for break keyword."
568 (python-tests-with-temp-buffer 755 (python-tests-with-temp-buffer
569 " 756 "
570for element in lst: 757for element in lst:
571 if element is None: 758 if element is None:
572 break 759 break
573" 760"
574 (python-tests-look-at "if") 761 (python-tests-look-at "if")
575 (should (= (python-indent-calculate-indentation) 4)) 762 (should (= (python-indent-calculate-indentation) 4))
576 (python-tests-look-at "break") 763 (python-tests-look-at "break")
577 (should (= (python-indent-calculate-indentation) 8)) 764 (should (= (python-indent-calculate-indentation) 8))
578 (forward-line 1) 765 (forward-line 1)
579 (should (= (python-indent-calculate-indentation) 4)))) 766 (should (eq (car (python-indent-context)) :after-block-end))
767 (should (= (python-indent-calculate-indentation) 4))))
580 768
581(ert-deftest python-indent-block-enders-5 () 769(ert-deftest python-indent-block-enders-5 ()
582 "Test de-indentation for raise keyword." 770 "Test de-indentation for raise keyword."
583 (python-tests-with-temp-buffer 771 (python-tests-with-temp-buffer
584 " 772 "
585for element in lst: 773for element in lst:
586 if element is None: 774 if element is None:
587 raise ValueError('Element cannot be None') 775 raise ValueError('Element cannot be None')
588" 776"
589 (python-tests-look-at "if") 777 (python-tests-look-at "if")
590 (should (= (python-indent-calculate-indentation) 4)) 778 (should (= (python-indent-calculate-indentation) 4))
591 (python-tests-look-at "raise") 779 (python-tests-look-at "raise")
592 (should (= (python-indent-calculate-indentation) 8)) 780 (should (= (python-indent-calculate-indentation) 8))
593 (forward-line 1) 781 (forward-line 1)
594 (should (= (python-indent-calculate-indentation) 4)))) 782 (should (eq (car (python-indent-context)) :after-block-end))
783 (should (= (python-indent-calculate-indentation) 4))))
595 784
596(ert-deftest python-indent-dedenters-1 () 785(ert-deftest python-indent-dedenters-1 ()
597 "Test de-indentation for the elif keyword." 786 "Test de-indentation for the elif keyword."
598 (python-tests-with-temp-buffer 787 (python-tests-with-temp-buffer
599 " 788 "
600if save: 789if save:
601 try: 790 try:
602 write_to_disk(data) 791 write_to_disk(data)
@@ -604,15 +793,15 @@ if save:
604 cleanup() 793 cleanup()
605 elif 794 elif
606" 795"
607 (python-tests-look-at "elif\n") 796 (python-tests-look-at "elif\n")
608 (should (eq (car (python-indent-context)) 'dedenter-statement)) 797 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
609 (should (= (python-indent-calculate-indentation) 0)) 798 (should (= (python-indent-calculate-indentation) 0))
610 (should (equal (python-indent-calculate-levels) '(0))))) 799 (should (= (python-indent-calculate-indentation t) 0))))
611 800
612(ert-deftest python-indent-dedenters-2 () 801(ert-deftest python-indent-dedenters-2 ()
613 "Test de-indentation for the else keyword." 802 "Test de-indentation for the else keyword."
614 (python-tests-with-temp-buffer 803 (python-tests-with-temp-buffer
615 " 804 "
616if save: 805if save:
617 try: 806 try:
618 write_to_disk(data) 807 write_to_disk(data)
@@ -627,43 +816,50 @@ if save:
627 finally: 816 finally:
628 data.free() 817 data.free()
629" 818"
630 (python-tests-look-at "else\n") 819 (python-tests-look-at "else\n")
631 (should (eq (car (python-indent-context)) 'dedenter-statement)) 820 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
632 (should (= (python-indent-calculate-indentation) 8)) 821 (should (= (python-indent-calculate-indentation) 8))
633 (should (equal (python-indent-calculate-levels) '(0 4 8))))) 822 (python-indent-line t)
823 (should (= (python-indent-calculate-indentation t) 4))
824 (python-indent-line t)
825 (should (= (python-indent-calculate-indentation t) 0))
826 (python-indent-line t)
827 (should (= (python-indent-calculate-indentation t) 8))))
634 828
635(ert-deftest python-indent-dedenters-3 () 829(ert-deftest python-indent-dedenters-3 ()
636 "Test de-indentation for the except keyword." 830 "Test de-indentation for the except keyword."
637 (python-tests-with-temp-buffer 831 (python-tests-with-temp-buffer
638 " 832 "
639if save: 833if save:
640 try: 834 try:
641 write_to_disk(data) 835 write_to_disk(data)
642 except 836 except
643" 837"
644 (python-tests-look-at "except\n") 838 (python-tests-look-at "except\n")
645 (should (eq (car (python-indent-context)) 'dedenter-statement)) 839 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
646 (should (= (python-indent-calculate-indentation) 4)) 840 (should (= (python-indent-calculate-indentation) 4))
647 (should (equal (python-indent-calculate-levels) '(4))))) 841 (python-indent-line t)
842 (should (= (python-indent-calculate-indentation t) 4))))
648 843
649(ert-deftest python-indent-dedenters-4 () 844(ert-deftest python-indent-dedenters-4 ()
650 "Test de-indentation for the finally keyword." 845 "Test de-indentation for the finally keyword."
651 (python-tests-with-temp-buffer 846 (python-tests-with-temp-buffer
652 " 847 "
653if save: 848if save:
654 try: 849 try:
655 write_to_disk(data) 850 write_to_disk(data)
656 finally 851 finally
657" 852"
658 (python-tests-look-at "finally\n") 853 (python-tests-look-at "finally\n")
659 (should (eq (car (python-indent-context)) 'dedenter-statement)) 854 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
660 (should (= (python-indent-calculate-indentation) 4)) 855 (should (= (python-indent-calculate-indentation) 4))
661 (should (equal (python-indent-calculate-levels) '(4))))) 856 (python-indent-line t)
857 (should (= (python-indent-calculate-indentation) 4))))
662 858
663(ert-deftest python-indent-dedenters-5 () 859(ert-deftest python-indent-dedenters-5 ()
664 "Test invalid levels are skipped in a complex example." 860 "Test invalid levels are skipped in a complex example."
665 (python-tests-with-temp-buffer 861 (python-tests-with-temp-buffer
666 " 862 "
667if save: 863if save:
668 try: 864 try:
669 write_to_disk(data) 865 write_to_disk(data)
@@ -676,29 +872,31 @@ if save:
676 do_cleanup() 872 do_cleanup()
677 else 873 else
678" 874"
679 (python-tests-look-at "else\n") 875 (python-tests-look-at "else\n")
680 (should (eq (car (python-indent-context)) 'dedenter-statement)) 876 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
681 (should (= (python-indent-calculate-indentation) 8)) 877 (should (= (python-indent-calculate-indentation) 8))
682 (should (equal (python-indent-calculate-levels) '(0 8))))) 878 (should (= (python-indent-calculate-indentation t) 0))
879 (python-indent-line t)
880 (should (= (python-indent-calculate-indentation t) 8))))
683 881
684(ert-deftest python-indent-dedenters-6 () 882(ert-deftest python-indent-dedenters-6 ()
685 "Test indentation is zero when no opening block for dedenter." 883 "Test indentation is zero when no opening block for dedenter."
686 (python-tests-with-temp-buffer 884 (python-tests-with-temp-buffer
687 " 885 "
688try: 886try:
689 # if save: 887 # if save:
690 write_to_disk(data) 888 write_to_disk(data)
691 else 889 else
692" 890"
693 (python-tests-look-at "else\n") 891 (python-tests-look-at "else\n")
694 (should (eq (car (python-indent-context)) 'dedenter-statement)) 892 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
695 (should (= (python-indent-calculate-indentation) 0)) 893 (should (= (python-indent-calculate-indentation) 0))
696 (should (equal (python-indent-calculate-levels) '(0))))) 894 (should (= (python-indent-calculate-indentation t) 0))))
697 895
698(ert-deftest python-indent-dedenters-7 () 896(ert-deftest python-indent-dedenters-7 ()
699 "Test indentation case from Bug#15163." 897 "Test indentation case from Bug#15163."
700 (python-tests-with-temp-buffer 898 (python-tests-with-temp-buffer
701 " 899 "
702if a: 900if a:
703 if b: 901 if b:
704 pass 902 pass
@@ -706,10 +904,10 @@ if a:
706 pass 904 pass
707 else: 905 else:
708" 906"
709 (python-tests-look-at "else:" 2) 907 (python-tests-look-at "else:" 2)
710 (should (eq (car (python-indent-context)) 'dedenter-statement)) 908 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
711 (should (= (python-indent-calculate-indentation) 0)) 909 (should (= (python-indent-calculate-indentation) 0))
712 (should (equal (python-indent-calculate-levels) '(0))))) 910 (should (= (python-indent-calculate-indentation t) 0))))
713 911
714(ert-deftest python-indent-dedenters-8 () 912(ert-deftest python-indent-dedenters-8 ()
715 "Test indentation for Bug#18432." 913 "Test indentation for Bug#18432."
@@ -721,10 +919,99 @@ if (a == 1 or
721elif (a == 3 or 919elif (a == 3 or
722a == 4): 920a == 4):
723" 921"
922 (python-tests-look-at "elif (a == 3 or")
923 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
924 (should (= (python-indent-calculate-indentation) 0))
925 (should (= (python-indent-calculate-indentation t) 0))
724 (python-tests-look-at "a == 4):\n") 926 (python-tests-look-at "a == 4):\n")
725 (should (eq (car (python-indent-context)) 'inside-paren)) 927 (should (eq (car (python-indent-context)) :inside-paren))
726 (should (= (python-indent-calculate-indentation) 6)) 928 (should (= (python-indent-calculate-indentation) 6))
727 (should (equal (python-indent-calculate-levels) '(0 4 6))))) 929 (python-indent-line)
930 (should (= (python-indent-calculate-indentation t) 4))
931 (python-indent-line t)
932 (should (= (python-indent-calculate-indentation t) 0))
933 (python-indent-line t)
934 (should (= (python-indent-calculate-indentation t) 6))))
935
936(ert-deftest python-indent-inside-string-1 ()
937 "Test indentation for strings."
938 (python-tests-with-temp-buffer
939 "
940multiline = '''
941bunch
942of
943lines
944'''
945"
946 (python-tests-look-at "multiline = '''")
947 (should (eq (car (python-indent-context)) :after-line))
948 (should (= (python-indent-calculate-indentation) 0))
949 (python-tests-look-at "bunch")
950 (should (eq (car (python-indent-context)) :inside-string))
951 (should (= (python-indent-calculate-indentation) 0))
952 (python-tests-look-at "of")
953 (should (eq (car (python-indent-context)) :inside-string))
954 (should (= (python-indent-calculate-indentation) 0))
955 (python-tests-look-at "lines")
956 (should (eq (car (python-indent-context)) :inside-string))
957 (should (= (python-indent-calculate-indentation) 0))
958 (python-tests-look-at "'''")
959 (should (eq (car (python-indent-context)) :inside-string))
960 (should (= (python-indent-calculate-indentation) 0))))
961
962(ert-deftest python-indent-inside-string-2 ()
963 "Test indentation for docstrings."
964 (python-tests-with-temp-buffer
965 "
966def fn(a, b, c=True):
967 '''docstring
968 bunch
969 of
970 lines
971 '''
972"
973 (python-tests-look-at "'''docstring")
974 (should (eq (car (python-indent-context)) :after-block-start))
975 (should (= (python-indent-calculate-indentation) 4))
976 (python-tests-look-at "bunch")
977 (should (eq (car (python-indent-context)) :inside-string))
978 (should (= (python-indent-calculate-indentation) 4))
979 (python-tests-look-at "of")
980 (should (eq (car (python-indent-context)) :inside-string))
981 (should (= (python-indent-calculate-indentation) 4))
982 (python-tests-look-at "lines")
983 (should (eq (car (python-indent-context)) :inside-string))
984 (should (= (python-indent-calculate-indentation) 4))
985 (python-tests-look-at "'''")
986 (should (eq (car (python-indent-context)) :inside-string))
987 (should (= (python-indent-calculate-indentation) 4))))
988
989(ert-deftest python-indent-inside-string-3 ()
990 "Test indentation for nested strings."
991 (python-tests-with-temp-buffer
992 "
993def fn(a, b, c=True):
994 some_var = '''
995 bunch
996 of
997 lines
998 '''
999"
1000 (python-tests-look-at "some_var = '''")
1001 (should (eq (car (python-indent-context)) :after-block-start))
1002 (should (= (python-indent-calculate-indentation) 4))
1003 (python-tests-look-at "bunch")
1004 (should (eq (car (python-indent-context)) :inside-string))
1005 (should (= (python-indent-calculate-indentation) 4))
1006 (python-tests-look-at "of")
1007 (should (eq (car (python-indent-context)) :inside-string))
1008 (should (= (python-indent-calculate-indentation) 4))
1009 (python-tests-look-at "lines")
1010 (should (eq (car (python-indent-context)) :inside-string))
1011 (should (= (python-indent-calculate-indentation) 4))
1012 (python-tests-look-at "'''")
1013 (should (eq (car (python-indent-context)) :inside-string))
1014 (should (= (python-indent-calculate-indentation) 4))))
728 1015
729(ert-deftest python-indent-electric-colon-1 () 1016(ert-deftest python-indent-electric-colon-1 ()
730 "Test indentation case from Bug#18228." 1017 "Test indentation case from Bug#18228."
@@ -1802,6 +2089,23 @@ def f():
1802 (python-nav-backward-up-list) 2089 (python-nav-backward-up-list)
1803 (should (looking-at "def f():")))) 2090 (should (looking-at "def f():"))))
1804 2091
2092(ert-deftest python-indent-dedent-line-backspace-1 ()
2093 "Check de-indentation on first call. Bug#18319."
2094 (python-tests-with-temp-buffer
2095 "
2096if True:
2097 x ()
2098 if False:
2099"
2100 (python-tests-look-at "if False:")
2101 (call-interactively #'python-indent-dedent-line-backspace)
2102 (should (zerop (current-indentation)))
2103 ;; XXX: This should be a call to `undo' but it's triggering errors.
2104 (insert " ")
2105 (should (= (current-indentation) 4))
2106 (call-interactively #'python-indent-dedent-line-backspace)
2107 (should (zerop (current-indentation)))))
2108
1805 2109
1806;;; Shell integration 2110;;; Shell integration
1807 2111
diff --git a/test/automated/regexp-tests.el b/test/automated/regexp-tests.el
index 31a4ee958c6..ee177b3e2e9 100644
--- a/test/automated/regexp-tests.el
+++ b/test/automated/regexp-tests.el
@@ -23,6 +23,8 @@
23 23
24;;; Code: 24;;; Code:
25 25
26(require 'regexp-opt)
27
26(ert-deftest regexp-test-regexp-opt () 28(ert-deftest regexp-test-regexp-opt ()
27 "Test the `compilation-error-regexp-alist' regexps. 29 "Test the `compilation-error-regexp-alist' regexps.
28The test data is in `compile-tests--test-regexps-data'." 30The test data is in `compile-tests--test-regexps-data'."