diff options
| author | Marcin Borkowski | 2017-03-31 13:06:06 +0200 |
|---|---|---|
| committer | Marcin Borkowski | 2017-05-12 11:36:27 +0200 |
| commit | 22fc91704be4737865b3715e5278dc78029791bd (patch) | |
| tree | be0dcd1fb3fa25bbfb01467a8dac6716056da217 /test | |
| parent | 6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b (diff) | |
| download | emacs-22fc91704be4737865b3715e5278dc78029791bd.tar.gz emacs-22fc91704be4737865b3715e5278dc78029791bd.zip | |
Fix Bug#21072 and rework `mark-defun'
* test/lisp/progmodes/elisp-mode-tests.el (mark-defun-test-buffer):
New variable
(mark-defun-no-arg-region-inactive)
(mark-defun-no-arg-region-active)
(mark-defun-arg-region-active)
(mark-defun-pos-arg-region-inactive)
(mark-defun-neg-arg-region-inactive, mark-defun-bob): Add tests for
the new `mark-defun'.
* lisp/emacs-lisp/lisp.el (beginning-of-defun--in-emptyish-line-p):
New function.
(beginning-of-defun-comments): New function.
(mark-defun): Fix bug#21072, also rewrite large parts of `mark-defun'
to accept a numerical prefix argument.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-tests.el | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index f6039f78eb1..2119758bb77 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el | |||
| @@ -342,5 +342,252 @@ a marker." | |||
| 342 | `(let ,marker-list | 342 | `(let ,marker-list |
| 343 | ,@body)))) | 343 | ,@body)))) |
| 344 | 344 | ||
| 345 | ;;; mark-defun | ||
| 346 | |||
| 347 | (defvar mark-defun-test-buffer | ||
| 348 | ";; Comment header | ||
| 349 | =!before-1= | ||
| 350 | \(defun func-1 (arg) | ||
| 351 | =!inside-1=\"docstring\" | ||
| 352 | body) | ||
| 353 | =!after-1==!before-2= | ||
| 354 | ;; Comment before a defun | ||
| 355 | \(d=!inside-2=efun func-2 (arg) | ||
| 356 | \"docstring\" | ||
| 357 | body) | ||
| 358 | =!after-2==!before-3= | ||
| 359 | \(defun func-3 (arg) | ||
| 360 | \"docstring\"=!inside-3= | ||
| 361 | body) | ||
| 362 | =!after-3==!before-4=(defun func-4 (arg) | ||
| 363 | \"docstring\"=!inside-4= | ||
| 364 | body) | ||
| 365 | =!after-4= | ||
| 366 | ;; end | ||
| 367 | " | ||
| 368 | "Test buffer for `mark-defun'.") | ||
| 369 | |||
| 370 | (ert-deftest mark-defun-no-arg-region-inactive () | ||
| 371 | "Test `mark-defun' with no prefix argument and inactive | ||
| 372 | region." | ||
| 373 | (setq last-command nil) | ||
| 374 | (elisp-tests-with-temp-buffer | ||
| 375 | mark-defun-test-buffer | ||
| 376 | ;; mark-defun inside a defun, with comments and an empty line | ||
| 377 | ;; before | ||
| 378 | (goto-char inside-1) | ||
| 379 | (mark-defun) | ||
| 380 | (should (= (point) before-1)) | ||
| 381 | (should (= (mark) after-1)) | ||
| 382 | ;; mark-defun inside a defun with comments before | ||
| 383 | (deactivate-mark) | ||
| 384 | (goto-char inside-2) | ||
| 385 | (mark-defun) | ||
| 386 | (should (= (point) before-2)) | ||
| 387 | (should (= (mark) after-2)) | ||
| 388 | ;; mark-defun inside a defun with empty line before | ||
| 389 | (deactivate-mark) | ||
| 390 | (goto-char inside-3) | ||
| 391 | (mark-defun) | ||
| 392 | (should (= (point) before-3)) | ||
| 393 | (should (= (mark) after-3)) | ||
| 394 | ;; mark-defun inside a defun with another one right before | ||
| 395 | (deactivate-mark) | ||
| 396 | (goto-char inside-4) | ||
| 397 | (mark-defun) | ||
| 398 | (should (= (point) before-4)) | ||
| 399 | (should (= (mark) after-4)) | ||
| 400 | ;; mark-defun between a comment and a defun | ||
| 401 | (deactivate-mark) | ||
| 402 | (goto-char before-1) | ||
| 403 | (mark-defun) | ||
| 404 | (should (= (point) before-1)) | ||
| 405 | (should (= (mark) after-1)) | ||
| 406 | ;; mark-defun between defuns | ||
| 407 | (deactivate-mark) | ||
| 408 | (goto-char before-3) | ||
| 409 | (mark-defun) | ||
| 410 | (should (= (point) before-3)) | ||
| 411 | (should (= (mark) after-3)) | ||
| 412 | ;; mark-defun in comment right before the defun | ||
| 413 | (deactivate-mark) | ||
| 414 | (goto-char before-2) | ||
| 415 | (mark-defun) | ||
| 416 | (should (= (point) before-2)) | ||
| 417 | (should (= (mark) after-2)))) | ||
| 418 | |||
| 419 | (ert-deftest mark-defun-no-arg-region-active () | ||
| 420 | "Test `mark-defun' with no prefix argument and active | ||
| 421 | region." | ||
| 422 | (transient-mark-mode 1) | ||
| 423 | (setq last-command nil) | ||
| 424 | (elisp-tests-with-temp-buffer | ||
| 425 | mark-defun-test-buffer | ||
| 426 | ;; mark-defun when a defun is marked | ||
| 427 | (goto-char before-1) | ||
| 428 | (set-mark after-1) | ||
| 429 | (mark-defun) | ||
| 430 | (should (= (point) before-1)) | ||
| 431 | (should (= (mark) after-2)) | ||
| 432 | ;; mark-defun when two defuns are marked | ||
| 433 | (deactivate-mark) | ||
| 434 | (goto-char before-1) | ||
| 435 | (set-mark after-2) | ||
| 436 | (mark-defun) | ||
| 437 | (should (= (point) before-1)) | ||
| 438 | (should (= (mark) after-3)))) | ||
| 439 | |||
| 440 | (ert-deftest mark-defun-arg-region-active () | ||
| 441 | "Test `mark-defun' with a prefix arg and active region." | ||
| 442 | (transient-mark-mode 1) | ||
| 443 | (setq last-command nil) | ||
| 444 | (elisp-tests-with-temp-buffer | ||
| 445 | mark-defun-test-buffer | ||
| 446 | ;; mark-defun with positive arg when a defun is marked | ||
| 447 | (goto-char before-1) | ||
| 448 | (set-mark after-1) | ||
| 449 | (mark-defun 2) | ||
| 450 | (should (= (point) before-1)) | ||
| 451 | (should (= (mark) after-3)) | ||
| 452 | ;; mark-defun with arg=-1 when a defun is marked | ||
| 453 | (goto-char before-2) | ||
| 454 | (set-mark after-2) | ||
| 455 | (mark-defun -1) | ||
| 456 | (should (= (point) before-1)) | ||
| 457 | (should (= (mark) after-2)) | ||
| 458 | ;; mark-defun with arg=-2 when a defun is marked | ||
| 459 | (goto-char before-3) | ||
| 460 | (set-mark after-3) | ||
| 461 | (mark-defun -2) | ||
| 462 | (should (= (point) before-1)) | ||
| 463 | (should (= (mark) after-3)))) | ||
| 464 | |||
| 465 | (ert-deftest mark-defun-pos-arg-region-inactive () | ||
| 466 | "Test `mark-defun' with positive argument and inactive | ||
| 467 | region." | ||
| 468 | (setq last-command nil) | ||
| 469 | (elisp-tests-with-temp-buffer | ||
| 470 | mark-defun-test-buffer | ||
| 471 | ;; mark-defun with positive arg inside a defun | ||
| 472 | (goto-char inside-1) | ||
| 473 | (mark-defun 2) | ||
| 474 | (should (= (point) before-1)) | ||
| 475 | (should (= (mark) after-2)) | ||
| 476 | ;; mark-defun with positive arg between defuns | ||
| 477 | (deactivate-mark) | ||
| 478 | (goto-char before-3) | ||
| 479 | (mark-defun 2) | ||
| 480 | (should (= (point) before-3)) | ||
| 481 | (should (= (mark) after-4)) | ||
| 482 | ;; mark-defun with positive arg in a comment | ||
| 483 | (deactivate-mark) | ||
| 484 | (goto-char before-2) | ||
| 485 | (mark-defun 2) | ||
| 486 | (should (= (point) before-2)) | ||
| 487 | (should (= (mark) after-3)))) | ||
| 488 | |||
| 489 | (ert-deftest mark-defun-neg-arg-region-inactive () | ||
| 490 | "Test `mark-defun' with negative argument and inactive | ||
| 491 | region." | ||
| 492 | (setq last-command nil) | ||
| 493 | (elisp-tests-with-temp-buffer | ||
| 494 | mark-defun-test-buffer | ||
| 495 | ;; mark-defun with arg=-1 inside a defun | ||
| 496 | (goto-char inside-1) | ||
| 497 | (mark-defun -1) | ||
| 498 | (should (= (point) before-1)) | ||
| 499 | (should (= (mark) after-1)) | ||
| 500 | ;; mark-defun with arg=-1 between defuns | ||
| 501 | (deactivate-mark) | ||
| 502 | (goto-char after-2) | ||
| 503 | (mark-defun -1) | ||
| 504 | (should (= (point) before-2)) | ||
| 505 | (should (= (mark) after-2)) | ||
| 506 | ;; mark-defun with arg=-1 in a comment | ||
| 507 | ;; (this is probably not an optimal behavior...) | ||
| 508 | (deactivate-mark) | ||
| 509 | (goto-char before-2) | ||
| 510 | (mark-defun -1) | ||
| 511 | (should (= (point) before-1)) | ||
| 512 | (should (= (mark) after-1)) | ||
| 513 | ;; mark-defun with arg=-2 inside a defun | ||
| 514 | (deactivate-mark) | ||
| 515 | (goto-char inside-4) | ||
| 516 | (mark-defun -2) | ||
| 517 | (should (= (point) before-3)) | ||
| 518 | (should (= (mark) after-4)) | ||
| 519 | ;; mark-defun with arg=-2 between defuns | ||
| 520 | (deactivate-mark) | ||
| 521 | (goto-char before-3) | ||
| 522 | (mark-defun -2) | ||
| 523 | (should (= (point) before-1)) | ||
| 524 | (should (= (mark) after-2))) | ||
| 525 | (elisp-tests-with-temp-buffer ; test case submitted by Drew Adams | ||
| 526 | "(defun a () | ||
| 527 | nil) | ||
| 528 | =!before-b=(defun b () | ||
| 529 | =!in-b= nil) | ||
| 530 | =!after-b=;;;; | ||
| 531 | \(defun c () | ||
| 532 | nil) | ||
| 533 | " | ||
| 534 | (setq last-command nil) | ||
| 535 | (goto-char in-b) | ||
| 536 | (mark-defun -1) | ||
| 537 | (should (= (point) before-b)) | ||
| 538 | (should (= (mark) after-b)))) | ||
| 539 | |||
| 540 | (ert-deftest mark-defun-bob () | ||
| 541 | "Test `mark-defun' at the beginning of buffer." | ||
| 542 | ;; Bob, comment, newline, defun | ||
| 543 | (setq last-command nil) | ||
| 544 | (elisp-tests-with-temp-buffer | ||
| 545 | ";; Comment at the bob | ||
| 546 | =!before= | ||
| 547 | \(defun func (arg)=!inside= | ||
| 548 | \"docstring\" | ||
| 549 | body) | ||
| 550 | =!after=" | ||
| 551 | (goto-char inside) | ||
| 552 | (mark-defun) | ||
| 553 | (should (= (point) before)) | ||
| 554 | (should (= (mark) after))) | ||
| 555 | ;; Bob, newline, comment, defun | ||
| 556 | (elisp-tests-with-temp-buffer | ||
| 557 | "=!before= | ||
| 558 | ;; Comment before the defun | ||
| 559 | \(defun func (arg)=!inside= | ||
| 560 | \"docstring\" | ||
| 561 | body) | ||
| 562 | =!after=" | ||
| 563 | (goto-char inside) | ||
| 564 | (mark-defun) | ||
| 565 | (should (= (point) before)) | ||
| 566 | (should (= (mark) after))) | ||
| 567 | ;; Bob, comment, defun | ||
| 568 | (elisp-tests-with-temp-buffer | ||
| 569 | "=!before=;; Comment at the bob before the defun | ||
| 570 | \(defun func (arg)=!inside= | ||
| 571 | \"docstring\" | ||
| 572 | body) | ||
| 573 | =!after=" | ||
| 574 | (goto-char inside) | ||
| 575 | (mark-defun) | ||
| 576 | (should (= (point) before)) | ||
| 577 | (should (= (mark) after))) | ||
| 578 | ;; Bob, newline, comment, newline, defun | ||
| 579 | (elisp-tests-with-temp-buffer | ||
| 580 | " | ||
| 581 | ;; Comment before the defun | ||
| 582 | =!before= | ||
| 583 | \(defun func (arg)=!inside= | ||
| 584 | \"docstring\" | ||
| 585 | body) | ||
| 586 | =!after=" | ||
| 587 | (goto-char inside) | ||
| 588 | (mark-defun) | ||
| 589 | (should (= (point) before)) | ||
| 590 | (should (= (mark) after)))) | ||
| 591 | |||
| 345 | (provide 'lisp-tests) | 592 | (provide 'lisp-tests) |
| 346 | ;;; lisp-tests.el ends here | 593 | ;;; lisp-tests.el ends here |