diff options
| author | kobarity | 2023-06-18 23:47:25 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2023-06-24 15:11:39 +0300 |
| commit | 9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d (patch) | |
| tree | 2c894775d3092898b6ef6cd993b66e64256aab8d /test/lisp/progmodes/python-tests.el | |
| parent | 5b7e999e24f6cd446961ac441f69af021528623b (diff) | |
| download | emacs-9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d.tar.gz emacs-9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d.zip | |
Fix Python indentation of continuation lines within parens
* lisp/progmodes/python.el (python-indent-context): Add a new indent
context `:inside-paren-continuation-line'.
(python-indent--calculate-indentation): Use the new indent context.
* test/lisp/progmodes/python-tests.el (python-indent-pep8-2)
(python-indent-pep8-3)
(python-indent-inside-paren-1)
(python-indent-inside-paren-2)
(python-indent-inside-paren-3)
(python-indent-inside-paren-6)
(python-indent-after-backslash-2): Change to use the new indent
context.
(python-indent-inside-paren-8)
(python-indent-inside-paren-9): New tests. (Bug#63959)
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 89 |
1 files changed, 77 insertions, 12 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 9323f72f384..54e32cbf07b 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -683,7 +683,7 @@ def long_function_name( | |||
| 683 | (should (= (python-indent-calculate-indentation) 8)) | 683 | (should (= (python-indent-calculate-indentation) 8)) |
| 684 | (python-tests-look-at "var_four):") | 684 | (python-tests-look-at "var_four):") |
| 685 | (should (eq (car (python-indent-context)) | 685 | (should (eq (car (python-indent-context)) |
| 686 | :inside-paren-newline-start-from-block)) | 686 | :inside-paren-continuation-line)) |
| 687 | (should (= (python-indent-calculate-indentation) 8)) | 687 | (should (= (python-indent-calculate-indentation) 8)) |
| 688 | (python-tests-look-at "print (var_one)") | 688 | (python-tests-look-at "print (var_one)") |
| 689 | (should (eq (car (python-indent-context)) | 689 | (should (eq (car (python-indent-context)) |
| @@ -707,8 +707,8 @@ foo = long_function_name( | |||
| 707 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 707 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| 708 | (should (= (python-indent-calculate-indentation) 4)) | 708 | (should (= (python-indent-calculate-indentation) 4)) |
| 709 | (python-tests-look-at "var_three, var_four)") | 709 | (python-tests-look-at "var_three, var_four)") |
| 710 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 710 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 711 | (should (= (python-indent-calculate-indentation) 4)))) | 711 | (should (= (python-indent-calculate-indentation) 2)))) |
| 712 | 712 | ||
| 713 | (ert-deftest python-indent-hanging-close-paren () | 713 | (ert-deftest python-indent-hanging-close-paren () |
| 714 | "Like first pep8 case, but with hanging close paren." ;; See Bug#20742. | 714 | "Like first pep8 case, but with hanging close paren." ;; See Bug#20742. |
| @@ -864,7 +864,7 @@ data = { | |||
| 864 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 864 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| 865 | (should (= (python-indent-calculate-indentation) 4)) | 865 | (should (= (python-indent-calculate-indentation) 4)) |
| 866 | (python-tests-look-at "{") | 866 | (python-tests-look-at "{") |
| 867 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 867 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 868 | (should (= (python-indent-calculate-indentation) 4)) | 868 | (should (= (python-indent-calculate-indentation) 4)) |
| 869 | (python-tests-look-at "'objlist': [") | 869 | (python-tests-look-at "'objlist': [") |
| 870 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 870 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| @@ -876,20 +876,20 @@ data = { | |||
| 876 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 876 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| 877 | (should (= (python-indent-calculate-indentation) 16)) | 877 | (should (= (python-indent-calculate-indentation) 16)) |
| 878 | (python-tests-look-at "'name': 'first',") | 878 | (python-tests-look-at "'name': 'first',") |
| 879 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 879 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 880 | (should (= (python-indent-calculate-indentation) 16)) | 880 | (should (= (python-indent-calculate-indentation) 16)) |
| 881 | (python-tests-look-at "},") | 881 | (python-tests-look-at "},") |
| 882 | (should (eq (car (python-indent-context)) | 882 | (should (eq (car (python-indent-context)) |
| 883 | :inside-paren-at-closing-nested-paren)) | 883 | :inside-paren-at-closing-nested-paren)) |
| 884 | (should (= (python-indent-calculate-indentation) 12)) | 884 | (should (= (python-indent-calculate-indentation) 12)) |
| 885 | (python-tests-look-at "{") | 885 | (python-tests-look-at "{") |
| 886 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 886 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 887 | (should (= (python-indent-calculate-indentation) 12)) | 887 | (should (= (python-indent-calculate-indentation) 12)) |
| 888 | (python-tests-look-at "'pk': 2,") | 888 | (python-tests-look-at "'pk': 2,") |
| 889 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 889 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| 890 | (should (= (python-indent-calculate-indentation) 16)) | 890 | (should (= (python-indent-calculate-indentation) 16)) |
| 891 | (python-tests-look-at "'name': 'second',") | 891 | (python-tests-look-at "'name': 'second',") |
| 892 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 892 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 893 | (should (= (python-indent-calculate-indentation) 16)) | 893 | (should (= (python-indent-calculate-indentation) 16)) |
| 894 | (python-tests-look-at "}") | 894 | (python-tests-look-at "}") |
| 895 | (should (eq (car (python-indent-context)) | 895 | (should (eq (car (python-indent-context)) |
| @@ -933,7 +933,7 @@ data = {'key': { | |||
| 933 | (should (eq (car (python-indent-context)) :inside-paren)) | 933 | (should (eq (car (python-indent-context)) :inside-paren)) |
| 934 | (should (= (python-indent-calculate-indentation) 9)) | 934 | (should (= (python-indent-calculate-indentation) 9)) |
| 935 | (python-tests-look-at "{'pk': 2,") | 935 | (python-tests-look-at "{'pk': 2,") |
| 936 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 936 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 937 | (should (= (python-indent-calculate-indentation) 8)) | 937 | (should (= (python-indent-calculate-indentation) 8)) |
| 938 | (python-tests-look-at "'name': 'second'}") | 938 | (python-tests-look-at "'name': 'second'}") |
| 939 | (should (eq (car (python-indent-context)) :inside-paren)) | 939 | (should (eq (car (python-indent-context)) :inside-paren)) |
| @@ -966,10 +966,10 @@ data = ('these', | |||
| 966 | (should (eq (car (python-indent-context)) :inside-paren)) | 966 | (should (eq (car (python-indent-context)) :inside-paren)) |
| 967 | (should (= (python-indent-calculate-indentation) 8)) | 967 | (should (= (python-indent-calculate-indentation) 8)) |
| 968 | (forward-line 1) | 968 | (forward-line 1) |
| 969 | (should (eq (car (python-indent-context)) :inside-paren)) | 969 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 970 | (should (= (python-indent-calculate-indentation) 8)) | 970 | (should (= (python-indent-calculate-indentation) 8)) |
| 971 | (forward-line 1) | 971 | (forward-line 1) |
| 972 | (should (eq (car (python-indent-context)) :inside-paren)) | 972 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 973 | (should (= (python-indent-calculate-indentation) 8)))) | 973 | (should (= (python-indent-calculate-indentation) 8)))) |
| 974 | 974 | ||
| 975 | (ert-deftest python-indent-inside-paren-4 () | 975 | (ert-deftest python-indent-inside-paren-4 () |
| @@ -1023,7 +1023,7 @@ CHOICES = (('some', 'choice'), | |||
| 1023 | (should (eq (car (python-indent-context)) :inside-paren)) | 1023 | (should (eq (car (python-indent-context)) :inside-paren)) |
| 1024 | (should (= (python-indent-calculate-indentation) 11)) | 1024 | (should (= (python-indent-calculate-indentation) 11)) |
| 1025 | (forward-line 1) | 1025 | (forward-line 1) |
| 1026 | (should (eq (car (python-indent-context)) :inside-paren)) | 1026 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 1027 | (should (= (python-indent-calculate-indentation) 11)))) | 1027 | (should (= (python-indent-calculate-indentation) 11)))) |
| 1028 | 1028 | ||
| 1029 | (ert-deftest python-indent-inside-paren-7 () | 1029 | (ert-deftest python-indent-inside-paren-7 () |
| @@ -1034,6 +1034,71 @@ CHOICES = (('some', 'choice'), | |||
| 1034 | ;; This signals an error if the test fails | 1034 | ;; This signals an error if the test fails |
| 1035 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) | 1035 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) |
| 1036 | 1036 | ||
| 1037 | (ert-deftest python-indent-inside-paren-8 () | ||
| 1038 | "Test for Bug#63959." | ||
| 1039 | (python-tests-with-temp-buffer | ||
| 1040 | " | ||
| 1041 | for a in [ # comment | ||
| 1042 | 'some', # Manually indented. | ||
| 1043 | 'thing']: # Respect indentation of the previous line. | ||
| 1044 | " | ||
| 1045 | (python-tests-look-at "for a in [ # comment") | ||
| 1046 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1047 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1048 | (forward-line 1) | ||
| 1049 | (should (eq (car (python-indent-context)) | ||
| 1050 | :inside-paren-newline-start-from-block)) | ||
| 1051 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 1052 | (forward-line 1) | ||
| 1053 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) | ||
| 1054 | (should (= (python-indent-calculate-indentation) 10)))) | ||
| 1055 | |||
| 1056 | (ert-deftest python-indent-inside-paren-9 () | ||
| 1057 | "Test `:inside-paren-continuation-line'." | ||
| 1058 | (python-tests-with-temp-buffer | ||
| 1059 | " | ||
| 1060 | a = ((( | ||
| 1061 | 1, 2), | ||
| 1062 | 3), # Do not respect the indentation of the previous line | ||
| 1063 | 4) # Do not respect the indentation of the previous line | ||
| 1064 | b = (( | ||
| 1065 | 1, 2), # Manually indented | ||
| 1066 | 3, # Do not respect the indentation of the previous line | ||
| 1067 | 4, # Respect the indentation of the previous line | ||
| 1068 | 5, # Manually indented | ||
| 1069 | 6) # Respect the indentation of the previous line | ||
| 1070 | " | ||
| 1071 | (python-tests-look-at "a = (((") | ||
| 1072 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1073 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1074 | (forward-line 1) | ||
| 1075 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | ||
| 1076 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1077 | (forward-line 1) | ||
| 1078 | (should (eq (car (python-indent-context)) :inside-paren)) | ||
| 1079 | (should (= (python-indent-calculate-indentation) 6)) | ||
| 1080 | (forward-line 1) | ||
| 1081 | (should (eq (car (python-indent-context)) :inside-paren)) | ||
| 1082 | (should (= (python-indent-calculate-indentation) 5)) | ||
| 1083 | (forward-line 1) | ||
| 1084 | (should (eq (car (python-indent-context)) :after-line)) | ||
| 1085 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1086 | (forward-line 1) | ||
| 1087 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | ||
| 1088 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1089 | (forward-line 1) | ||
| 1090 | (should (eq (car (python-indent-context)) :inside-paren)) | ||
| 1091 | (should (= (python-indent-calculate-indentation) 5)) | ||
| 1092 | (forward-line 1) | ||
| 1093 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) | ||
| 1094 | (should (= (python-indent-calculate-indentation) 5)) | ||
| 1095 | (forward-line 1) | ||
| 1096 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) | ||
| 1097 | (should (= (python-indent-calculate-indentation) 5)) | ||
| 1098 | (forward-line 1) | ||
| 1099 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) | ||
| 1100 | (should (= (python-indent-calculate-indentation) 8)))) | ||
| 1101 | |||
| 1037 | (ert-deftest python-indent-inside-paren-block-1 () | 1102 | (ert-deftest python-indent-inside-paren-block-1 () |
| 1038 | "`python-indent-block-paren-deeper' set to nil (default). | 1103 | "`python-indent-block-paren-deeper' set to nil (default). |
| 1039 | See Bug#62696." | 1104 | See Bug#62696." |
| @@ -1271,7 +1336,7 @@ objects = Thing.objects.all() \\ | |||
| 1271 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 1336 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) |
| 1272 | (should (= (python-indent-calculate-indentation) 27)) | 1337 | (should (= (python-indent-calculate-indentation) 27)) |
| 1273 | (python-tests-look-at "status='bought'") | 1338 | (python-tests-look-at "status='bought'") |
| 1274 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)) | 1339 | (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) |
| 1275 | (should (= (python-indent-calculate-indentation) 27)) | 1340 | (should (= (python-indent-calculate-indentation) 27)) |
| 1276 | (python-tests-look-at ") \\") | 1341 | (python-tests-look-at ") \\") |
| 1277 | (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren)) | 1342 | (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren)) |