diff options
| author | kobarity | 2023-03-12 17:05:54 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2023-03-16 16:59:06 +0200 |
| commit | 5cf1de683b2414927e521c34daeee460fb7649f5 (patch) | |
| tree | 8f3602006d4454ddb7be376fea41dfe15e5f3c94 /test/lisp/progmodes/python-tests.el | |
| parent | 7385c991dff3466b37cf50628e7685cd53e71921 (diff) | |
| download | emacs-5cf1de683b2414927e521c34daeee460fb7649f5.tar.gz emacs-5cf1de683b2414927e521c34daeee460fb7649f5.zip | |
Fix python-fill-paragraph problems on filling strings (bug#62142)
* lisp/progmodes/python.el (python-syntax--context-compiler-macro)
(python-syntax-context): Add single-quoted-string and
triple-quoted-string as TYPE argument.
(python-info-triple-quoted-string-p): New helper function.
(python-fill-paragraph)
(python-fill-string): Use it.
* test/lisp/progmodes/python-tests.el (python-syntax-context-1)
(python-fill-paragraph-single-quoted-string-1)
(python-fill-paragraph-single-quoted-string-2)
(python-fill-paragraph-triple-quoted-string-1)
(python-info-triple-quoted-string-p-1)
(python-info-triple-quoted-string-p-2)
(python-info-triple-quoted-string-p-3): New tests.
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index e5a9d128bc5..ed4a08da6ab 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -255,6 +255,27 @@ aliqua." | |||
| 255 | 255 | ||
| 256 | ;;; Font-lock and syntax | 256 | ;;; Font-lock and syntax |
| 257 | 257 | ||
| 258 | (ert-deftest python-syntax-context-1 () | ||
| 259 | (python-tests-with-temp-buffer | ||
| 260 | " | ||
| 261 | # Comment | ||
| 262 | s = 'Single Quoted String' | ||
| 263 | t = '''Triple Quoted String''' | ||
| 264 | p = (1 + 2) | ||
| 265 | " | ||
| 266 | (python-tests-look-at "Comment") | ||
| 267 | (should (= (python-syntax-context 'comment) (pos-bol))) | ||
| 268 | (python-tests-look-at "Single") | ||
| 269 | (should (= (python-syntax-context 'string) (1- (point)))) | ||
| 270 | (should (= (python-syntax-context 'single-quoted-string) (1- (point)))) | ||
| 271 | (should-not (python-syntax-context 'triple-quoted-string)) | ||
| 272 | (python-tests-look-at "Triple") | ||
| 273 | (should (= (python-syntax-context 'string) (1- (point)))) | ||
| 274 | (should-not (python-syntax-context 'single-quoted-string)) | ||
| 275 | (should (= (python-syntax-context 'triple-quoted-string) (1- (point)))) | ||
| 276 | (python-tests-look-at "1 + 2") | ||
| 277 | (should (= (python-syntax-context 'paren) (1- (point)))))) | ||
| 278 | |||
| 258 | (ert-deftest python-syntax-after-python-backspace () | 279 | (ert-deftest python-syntax-after-python-backspace () |
| 259 | ;; `python-indent-dedent-line-backspace' garbles syntax | 280 | ;; `python-indent-dedent-line-backspace' garbles syntax |
| 260 | (python-tests-with-temp-buffer | 281 | (python-tests-with-temp-buffer |
| @@ -2052,6 +2073,54 @@ this is a test this is a test this is a test this is a test this is a test this | |||
| 2052 | (fill-paragraph) | 2073 | (fill-paragraph) |
| 2053 | (should (= (current-indentation) 0)))) | 2074 | (should (= (current-indentation) 0)))) |
| 2054 | 2075 | ||
| 2076 | (ert-deftest python-fill-paragraph-single-quoted-string-1 () | ||
| 2077 | "Single quoted string should not be filled." | ||
| 2078 | (let ((contents " | ||
| 2079 | s = 'abc def ghi jkl mno pqr stu vwx yz' | ||
| 2080 | ") | ||
| 2081 | (fill-column 20)) | ||
| 2082 | (python-tests-with-temp-buffer | ||
| 2083 | contents | ||
| 2084 | (python-tests-look-at "abc") | ||
| 2085 | (fill-paragraph) | ||
| 2086 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2087 | contents))))) | ||
| 2088 | |||
| 2089 | (ert-deftest python-fill-paragraph-single-quoted-string-2 () | ||
| 2090 | "Ensure no fill is performed after the end of the single quoted string." | ||
| 2091 | (let ((contents " | ||
| 2092 | s1 = 'abc' | ||
| 2093 | s2 = 'def' | ||
| 2094 | ")) | ||
| 2095 | (python-tests-with-temp-buffer | ||
| 2096 | contents | ||
| 2097 | (python-tests-look-at "abc") | ||
| 2098 | (fill-paragraph) | ||
| 2099 | (should (string= (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2100 | contents))))) | ||
| 2101 | |||
| 2102 | (ert-deftest python-fill-paragraph-triple-quoted-string-1 () | ||
| 2103 | "Triple quoted string should be filled." | ||
| 2104 | (let ((contents " | ||
| 2105 | s = '''abc def ghi jkl mno pqr stu vwx yz''' | ||
| 2106 | ") | ||
| 2107 | (expected " | ||
| 2108 | s = '''abc def ghi | ||
| 2109 | jkl mno pqr stu vwx | ||
| 2110 | yz''' | ||
| 2111 | ") | ||
| 2112 | (fill-column 20)) | ||
| 2113 | (dolist (look-at '("'''abc" "z'''")) | ||
| 2114 | (dolist (offset '(0 1 2 3)) | ||
| 2115 | (python-tests-with-temp-buffer | ||
| 2116 | contents | ||
| 2117 | (python-tests-look-at look-at) | ||
| 2118 | (forward-char offset) | ||
| 2119 | (fill-paragraph) | ||
| 2120 | (should (string= | ||
| 2121 | (buffer-substring-no-properties (point-min) (point-max)) | ||
| 2122 | expected))))))) | ||
| 2123 | |||
| 2055 | 2124 | ||
| 2056 | ;;; Mark | 2125 | ;;; Mark |
| 2057 | 2126 | ||
| @@ -6491,6 +6560,56 @@ class Class: | |||
| 6491 | (python-tests-look-at "'''Not a method docstring.'''") | 6560 | (python-tests-look-at "'''Not a method docstring.'''") |
| 6492 | (should (not (python-info-docstring-p))))) | 6561 | (should (not (python-info-docstring-p))))) |
| 6493 | 6562 | ||
| 6563 | (ert-deftest python-info-triple-quoted-string-p-1 () | ||
| 6564 | "Test triple quoted string." | ||
| 6565 | (python-tests-with-temp-buffer | ||
| 6566 | " | ||
| 6567 | t = '''Triple''' | ||
| 6568 | " | ||
| 6569 | (python-tests-look-at " '''Triple") | ||
| 6570 | (should-not | ||
| 6571 | (python-tests-should-not-move | ||
| 6572 | #'python-info-triple-quoted-string-p)) | ||
| 6573 | (forward-char) | ||
| 6574 | (let ((start-pos (+ (point) 2)) | ||
| 6575 | (eol (pos-eol))) | ||
| 6576 | (while (< (point) eol) | ||
| 6577 | (should (= (python-tests-should-not-move | ||
| 6578 | #'python-info-triple-quoted-string-p) | ||
| 6579 | start-pos)) | ||
| 6580 | (forward-char))) | ||
| 6581 | (dolist (pos `(,(point) ,(point-min) ,(point-max))) | ||
| 6582 | (goto-char pos) | ||
| 6583 | (should-not | ||
| 6584 | (python-tests-should-not-move | ||
| 6585 | #'python-info-triple-quoted-string-p))))) | ||
| 6586 | |||
| 6587 | (ert-deftest python-info-triple-quoted-string-p-2 () | ||
| 6588 | "Test empty triple quoted string." | ||
| 6589 | (python-tests-with-temp-buffer | ||
| 6590 | " | ||
| 6591 | e = '''''' | ||
| 6592 | " | ||
| 6593 | (python-tests-look-at "''''''") | ||
| 6594 | (let ((start-pos (+ (point) 2)) | ||
| 6595 | (eol (pos-eol))) | ||
| 6596 | (while (< (point) eol) | ||
| 6597 | (should (= (python-tests-should-not-move | ||
| 6598 | #'python-info-triple-quoted-string-p) | ||
| 6599 | start-pos)) | ||
| 6600 | (forward-char))))) | ||
| 6601 | |||
| 6602 | (ert-deftest python-info-triple-quoted-string-p-3 () | ||
| 6603 | "Test single quoted string." | ||
| 6604 | (python-tests-with-temp-buffer | ||
| 6605 | " | ||
| 6606 | s = 'Single' | ||
| 6607 | " | ||
| 6608 | (while (< (point) (point-max)) | ||
| 6609 | (should-not (python-tests-should-not-move | ||
| 6610 | #'python-info-triple-quoted-string-p)) | ||
| 6611 | (forward-char)))) | ||
| 6612 | |||
| 6494 | (ert-deftest python-info-encoding-from-cookie-1 () | 6613 | (ert-deftest python-info-encoding-from-cookie-1 () |
| 6495 | "Should detect it on first line." | 6614 | "Should detect it on first line." |
| 6496 | (python-tests-with-temp-buffer | 6615 | (python-tests-with-temp-buffer |