diff options
| author | Lele Gaifax | 2022-05-22 10:44:31 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-22 13:22:59 +0200 |
| commit | 35d0190b0b91c085c73bbe6c2b8e93ea8288b589 (patch) | |
| tree | 38ba5e3c42cf4508c4167cbf96ecb8dbbd92a2b2 /test | |
| parent | ae8b1b8fd476b8c6240c1337c0c51763d4879ac9 (diff) | |
| download | emacs-35d0190b0b91c085c73bbe6c2b8e93ea8288b589.tar.gz emacs-35d0190b0b91c085c73bbe6c2b8e93ea8288b589.zip | |
Properly indent Python PEP634 match/case blocks
Python 3.10 introduced the "structural pattern matching" syntax, and
commit 139042eb8629e6fd49b2c3002a8fc4d1aabd174d told font-lock about the
new keywords. This adds them also as block-start statements, to enable
proper indentation of such blocks.
* lisp/progmodes/python.el (python-rx): Add "match" and "case" as
block-start keywords.
* test/lisp/progmodes/python-tests.el (python-indent-after-match-block,
python-indent-after-case-block): New tests to verify indentation of
"match" and "case" blocks (bug#55572).
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index ee7b66610aa..a3f778bbbe9 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -1516,6 +1516,31 @@ this is an arbitrarily | |||
| 1516 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) | 1516 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) |
| 1517 | expected))))) | 1517 | expected))))) |
| 1518 | 1518 | ||
| 1519 | (ert-deftest python-indent-after-match-block () | ||
| 1520 | "Test PEP634 match." | ||
| 1521 | (python-tests-with-temp-buffer | ||
| 1522 | " | ||
| 1523 | match foo: | ||
| 1524 | " | ||
| 1525 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1526 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1527 | (goto-char (point-max)) | ||
| 1528 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1529 | (should (= (python-indent-calculate-indentation) 4)))) | ||
| 1530 | |||
| 1531 | (ert-deftest python-indent-after-case-block () | ||
| 1532 | "Test PEP634 case." | ||
| 1533 | (python-tests-with-temp-buffer | ||
| 1534 | " | ||
| 1535 | match foo: | ||
| 1536 | case 1: | ||
| 1537 | " | ||
| 1538 | (should (eq (car (python-indent-context)) :no-indent)) | ||
| 1539 | (should (= (python-indent-calculate-indentation) 0)) | ||
| 1540 | (goto-char (point-max)) | ||
| 1541 | (should (eq (car (python-indent-context)) :after-block-start)) | ||
| 1542 | (should (= (python-indent-calculate-indentation) 8)))) | ||
| 1543 | |||
| 1519 | 1544 | ||
| 1520 | ;;; Filling | 1545 | ;;; Filling |
| 1521 | 1546 | ||