diff options
| author | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
|---|---|---|
| committer | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
| commit | 49ffcbf86a32a8a217538d4df3736fe069ccf35d (patch) | |
| tree | a5f16157cc20fb19a844473a6fbd2b434f4c8260 /test/lisp/progmodes/python-tests.el | |
| parent | af569fa3d90a717983b743eb97adbf869c6d1736 (diff) | |
| parent | 7ca1d782f5910d0c3978c6798a45c6854ec668c7 (diff) | |
| download | emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.tar.gz emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.zip | |
Merge branch 'master' into scratch/comp-static-data
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 518 |
1 files changed, 372 insertions, 146 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 4f24c042c6a..9323f72f384 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -136,20 +136,6 @@ STRING, it is skipped so the next STRING occurrence is selected." | |||
| 136 | while pos | 136 | while pos |
| 137 | collect (cons pos (get-text-property pos 'face)))) | 137 | collect (cons pos (get-text-property pos 'face)))) |
| 138 | 138 | ||
| 139 | (defun python-tests-assert-faces-after-change (content faces search replace) | ||
| 140 | "Assert that font faces for CONTENT are equal to FACES after change. | ||
| 141 | All occurrences of SEARCH are changed to REPLACE." | ||
| 142 | (python-tests-with-temp-buffer | ||
| 143 | content | ||
| 144 | ;; Force enable font-lock mode without jit-lock. | ||
| 145 | (rename-buffer "*python-font-lock-test*" t) | ||
| 146 | (let (noninteractive font-lock-support-mode) | ||
| 147 | (font-lock-mode)) | ||
| 148 | (while | ||
| 149 | (re-search-forward search nil t) | ||
| 150 | (replace-match replace)) | ||
| 151 | (should (equal faces (python-tests-get-buffer-faces))))) | ||
| 152 | |||
| 153 | (defun python-tests-self-insert (char-or-str) | 139 | (defun python-tests-self-insert (char-or-str) |
| 154 | "Call `self-insert-command' for chars in CHAR-OR-STR." | 140 | "Call `self-insert-command' for chars in CHAR-OR-STR." |
| 155 | (let ((chars | 141 | (let ((chars |
| @@ -255,6 +241,27 @@ aliqua." | |||
| 255 | 241 | ||
| 256 | ;;; Font-lock and syntax | 242 | ;;; Font-lock and syntax |
| 257 | 243 | ||
| 244 | (ert-deftest python-syntax-context-1 () | ||
| 245 | (python-tests-with-temp-buffer | ||
| 246 | " | ||
| 247 | # Comment | ||
| 248 | s = 'Single Quoted String' | ||
| 249 | t = '''Triple Quoted String''' | ||
| 250 | p = (1 + 2) | ||
| 251 | " | ||
| 252 | (python-tests-look-at "Comment") | ||
| 253 | (should (= (python-syntax-context 'comment) (pos-bol))) | ||
| 254 | (python-tests-look-at "Single") | ||
| 255 | (should (= (python-syntax-context 'string) (1- (point)))) | ||
| 256 | (should (= (python-syntax-context 'single-quoted-string) (1- (point)))) | ||
| 257 | (should-not (python-syntax-context 'triple-quoted-string)) | ||
| 258 | (python-tests-look-at "Triple") | ||
| 259 | (should (= (python-syntax-context 'string) (1- (point)))) | ||
| 260 | (should-not (python-syntax-context 'single-quoted-string)) | ||
| 261 | (should (= (python-syntax-context 'triple-quoted-string) (1- (point)))) | ||
| 262 | (python-tests-look-at "1 + 2") | ||
| 263 | (should (= (python-syntax-context 'paren) (1- (point)))))) | ||
| 264 | |||
| 258 | (ert-deftest python-syntax-after-python-backspace () | 265 | (ert-deftest python-syntax-after-python-backspace () |
| 259 | ;; `python-indent-dedent-line-backspace' garbles syntax | 266 | ;; `python-indent-dedent-line-backspace' garbles syntax |
| 260 | (python-tests-with-temp-buffer | 267 | (python-tests-with-temp-buffer |
| @@ -276,13 +283,6 @@ aliqua." | |||
| 276 | "def 1func():" | 283 | "def 1func():" |
| 277 | '((1 . font-lock-keyword-face) (4)))) | 284 | '((1 . font-lock-keyword-face) (4)))) |
| 278 | 285 | ||
| 279 | (ert-deftest python-font-lock-keywords-level-1-3 () | ||
| 280 | (python-tests-assert-faces | ||
| 281 | "def \\ | ||
| 282 | func():" | ||
| 283 | '((1 . font-lock-keyword-face) (4) | ||
| 284 | (15 . font-lock-function-name-face) (19)))) | ||
| 285 | |||
| 286 | (ert-deftest python-font-lock-assignment-statement-1 () | 286 | (ert-deftest python-font-lock-assignment-statement-1 () |
| 287 | (python-tests-assert-faces | 287 | (python-tests-assert-faces |
| 288 | "a, b, c = 1, 2, 3" | 288 | "a, b, c = 1, 2, 3" |
| @@ -474,129 +474,6 @@ def f(x: CustomInt) -> CustomInt: | |||
| 474 | (136 . font-lock-operator-face) (137) | 474 | (136 . font-lock-operator-face) (137) |
| 475 | (144 . font-lock-keyword-face) (150)))) | 475 | (144 . font-lock-keyword-face) (150)))) |
| 476 | 476 | ||
| 477 | (ert-deftest python-font-lock-assignment-statement-multiline-1 () | ||
| 478 | (python-tests-assert-faces-after-change | ||
| 479 | " | ||
| 480 | [ | ||
| 481 | a, | ||
| 482 | b | ||
| 483 | ] # ( | ||
| 484 | 1, | ||
| 485 | 2 | ||
| 486 | ) | ||
| 487 | " | ||
| 488 | '((1) | ||
| 489 | (8 . font-lock-variable-name-face) (9) | ||
| 490 | (15 . font-lock-variable-name-face) (16) | ||
| 491 | (19 . font-lock-operator-face) (20)) | ||
| 492 | "#" "=")) | ||
| 493 | |||
| 494 | (ert-deftest python-font-lock-assignment-statement-multiline-2 () | ||
| 495 | (python-tests-assert-faces-after-change | ||
| 496 | " | ||
| 497 | [ | ||
| 498 | *a | ||
| 499 | ] # 5, 6 | ||
| 500 | " | ||
| 501 | '((1) | ||
| 502 | (8 . font-lock-operator-face) | ||
| 503 | (9 . font-lock-variable-name-face) (10) | ||
| 504 | (13 . font-lock-operator-face) (14)) | ||
| 505 | "#" "=")) | ||
| 506 | |||
| 507 | (ert-deftest python-font-lock-assignment-statement-multiline-3 () | ||
| 508 | (python-tests-assert-faces-after-change | ||
| 509 | "a\\ | ||
| 510 | ,\\ | ||
| 511 | b\\ | ||
| 512 | ,\\ | ||
| 513 | c\\ | ||
| 514 | #\\ | ||
| 515 | 1\\ | ||
| 516 | ,\\ | ||
| 517 | 2\\ | ||
| 518 | ,\\ | ||
| 519 | 3" | ||
| 520 | '((1 . font-lock-variable-name-face) (2) | ||
| 521 | (15 . font-lock-variable-name-face) (16) | ||
| 522 | (29 . font-lock-variable-name-face) (30) | ||
| 523 | (36 . font-lock-operator-face) (37)) | ||
| 524 | "#" "=")) | ||
| 525 | |||
| 526 | (ert-deftest python-font-lock-assignment-statement-multiline-4 () | ||
| 527 | (python-tests-assert-faces-after-change | ||
| 528 | "a\\ | ||
| 529 | :\\ | ||
| 530 | int\\ | ||
| 531 | #\\ | ||
| 532 | 5" | ||
| 533 | '((1 . font-lock-variable-name-face) (2) | ||
| 534 | (15 . font-lock-builtin-face) (18) | ||
| 535 | (24 . font-lock-operator-face) (25)) | ||
| 536 | "#" "=")) | ||
| 537 | |||
| 538 | (ert-deftest python-font-lock-assignment-statement-multiline-5 () | ||
| 539 | (python-tests-assert-faces-after-change | ||
| 540 | "(\\ | ||
| 541 | a\\ | ||
| 542 | )\\ | ||
| 543 | #\\ | ||
| 544 | 5\\ | ||
| 545 | ;\\ | ||
| 546 | (\\ | ||
| 547 | b\\ | ||
| 548 | )\\ | ||
| 549 | #\\ | ||
| 550 | 6" | ||
| 551 | '((1) | ||
| 552 | (8 . font-lock-variable-name-face) (9) | ||
| 553 | (18 . font-lock-operator-face) (19) | ||
| 554 | (46 . font-lock-variable-name-face) (47) | ||
| 555 | (60 . font-lock-operator-face) (61)) | ||
| 556 | "#" "=")) | ||
| 557 | |||
| 558 | (ert-deftest python-font-lock-assignment-statement-multiline-6 () | ||
| 559 | (python-tests-assert-faces-after-change | ||
| 560 | "( | ||
| 561 | a | ||
| 562 | )\\ | ||
| 563 | #\\ | ||
| 564 | 5\\ | ||
| 565 | ;\\ | ||
| 566 | ( | ||
| 567 | b | ||
| 568 | )\\ | ||
| 569 | #\\ | ||
| 570 | 6" | ||
| 571 | '((1) | ||
| 572 | (7 . font-lock-variable-name-face) (8) | ||
| 573 | (16 . font-lock-operator-face) (17) | ||
| 574 | (43 . font-lock-variable-name-face) (44) | ||
| 575 | (56 . font-lock-operator-face) (57)) | ||
| 576 | "#" "=")) | ||
| 577 | |||
| 578 | (ert-deftest python-font-lock-operator-1 () | ||
| 579 | (python-tests-assert-faces | ||
| 580 | "1 << 2 ** 3 == +4%-5|~6&7^8%9" | ||
| 581 | '((1) | ||
| 582 | (3 . font-lock-operator-face) (5) | ||
| 583 | (8 . font-lock-operator-face) (10) | ||
| 584 | (13 . font-lock-operator-face) (15) | ||
| 585 | (16 . font-lock-operator-face) (17) | ||
| 586 | (18 . font-lock-operator-face) (20) | ||
| 587 | (21 . font-lock-operator-face) (23) | ||
| 588 | (24 . font-lock-operator-face) (25) | ||
| 589 | (26 . font-lock-operator-face) (27) | ||
| 590 | (28 . font-lock-operator-face) (29)))) | ||
| 591 | |||
| 592 | (ert-deftest python-font-lock-operator-2 () | ||
| 593 | "Keyword operators are font-locked as keywords." | ||
| 594 | (python-tests-assert-faces | ||
| 595 | "is_ is None" | ||
| 596 | '((1) | ||
| 597 | (5 . font-lock-keyword-face) (7) | ||
| 598 | (8 . font-lock-constant-face)))) | ||
| 599 | |||
| 600 | (ert-deftest python-font-lock-escape-sequence-string-newline () | 477 | (ert-deftest python-font-lock-escape-sequence-string-newline () |
| 601 | (python-tests-assert-faces | 478 | (python-tests-assert-faces |
| 602 | "'\\n' | 479 | "'\\n' |
| @@ -708,6 +585,7 @@ u\"\\n\"" | |||
| 708 | (845 . font-lock-string-face) (886)))) | 585 | (845 . font-lock-string-face) (886)))) |
| 709 | 586 | ||
| 710 | (ert-deftest python-font-lock-escape-sequence-bytes-newline () | 587 | (ert-deftest python-font-lock-escape-sequence-bytes-newline () |
| 588 | :expected-result :failed | ||
| 711 | (python-tests-assert-faces | 589 | (python-tests-assert-faces |
| 712 | "b'\\n' | 590 | "b'\\n' |
| 713 | b\"\\n\"" | 591 | b\"\\n\"" |
| @@ -720,6 +598,7 @@ b\"\\n\"" | |||
| 720 | (11 . font-lock-doc-face)))) | 598 | (11 . font-lock-doc-face)))) |
| 721 | 599 | ||
| 722 | (ert-deftest python-font-lock-escape-sequence-hex-octal () | 600 | (ert-deftest python-font-lock-escape-sequence-hex-octal () |
| 601 | :expected-result :failed | ||
| 723 | (python-tests-assert-faces | 602 | (python-tests-assert-faces |
| 724 | "b'\\x12 \\777 \\1\\23' | 603 | "b'\\x12 \\777 \\1\\23' |
| 725 | '\\x12 \\777 \\1\\23'" | 604 | '\\x12 \\777 \\1\\23'" |
| @@ -740,6 +619,7 @@ b\"\\n\"" | |||
| 740 | (36 . font-lock-doc-face)))) | 619 | (36 . font-lock-doc-face)))) |
| 741 | 620 | ||
| 742 | (ert-deftest python-font-lock-escape-sequence-unicode () | 621 | (ert-deftest python-font-lock-escape-sequence-unicode () |
| 622 | :expected-result :failed | ||
| 743 | (python-tests-assert-faces | 623 | (python-tests-assert-faces |
| 744 | "b'\\u1234 \\U00010348 \\N{Plus-Minus Sign}' | 624 | "b'\\u1234 \\U00010348 \\N{Plus-Minus Sign}' |
| 745 | '\\u1234 \\U00010348 \\N{Plus-Minus Sign}'" | 625 | '\\u1234 \\U00010348 \\N{Plus-Minus Sign}'" |
| @@ -754,6 +634,7 @@ b\"\\n\"" | |||
| 754 | (80 . font-lock-doc-face)))) | 634 | (80 . font-lock-doc-face)))) |
| 755 | 635 | ||
| 756 | (ert-deftest python-font-lock-raw-escape-sequence () | 636 | (ert-deftest python-font-lock-raw-escape-sequence () |
| 637 | :expected-result :failed | ||
| 757 | (python-tests-assert-faces | 638 | (python-tests-assert-faces |
| 758 | "rb'\\x12 \123 \\n' | 639 | "rb'\\x12 \123 \\n' |
| 759 | r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" | 640 | r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" |
| @@ -1118,7 +999,7 @@ while ((not some_condition) and | |||
| 1118 | (should (eq (car (python-indent-context)) :no-indent)) | 999 | (should (eq (car (python-indent-context)) :no-indent)) |
| 1119 | (should (= (python-indent-calculate-indentation) 0)) | 1000 | (should (= (python-indent-calculate-indentation) 0)) |
| 1120 | (forward-line 1) | 1001 | (forward-line 1) |
| 1121 | (should (eq (car (python-indent-context)) :inside-paren)) | 1002 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) |
| 1122 | (should (= (python-indent-calculate-indentation) 7)) | 1003 | (should (= (python-indent-calculate-indentation) 7)) |
| 1123 | (forward-line 1) | 1004 | (forward-line 1) |
| 1124 | (should (eq (car (python-indent-context)) :after-block-start)) | 1005 | (should (eq (car (python-indent-context)) :after-block-start)) |
| @@ -1153,6 +1034,118 @@ CHOICES = (('some', 'choice'), | |||
| 1153 | ;; This signals an error if the test fails | 1034 | ;; This signals an error if the test fails |
| 1154 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) | 1035 | (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) |
| 1155 | 1036 | ||
| 1037 | (ert-deftest python-indent-inside-paren-block-1 () | ||
| 1038 | "`python-indent-block-paren-deeper' set to nil (default). | ||
| 1039 | See Bug#62696." | ||
| 1040 | (python-tests-with-temp-buffer | ||
| 1041 | " | ||
| 1042 | if ('VALUE' in my_unnecessarily_long_dictionary and | ||
| 1043 | some_other_long_condition_case): | ||
| 1044 | do_something() | ||
| 1045 | elif (some_case or | ||
| 1046 | another_case): | ||
| 1047 | do_another() | ||
| 1048 | " | ||
| 1049 | (python-tests-look-at "if") | ||
| 1050 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1051 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1052 | (forward-line 1) | ||
| 1053 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1054 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1055 | (forward-line 1) | ||
| 1056 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1057 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1058 | (forward-line 1) | ||
| 1059 | (should (eq (car (python-indent-context)) :at-dedenter-block-start)) | ||
| 1060 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1061 | (forward-line 1) | ||
| 1062 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1063 | (should (= (python-indent-calculate-indentation) 6)) | ||
| 1064 | (forward-line 1) | ||
| 1065 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1066 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 1067 | |||
| 1068 | (ert-deftest python-indent-inside-paren-block-2 () | ||
| 1069 | "`python-indent-block-paren-deeper' set to t. | ||
| 1070 | See Bug#62696." | ||
| 1071 | (python-tests-with-temp-buffer | ||
| 1072 | " | ||
| 1073 | if ('VALUE' in my_unnecessarily_long_dictionary and | ||
| 1074 | some_other_long_condition_case): | ||
| 1075 | do_something() | ||
| 1076 | elif (some_case or | ||
| 1077 | another_case): | ||
| 1078 | do_another() | ||
| 1079 | " | ||
| 1080 | (let ((python-indent-block-paren-deeper t)) | ||
| 1081 | (python-tests-look-at "if") | ||
| 1082 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1083 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1084 | (forward-line 1) | ||
| 1085 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1086 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 1087 | (forward-line 1) | ||
| 1088 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1089 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1090 | (forward-line 1) | ||
| 1091 | (should (eq (car (python-indent-context)) :at-dedenter-block-start)) | ||
| 1092 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1093 | (forward-line 1) | ||
| 1094 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1095 | (should (= (python-indent-calculate-indentation) 6)) | ||
| 1096 | (forward-line 1) | ||
| 1097 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1098 | (should (= (python-indent-calculate-indentation) 4))))) | ||
| 1099 | |||
| 1100 | (ert-deftest python-indent-inside-paren-block-3 () | ||
| 1101 | "With backslash. `python-indent-block-paren-deeper' set to nil (default). | ||
| 1102 | See Bug#62696." | ||
| 1103 | (python-tests-with-temp-buffer | ||
| 1104 | " | ||
| 1105 | if 'VALUE' in my_uncessarily_long_dictionary and\\ | ||
| 1106 | (some_other_long_condition_case or | ||
| 1107 | another_case): | ||
| 1108 | do_something() | ||
| 1109 | " | ||
| 1110 | (python-tests-look-at "if") | ||
| 1111 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1112 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1113 | (forward-line 1) | ||
| 1114 | (should (eq (car (python-indent-context)) | ||
| 1115 | :after-backslash-block-continuation)) | ||
| 1116 | (should (= (python-indent-calculate-indentation) 3)) | ||
| 1117 | (forward-line 1) | ||
| 1118 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1119 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1120 | (forward-line 1) | ||
| 1121 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1122 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 1123 | |||
| 1124 | (ert-deftest python-indent-inside-paren-block-4 () | ||
| 1125 | "With backslash. `python-indent-block-paren-deeper' set to t. | ||
| 1126 | See Bug#62696." | ||
| 1127 | (python-tests-with-temp-buffer | ||
| 1128 | " | ||
| 1129 | if 'VALUE' in my_uncessarily_long_dictionary and\\ | ||
| 1130 | (some_other_long_condition_case or | ||
| 1131 | another_case): | ||
| 1132 | do_something() | ||
| 1133 | " | ||
| 1134 | (let ((python-indent-block-paren-deeper t)) | ||
| 1135 | (python-tests-look-at "if") | ||
| 1136 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1137 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1138 | (forward-line 1) | ||
| 1139 | (should (eq (car (python-indent-context)) | ||
| 1140 | :after-backslash-block-continuation)) | ||
| 1141 | (should (= (python-indent-calculate-indentation) 3)) | ||
| 1142 | (forward-line 1) | ||
| 1143 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) | ||
| 1144 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 1145 | (forward-line 1) | ||
| 1146 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1147 | (should (= (python-indent-calculate-indentation) 4))))) | ||
| 1148 | |||
| 1156 | (ert-deftest python-indent-after-block-1 () | 1149 | (ert-deftest python-indent-after-block-1 () |
| 1157 | "The most simple after-block case that shouldn't fail." | 1150 | "The most simple after-block case that shouldn't fail." |
| 1158 | (python-tests-with-temp-buffer | 1151 | (python-tests-with-temp-buffer |
| @@ -1649,7 +1642,7 @@ a == 4): | |||
| 1649 | (should (= (python-indent-calculate-indentation) 0)) | 1642 | (should (= (python-indent-calculate-indentation) 0)) |
| 1650 | (should (= (python-indent-calculate-indentation t) 0)) | 1643 | (should (= (python-indent-calculate-indentation t) 0)) |
| 1651 | (python-tests-look-at "a == 4):\n") | 1644 | (python-tests-look-at "a == 4):\n") |
| 1652 | (should (eq (car (python-indent-context)) :inside-paren)) | 1645 | (should (eq (car (python-indent-context)) :inside-paren-from-block)) |
| 1653 | (should (= (python-indent-calculate-indentation) 6)) | 1646 | (should (= (python-indent-calculate-indentation) 6)) |
| 1654 | (python-indent-line) | 1647 | (python-indent-line) |
| 1655 | (should (= (python-indent-calculate-indentation t) 4)) | 1648 | (should (= (python-indent-calculate-indentation t) 4)) |
| @@ -1658,6 +1651,21 @@ a == 4): | |||
| 1658 | (python-indent-line t) | 1651 | (python-indent-line t) |
| 1659 | (should (= (python-indent-calculate-indentation t) 6)))) | 1652 | (should (= (python-indent-calculate-indentation t) 6)))) |
| 1660 | 1653 | ||
| 1654 | (ert-deftest python-indent-dedenters-9 () | ||
| 1655 | "Test de-indentation for the case keyword." | ||
| 1656 | (python-tests-with-temp-buffer | ||
| 1657 | " | ||
| 1658 | match a: | ||
| 1659 | case 1: | ||
| 1660 | print(1) | ||
| 1661 | case 2 | ||
| 1662 | " | ||
| 1663 | (python-tests-look-at "case 2") | ||
| 1664 | (should (eq (car (python-indent-context)) :at-dedenter-block-start)) | ||
| 1665 | (should (= (python-indent-calculate-indentation) 4)) | ||
| 1666 | (python-indent-line t) | ||
| 1667 | (should (= (python-indent-calculate-indentation t) 4)))) | ||
| 1668 | |||
| 1661 | (ert-deftest python-indent-inside-string-1 () | 1669 | (ert-deftest python-indent-inside-string-1 () |
| 1662 | "Test indentation for strings." | 1670 | "Test indentation for strings." |
| 1663 | (python-tests-with-temp-buffer | 1671 | (python-tests-with-temp-buffer |
| @@ -1982,6 +1990,32 @@ match foo: | |||
| 1982 | (should (eq (car (python-indent-context)) :after-block-start)) | 1990 | (should (eq (car (python-indent-context)) :after-block-start)) |
| 1983 | (should (= (python-indent-calculate-indentation) 8)))) | 1991 | (should (= (python-indent-calculate-indentation) 8)))) |
| 1984 | 1992 | ||
| 1993 | (ert-deftest python-indent-after-re-match () | ||
| 1994 | "Test BUG 62031 regression." | ||
| 1995 | (python-tests-with-temp-buffer | ||
| 1996 | " | ||
| 1997 | def test_re(string): | ||
| 1998 | if re.match('^[a-c]+$', string): | ||
| 1999 | print('yes') | ||
| 2000 | else: | ||
| 2001 | " | ||
| 2002 | (python-tests-look-at "else:") | ||
| 2003 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 2004 | |||
| 2005 | (ert-deftest python-indent-after-bare-match () | ||
| 2006 | "Test BUG 62031 regression." | ||
| 2007 | (python-tests-with-temp-buffer | ||
| 2008 | " | ||
| 2009 | from re import match | ||
| 2010 | |||
| 2011 | def test_re(string): | ||
| 2012 | if match('^[a-c]+$', string): | ||
| 2013 | print('yes') | ||
| 2014 | else: | ||
| 2015 | " | ||
| 2016 | (python-tests-look-at "else:") | ||
| 2017 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 2018 | |||
| 1985 | 2019 | ||
| 1986 | ;;; Filling | 2020 | ;;; Filling |
| 1987 | 2021 | ||
| @@ -2011,6 +2045,54 @@ this is a test this is a test this is a test this is a test this is a test this | |||
| 2011 | (fill-paragraph) | 2045 | (fill-paragraph) |
| 2012 | (should (= (current-indentation) 0)))) | 2046 | (should (= (current-indentation) 0)))) |
| 2013 | 2047 | ||
| 2048 | (ert-deftest python-fill-paragraph-single-quoted-string-1 () | ||
| 2049 | "Single quoted string should not be filled." | ||
| 2050 | (let ((contents " | ||
| 2051 | s = 'abc def ghi jkl mno pqr stu vwx yz' | ||
| 2052 | ") | ||
| 2053 | (fill-column 20)) | ||
| 2054 | (python-tests-with-temp-buffer | ||
| 2055 | contents | ||
| 2056 | (python-tests-look-at "abc") | ||
| 2057 | (fill-paragraph) | ||
| 2058 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2059 | contents))))) | ||
| 2060 | |||
| 2061 | (ert-deftest python-fill-paragraph-single-quoted-string-2 () | ||
| 2062 | "Ensure no fill is performed after the end of the single quoted string." | ||
| 2063 | (let ((contents " | ||
| 2064 | s1 = 'abc' | ||
| 2065 | s2 = 'def' | ||
| 2066 | ")) | ||
| 2067 | (python-tests-with-temp-buffer | ||
| 2068 | contents | ||
| 2069 | (python-tests-look-at "abc") | ||
| 2070 | (fill-paragraph) | ||
| 2071 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2072 | contents))))) | ||
| 2073 | |||
| 2074 | (ert-deftest python-fill-paragraph-triple-quoted-string-1 () | ||
| 2075 | "Triple quoted string should be filled." | ||
| 2076 | (let ((contents " | ||
| 2077 | s = '''abc def ghi jkl mno pqr stu vwx yz''' | ||
| 2078 | ") | ||
| 2079 | (expected " | ||
| 2080 | s = '''abc def ghi | ||
| 2081 | jkl mno pqr stu vwx | ||
| 2082 | yz''' | ||
| 2083 | ") | ||
| 2084 | (fill-column 20)) | ||
| 2085 | (dolist (look-at '("'''abc" "z'''")) | ||
| 2086 | (dolist (offset '(0 1 2 3)) | ||
| 2087 | (python-tests-with-temp-buffer | ||
| 2088 | contents | ||
| 2089 | (python-tests-look-at look-at) | ||
| 2090 | (forward-char offset) | ||
| 2091 | (fill-paragraph) | ||
| 2092 | (should (string= | ||
| 2093 | (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2094 | expected))))))) | ||
| 2095 | |||
| 2014 | 2096 | ||
| 2015 | ;;; Mark | 2097 | ;;; Mark |
| 2016 | 2098 | ||
| @@ -2943,6 +3025,36 @@ string | |||
| 2943 | "'\n''\n" | 3025 | "'\n''\n" |
| 2944 | (python-nav-end-of-statement))) | 3026 | (python-nav-end-of-statement))) |
| 2945 | 3027 | ||
| 3028 | (ert-deftest python-nav-end-of-statement-3 () | ||
| 3029 | "Test unmatched quotes (Bug#58780)." | ||
| 3030 | (python-tests-with-temp-buffer | ||
| 3031 | " | ||
| 3032 | ' \"\"\" | ||
| 3033 | v = 1 | ||
| 3034 | " | ||
| 3035 | (python-tests-look-at "v =") | ||
| 3036 | (should (= (save-excursion | ||
| 3037 | (python-nav-end-of-statement) | ||
| 3038 | (point)) | ||
| 3039 | (save-excursion | ||
| 3040 | (point-max)))))) | ||
| 3041 | |||
| 3042 | (ert-deftest python-nav-end-of-statement-4 () | ||
| 3043 | (python-tests-with-temp-buffer | ||
| 3044 | " | ||
| 3045 | abc = 'a\\ | ||
| 3046 | b\\ | ||
| 3047 | c' | ||
| 3048 | d = '''d''' | ||
| 3049 | " | ||
| 3050 | (python-tests-look-at "b\\") | ||
| 3051 | (should (= (save-excursion | ||
| 3052 | (python-nav-end-of-statement) | ||
| 3053 | (point)) | ||
| 3054 | (save-excursion | ||
| 3055 | (python-tests-look-at "c'") | ||
| 3056 | (pos-eol)))))) | ||
| 3057 | |||
| 2946 | (ert-deftest python-nav-forward-statement-1 () | 3058 | (ert-deftest python-nav-forward-statement-1 () |
| 2947 | (python-tests-with-temp-buffer | 3059 | (python-tests-with-temp-buffer |
| 2948 | " | 3060 | " |
| @@ -5209,6 +5321,20 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3): | |||
| 5209 | (should (string= (python-info-current-defun t) | 5321 | (should (string= (python-info-current-defun t) |
| 5210 | "def decoratorFunctionWithArguments")))) | 5322 | "def decoratorFunctionWithArguments")))) |
| 5211 | 5323 | ||
| 5324 | (ert-deftest python-info-current-defun-4 () | ||
| 5325 | "Ensure unmatched quotes do not cause hang (Bug#58780)." | ||
| 5326 | (python-tests-with-temp-buffer | ||
| 5327 | " | ||
| 5328 | def func(): | ||
| 5329 | ' \"\"\" | ||
| 5330 | v = 1 | ||
| 5331 | " | ||
| 5332 | (python-tests-look-at "v = 1") | ||
| 5333 | (should (string= (python-info-current-defun) | ||
| 5334 | "func")) | ||
| 5335 | (should (string= (python-info-current-defun t) | ||
| 5336 | "def func")))) | ||
| 5337 | |||
| 5212 | (ert-deftest python-info-current-symbol-1 () | 5338 | (ert-deftest python-info-current-symbol-1 () |
| 5213 | (python-tests-with-temp-buffer | 5339 | (python-tests-with-temp-buffer |
| 5214 | " | 5340 | " |
| @@ -5786,6 +5912,26 @@ def func(): | |||
| 5786 | (equal (list (python-tests-look-at "if (" -1 t)) | 5912 | (equal (list (python-tests-look-at "if (" -1 t)) |
| 5787 | (python-info-dedenter-opening-block-positions))))) | 5913 | (python-info-dedenter-opening-block-positions))))) |
| 5788 | 5914 | ||
| 5915 | (ert-deftest python-info-dedenter-opening-block-positions-7 () | ||
| 5916 | "Test case blocks." | ||
| 5917 | (python-tests-with-temp-buffer | ||
| 5918 | " | ||
| 5919 | match a: | ||
| 5920 | case 1: | ||
| 5921 | match b: | ||
| 5922 | case 2: | ||
| 5923 | something() | ||
| 5924 | case 3: | ||
| 5925 | " | ||
| 5926 | (python-tests-look-at "case 1:") | ||
| 5927 | (should-not (python-info-dedenter-opening-block-positions)) | ||
| 5928 | (python-tests-look-at "case 2:") | ||
| 5929 | (should-not (python-info-dedenter-opening-block-positions)) | ||
| 5930 | (python-tests-look-at "case 3:") | ||
| 5931 | (equal (list (python-tests-look-at "case 2:" -1) | ||
| 5932 | (python-tests-look-at "case 1:" -1 t)) | ||
| 5933 | (python-info-dedenter-opening-block-positions)))) | ||
| 5934 | |||
| 5789 | (ert-deftest python-info-dedenter-opening-block-message-1 () | 5935 | (ert-deftest python-info-dedenter-opening-block-message-1 () |
| 5790 | "Test dedenters inside strings are ignored." | 5936 | "Test dedenters inside strings are ignored." |
| 5791 | (python-tests-with-temp-buffer | 5937 | (python-tests-with-temp-buffer |
| @@ -5971,6 +6117,24 @@ elif b: | |||
| 5971 | (point)) | 6117 | (point)) |
| 5972 | (python-info-dedenter-statement-p))))) | 6118 | (python-info-dedenter-statement-p))))) |
| 5973 | 6119 | ||
| 6120 | (ert-deftest python-info-dedenter-statement-p-6 () | ||
| 6121 | "Test case keyword." | ||
| 6122 | (python-tests-with-temp-buffer | ||
| 6123 | " | ||
| 6124 | match a: # Comment | ||
| 6125 | case 1: | ||
| 6126 | match b: | ||
| 6127 | case 2: | ||
| 6128 | something() | ||
| 6129 | case 3: | ||
| 6130 | " | ||
| 6131 | (python-tests-look-at "case 1:") | ||
| 6132 | (should-not (python-info-dedenter-statement-p)) | ||
| 6133 | (python-tests-look-at "case 2:") | ||
| 6134 | (should-not (python-info-dedenter-statement-p)) | ||
| 6135 | (python-tests-look-at "case 3:") | ||
| 6136 | (should (= (point) (python-info-dedenter-statement-p))))) | ||
| 6137 | |||
| 5974 | (ert-deftest python-info-line-ends-backslash-p-1 () | 6138 | (ert-deftest python-info-line-ends-backslash-p-1 () |
| 5975 | (python-tests-with-temp-buffer | 6139 | (python-tests-with-temp-buffer |
| 5976 | " | 6140 | " |
| @@ -6406,6 +6570,68 @@ class Class: | |||
| 6406 | (python-tests-look-at "'''Not a method docstring.'''") | 6570 | (python-tests-look-at "'''Not a method docstring.'''") |
| 6407 | (should (not (python-info-docstring-p))))) | 6571 | (should (not (python-info-docstring-p))))) |
| 6408 | 6572 | ||
| 6573 | (ert-deftest python-info-docstring-p-7 () | ||
| 6574 | "Test string in a dictionary." | ||
| 6575 | (python-tests-with-temp-buffer | ||
| 6576 | " | ||
| 6577 | {'Not a docstring': 1} | ||
| 6578 | 'Also not a docstring' | ||
| 6579 | " | ||
| 6580 | (python-tests-look-at "Not a docstring") | ||
| 6581 | (should-not (python-info-docstring-p)) | ||
| 6582 | (python-tests-look-at "Also not a docstring") | ||
| 6583 | (should-not (python-info-docstring-p)))) | ||
| 6584 | |||
| 6585 | (ert-deftest python-info-triple-quoted-string-p-1 () | ||
| 6586 | "Test triple quoted string." | ||
| 6587 | (python-tests-with-temp-buffer | ||
| 6588 | " | ||
| 6589 | t = '''Triple''' | ||
| 6590 | " | ||
| 6591 | (python-tests-look-at " '''Triple") | ||
| 6592 | (should-not | ||
| 6593 | (python-tests-should-not-move | ||
| 6594 | #'python-info-triple-quoted-string-p)) | ||
| 6595 | (forward-char) | ||
| 6596 | (let ((start-pos (+ (point) 2)) | ||
| 6597 | (eol (pos-eol))) | ||
| 6598 | (while (< (point) eol) | ||
| 6599 | (should (= (python-tests-should-not-move | ||
| 6600 | #'python-info-triple-quoted-string-p) | ||
| 6601 | start-pos)) | ||
| 6602 | (forward-char))) | ||
| 6603 | (dolist (pos `(,(point) ,(point-min) ,(point-max))) | ||
| 6604 | (goto-char pos) | ||
| 6605 | (should-not | ||
| 6606 | (python-tests-should-not-move | ||
| 6607 | #'python-info-triple-quoted-string-p))))) | ||
| 6608 | |||
| 6609 | (ert-deftest python-info-triple-quoted-string-p-2 () | ||
| 6610 | "Test empty triple quoted string." | ||
| 6611 | (python-tests-with-temp-buffer | ||
| 6612 | " | ||
| 6613 | e = '''''' | ||
| 6614 | " | ||
| 6615 | (python-tests-look-at "''''''") | ||
| 6616 | (let ((start-pos (+ (point) 2)) | ||
| 6617 | (eol (pos-eol))) | ||
| 6618 | (while (< (point) eol) | ||
| 6619 | (should (= (python-tests-should-not-move | ||
| 6620 | #'python-info-triple-quoted-string-p) | ||
| 6621 | start-pos)) | ||
| 6622 | (forward-char))))) | ||
| 6623 | |||
| 6624 | (ert-deftest python-info-triple-quoted-string-p-3 () | ||
| 6625 | "Test single quoted string." | ||
| 6626 | (python-tests-with-temp-buffer | ||
| 6627 | " | ||
| 6628 | s = 'Single' | ||
| 6629 | " | ||
| 6630 | (while (< (point) (point-max)) | ||
| 6631 | (should-not (python-tests-should-not-move | ||
| 6632 | #'python-info-triple-quoted-string-p)) | ||
| 6633 | (forward-char)))) | ||
| 6634 | |||
| 6409 | (ert-deftest python-info-encoding-from-cookie-1 () | 6635 | (ert-deftest python-info-encoding-from-cookie-1 () |
| 6410 | "Should detect it on first line." | 6636 | "Should detect it on first line." |
| 6411 | (python-tests-with-temp-buffer | 6637 | (python-tests-with-temp-buffer |