]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a test for python-mode comment/else problem
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 27 Jul 2022 09:38:19 +0000 (11:38 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 27 Jul 2022 09:38:19 +0000 (11:38 +0200)
Based on a patch from kobarity <kobarity@gmail.com>

test/lisp/progmodes/python-tests.el

index 3b10bde23bc7efabd7ca1a1ac0becfb197d2b948..6f2ad87f81aed503ab00cb18d227e4e965c57659 100644 (file)
@@ -1122,6 +1122,35 @@ if save:
    (python-indent-line t)
    (should (= (python-indent-calculate-indentation t) 8))))
 
+(ert-deftest python-indent-dedenters-comment-else ()
+  "Test de-indentation for the else keyword with comments before it."
+  (python-tests-with-temp-buffer
+   "
+if save:
+    try:
+        write_to_disk(data)
+    except IOError:
+        msg = 'Error saving to disk'
+        message(msg)
+        logger.exception(msg)
+    except Exception:
+        if hide_details:
+            logger.exception('Unhandled exception')
+        # comment
+            else
+    finally:
+        data.free()
+"
+   (python-tests-look-at "else\n")
+   (should (eq (car (python-indent-context)) :at-dedenter-block-start))
+   (should (= (python-indent-calculate-indentation) 8))
+   (python-indent-line t)
+   (should (= (python-indent-calculate-indentation t) 4))
+   (python-indent-line t)
+   (should (= (python-indent-calculate-indentation t) 0))
+   (python-indent-line t)
+   (should (= (python-indent-calculate-indentation t) 8))))
+
 (ert-deftest python-indent-dedenters-3 ()
   "Test de-indentation for the except keyword."
   (python-tests-with-temp-buffer