diff options
| author | kobarity | 2022-05-16 15:40:17 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-16 15:40:17 +0200 |
| commit | c44908c0593a2c3aab6468144643ccd003084afa (patch) | |
| tree | 43bd441f1a6086b999173139ec19c0b07ba7a72f /test/lisp/progmodes/python-tests.el | |
| parent | ed71839c33f9dad1de4bdf6911dafbe4a571136b (diff) | |
| download | emacs-c44908c0593a2c3aab6468144643ccd003084afa.tar.gz emacs-c44908c0593a2c3aab6468144643ccd003084afa.zip | |
Fix Python highlighting of some assignment statements
* lisp/progmodes/python.el (python-rx): Limit not-simple-operator
to a single line (bug#51362).
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 01b233cc425..98b55a5f8bc 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -95,6 +95,19 @@ STRING, it is skipped so the next STRING occurrence is selected." | |||
| 95 | found-point | 95 | found-point |
| 96 | (and restore-point (goto-char starting-point))))) | 96 | (and restore-point (goto-char starting-point))))) |
| 97 | 97 | ||
| 98 | (defun python-tests-assert-faces (content faces) | ||
| 99 | "Assert that font faces for CONTENT are equal to FACES." | ||
| 100 | (python-tests-with-temp-buffer content | ||
| 101 | (font-lock-ensure nil nil) | ||
| 102 | (should (equal faces (python-tests-get-buffer-faces))))) | ||
| 103 | |||
| 104 | (defun python-tests-get-buffer-faces () | ||
| 105 | "Return a list of (position . face) for each face change positions." | ||
| 106 | (cl-loop for pos = (point-min) | ||
| 107 | then (next-single-property-change pos 'face) | ||
| 108 | while pos | ||
| 109 | collect (cons pos (get-text-property pos 'face)))) | ||
| 110 | |||
| 98 | (defun python-tests-self-insert (char-or-str) | 111 | (defun python-tests-self-insert (char-or-str) |
| 99 | "Call `self-insert-command' for chars in CHAR-OR-STR." | 112 | "Call `self-insert-command' for chars in CHAR-OR-STR." |
| 100 | (let ((chars | 113 | (let ((chars |
| @@ -201,6 +214,153 @@ aliqua." | |||
| 201 | (should (string= (buffer-string) "\"\"")) | 214 | (should (string= (buffer-string) "\"\"")) |
| 202 | (should (null (nth 3 (syntax-ppss)))))) | 215 | (should (null (nth 3 (syntax-ppss)))))) |
| 203 | 216 | ||
| 217 | (ert-deftest python-font-lock-assignment-statement-1 () | ||
| 218 | (python-tests-assert-faces | ||
| 219 | "a, b, c = 1, 2, 3" | ||
| 220 | '((1 . font-lock-variable-name-face) (2) | ||
| 221 | (4 . font-lock-variable-name-face) (5) | ||
| 222 | (7 . font-lock-variable-name-face) (8)))) | ||
| 223 | |||
| 224 | (ert-deftest python-font-lock-assignment-statement-2 () | ||
| 225 | (python-tests-assert-faces | ||
| 226 | "a, *b, c = 1, 2, 3, 4, 5" | ||
| 227 | '((1 . font-lock-variable-name-face) (2) | ||
| 228 | (5 . font-lock-variable-name-face) (6) | ||
| 229 | (8 . font-lock-variable-name-face) (9)))) | ||
| 230 | |||
| 231 | (ert-deftest python-font-lock-assignment-statement-3 () | ||
| 232 | (python-tests-assert-faces | ||
| 233 | "[a, b] = (1, 2)" | ||
| 234 | '((1) | ||
| 235 | (2 . font-lock-variable-name-face) (3) | ||
| 236 | (5 . font-lock-variable-name-face) (6)))) | ||
| 237 | |||
| 238 | (ert-deftest python-font-lock-assignment-statement-4 () | ||
| 239 | (python-tests-assert-faces | ||
| 240 | "(l[1], l[2]) = (10, 11)" | ||
| 241 | '((1) | ||
| 242 | (2 . font-lock-variable-name-face) (3) | ||
| 243 | (8 . font-lock-variable-name-face) (9)))) | ||
| 244 | |||
| 245 | (ert-deftest python-font-lock-assignment-statement-5 () | ||
| 246 | (python-tests-assert-faces | ||
| 247 | "(a, b, c, *d) = *x, y = 5, 6, 7, 8, 9" | ||
| 248 | '((1) | ||
| 249 | (2 . font-lock-variable-name-face) (3) | ||
| 250 | (5 . font-lock-variable-name-face) (6) | ||
| 251 | (8 . font-lock-variable-name-face) (9) | ||
| 252 | (12 . font-lock-variable-name-face) (13) | ||
| 253 | (18 . font-lock-variable-name-face) (19) | ||
| 254 | (21 . font-lock-variable-name-face) (22)))) | ||
| 255 | |||
| 256 | (ert-deftest python-font-lock-assignment-statement-6 () | ||
| 257 | (python-tests-assert-faces | ||
| 258 | "(a,) = 'foo'," | ||
| 259 | '((1) | ||
| 260 | (2 . font-lock-variable-name-face) (3) | ||
| 261 | (8 . font-lock-string-face) (13)))) | ||
| 262 | |||
| 263 | (ert-deftest python-font-lock-assignment-statement-7 () | ||
| 264 | (python-tests-assert-faces | ||
| 265 | "(*a,) = ['foo', 'bar', 'baz']" | ||
| 266 | '((1) | ||
| 267 | (3 . font-lock-variable-name-face) (4) | ||
| 268 | (10 . font-lock-string-face) (15) | ||
| 269 | (17 . font-lock-string-face) (22) | ||
| 270 | (24 . font-lock-string-face) (29)))) | ||
| 271 | |||
| 272 | (ert-deftest python-font-lock-assignment-statement-8 () | ||
| 273 | (python-tests-assert-faces | ||
| 274 | "d = D('a', ['b'], 'c')" | ||
| 275 | '((1 . font-lock-variable-name-face) (2) | ||
| 276 | (7 . font-lock-string-face) (10) | ||
| 277 | (13 . font-lock-string-face) (16) | ||
| 278 | (19 . font-lock-string-face) (22)))) | ||
| 279 | |||
| 280 | (ert-deftest python-font-lock-assignment-statement-9 () | ||
| 281 | (python-tests-assert-faces | ||
| 282 | "d.x, d.y[0], *d.z = 'a', 'b', 'c', 'd', 'e'" | ||
| 283 | '((1) | ||
| 284 | (3 . font-lock-variable-name-face) (4) | ||
| 285 | (8 . font-lock-variable-name-face) (9) | ||
| 286 | (17 . font-lock-variable-name-face) (18) | ||
| 287 | (21 . font-lock-string-face) (24) | ||
| 288 | (26 . font-lock-string-face) (29) | ||
| 289 | (31 . font-lock-string-face) (34) | ||
| 290 | (36 . font-lock-string-face) (39) | ||
| 291 | (41 . font-lock-string-face)))) | ||
| 292 | |||
| 293 | (ert-deftest python-font-lock-assignment-statement-10 () | ||
| 294 | (python-tests-assert-faces | ||
| 295 | "a: int = 5" | ||
| 296 | '((1 . font-lock-variable-name-face) (2) | ||
| 297 | (4 . font-lock-builtin-face) (7)))) | ||
| 298 | |||
| 299 | (ert-deftest python-font-lock-assignment-statement-11 () | ||
| 300 | (python-tests-assert-faces | ||
| 301 | "b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo')" | ||
| 302 | '((1 . font-lock-variable-name-face) (2) | ||
| 303 | (19 . font-lock-builtin-face) (22) | ||
| 304 | (40 . font-lock-builtin-face) (43) | ||
| 305 | (46 . font-lock-builtin-face) (49) | ||
| 306 | (55 . font-lock-constant-face) (59) | ||
| 307 | (61 . font-lock-string-face) (66)))) | ||
| 308 | |||
| 309 | (ert-deftest python-font-lock-assignment-statement-12 () | ||
| 310 | (python-tests-assert-faces | ||
| 311 | "c: Collection = {1, 2, 3}" | ||
| 312 | '((1 . font-lock-variable-name-face) (2)))) | ||
| 313 | |||
| 314 | (ert-deftest python-font-lock-assignment-statement-13 () | ||
| 315 | (python-tests-assert-faces | ||
| 316 | "d: Mapping[int, str] = {1: 'bar', 2: 'baz'}" | ||
| 317 | '((1 . font-lock-variable-name-face) (2) | ||
| 318 | (12 . font-lock-builtin-face) (15) | ||
| 319 | (17 . font-lock-builtin-face) (20) | ||
| 320 | (28 . font-lock-string-face) (33) | ||
| 321 | (38 . font-lock-string-face) (43)))) | ||
| 322 | |||
| 323 | (ert-deftest python-font-lock-assignment-statement-14 () | ||
| 324 | (python-tests-assert-faces | ||
| 325 | "(a) = 5; (b) = 6" | ||
| 326 | '((1) | ||
| 327 | (2 . font-lock-variable-name-face) (3) | ||
| 328 | (11 . font-lock-variable-name-face) (12)))) | ||
| 329 | |||
| 330 | (ert-deftest python-font-lock-assignment-statement-15 () | ||
| 331 | (python-tests-assert-faces | ||
| 332 | "[a] = 5,; [b] = 6," | ||
| 333 | '((1) | ||
| 334 | (2 . font-lock-variable-name-face) (3) | ||
| 335 | (12 . font-lock-variable-name-face) (13)))) | ||
| 336 | |||
| 337 | (ert-deftest python-font-lock-assignment-statement-16 () | ||
| 338 | (python-tests-assert-faces | ||
| 339 | "[*a] = 5, 6; [*b] = 7, 8" | ||
| 340 | '((1) | ||
| 341 | (3 . font-lock-variable-name-face) (4) | ||
| 342 | (16 . font-lock-variable-name-face) (17)))) | ||
| 343 | |||
| 344 | (ert-deftest python-font-lock-assignment-statement-17 () | ||
| 345 | (python-tests-assert-faces | ||
| 346 | "CustomInt = int | ||
| 347 | |||
| 348 | def f(x: CustomInt) -> CustomInt: | ||
| 349 | y = x + 1 | ||
| 350 | ys: Sequence[CustomInt] = [y, y + 1] | ||
| 351 | res: CustomInt = sum(ys) + 1 | ||
| 352 | return res | ||
| 353 | " | ||
| 354 | '((1 . font-lock-variable-name-face) (10) | ||
| 355 | (13 . font-lock-builtin-face) (16) | ||
| 356 | (18 . font-lock-keyword-face) (21) | ||
| 357 | (22 . font-lock-function-name-face) (23) | ||
| 358 | (56 . font-lock-variable-name-face) (57) | ||
| 359 | (70 . font-lock-variable-name-face) (72) | ||
| 360 | (111 . font-lock-variable-name-face) (114) | ||
| 361 | (128 . font-lock-builtin-face) (131) | ||
| 362 | (144 . font-lock-keyword-face) (150)))) | ||
| 363 | |||
| 204 | 364 | ||
| 205 | ;;; Indentation | 365 | ;;; Indentation |
| 206 | 366 | ||