aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-11-15 18:10:58 -0300
committerFabián Ezequiel Gallina2014-11-15 18:10:58 -0300
commit89ebffc1f60ead9b35c88663eadb345c3f569c3d (patch)
treed40ecde08eac62c35e4016caec0b41fbb28efa9d /test
parenta6b42789b55688822b762a20865c8d2c812125b9 (diff)
downloademacs-89ebffc1f60ead9b35c88663eadb345c3f569c3d.tar.gz
emacs-89ebffc1f60ead9b35c88663eadb345c3f569c3d.zip
Fix region indentation
Fixes: debbugs:18843 * lisp/progmodes/python.el (python-indent-region): Use python-indent-line and skip special cases. * test/automated/python-tests.el (python-indent-region-1) (python-indent-region-2, python-indent-region-3) (python-indent-region-4, python-indent-region-5): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog6
-rw-r--r--test/automated/python-tests.el104
2 files changed, 110 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index a5ee4b60589..971a4f8f400 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
12014-11-15 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el (python-indent-region-1)
4 (python-indent-region-2, python-indent-region-3)
5 (python-indent-region-4, python-indent-region-5): New tests.
6
12014-11-08 Michael Albinus <michael.albinus@gmx.de> 72014-11-08 Michael Albinus <michael.albinus@gmx.de>
2 8
3 Backport Tramp changes from trunk. 9 Backport Tramp changes from trunk.
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 39195fd7086..8c657c38b64 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -725,6 +725,110 @@ def b()
725 (python-tests-self-insert ":") 725 (python-tests-self-insert ":")
726 (should (= (current-indentation) 0)))) 726 (should (= (current-indentation) 0))))
727 727
728(ert-deftest python-indent-region-1 ()
729 "Test indentation case from Bug#18843."
730 (let ((contents "
731def foo ():
732 try:
733 pass
734 except:
735 pass
736"))
737 (python-tests-with-temp-buffer
738 contents
739 (python-indent-region (point-min) (point-max))
740 (should (string= (buffer-substring-no-properties (point-min) (point-max))
741 contents)))))
742
743(ert-deftest python-indent-region-2 ()
744 "Test region indentation on comments."
745 (let ((contents "
746def f():
747 if True:
748 pass
749
750# This is
751# some multiline
752# comment
753"))
754 (python-tests-with-temp-buffer
755 contents
756 (python-indent-region (point-min) (point-max))
757 (should (string= (buffer-substring-no-properties (point-min) (point-max))
758 contents)))))
759
760(ert-deftest python-indent-region-3 ()
761 "Test region indentation on comments."
762 (let ((contents "
763def f():
764 if True:
765 pass
766# This is
767# some multiline
768# comment
769")
770 (expected "
771def f():
772 if True:
773 pass
774 # This is
775 # some multiline
776 # comment
777"))
778 (python-tests-with-temp-buffer
779 contents
780 (python-indent-region (point-min) (point-max))
781 (should (string= (buffer-substring-no-properties (point-min) (point-max))
782 expected)))))
783
784(ert-deftest python-indent-region-4 ()
785 "Test region indentation block starts, dedenders and enders."
786 (let ((contents "
787def f():
788 if True:
789a = 5
790 else:
791 a = 10
792 return a
793")
794 (expected "
795def f():
796 if True:
797 a = 5
798 else:
799 a = 10
800 return a
801"))
802 (python-tests-with-temp-buffer
803 contents
804 (python-indent-region (point-min) (point-max))
805 (should (string= (buffer-substring-no-properties (point-min) (point-max))
806 expected)))))
807
808(ert-deftest python-indent-region-5 ()
809 "Test region indentation leaves strings untouched (start delimiter)."
810 (let ((contents "
811def f():
812'''
813this is
814a multiline
815string
816'''
817")
818 (expected "
819def f():
820 '''
821this is
822a multiline
823string
824'''
825"))
826 (python-tests-with-temp-buffer
827 contents
828 (python-indent-region (point-min) (point-max))
829 (should (string= (buffer-substring-no-properties (point-min) (point-max))
830 expected)))))
831
728 832
729;;; Navigation 833;;; Navigation
730 834