diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/calendar/todo-mode-tests.el | 190 |
1 files changed, 186 insertions, 4 deletions
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el index 159294f8162..325faeff514 100644 --- a/test/lisp/calendar/todo-mode-tests.el +++ b/test/lisp/calendar/todo-mode-tests.el | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | (require 'ert) | 27 | (require 'ert) |
| 28 | (require 'ert-x) | ||
| 28 | (require 'todo-mode) | 29 | (require 'todo-mode) |
| 29 | 30 | ||
| 30 | (defvar todo-test-data-dir | 31 | (defvar todo-test-data-dir |
| @@ -561,11 +562,12 @@ source file is different." | |||
| 561 | ;; Headers in the todo file are still hidden. | 562 | ;; Headers in the todo file are still hidden. |
| 562 | (should (equal (overlay-get (todo-get-overlay 'header) 'display) ""))))) | 563 | (should (equal (overlay-get (todo-get-overlay 'header) 'display) ""))))) |
| 563 | 564 | ||
| 564 | (defun todo-test--insert-item (item &optional priority) | 565 | (defun todo-test--insert-item (item &optional priority |
| 566 | _arg diary-type date-type time where) | ||
| 565 | "Insert string ITEM into current category with priority PRIORITY. | 567 | "Insert string ITEM into current category with priority PRIORITY. |
| 566 | Use defaults for all other item insertion parameters. This | 568 | The remaining arguments (except _ARG, which is ignored) specify |
| 567 | provides a noninteractive API for todo-insert-item for use in | 569 | item insertion parameters. This provides a noninteractive API |
| 568 | automatic testing." | 570 | for todo-insert-item for use in automatic testing." |
| 569 | (cl-letf (((symbol-function 'read-from-minibuffer) | 571 | (cl-letf (((symbol-function 'read-from-minibuffer) |
| 570 | (lambda (_prompt) item)) | 572 | (lambda (_prompt) item)) |
| 571 | ((symbol-function 'read-number) ; For todo-set-item-priority | 573 | ((symbol-function 'read-number) ; For todo-set-item-priority |
| @@ -581,6 +583,186 @@ automatic testing." | |||
| 581 | (todo-test--insert-item item 1) | 583 | (todo-test--insert-item item 1) |
| 582 | (should (equal (overlay-get (todo-get-overlay 'header) 'display) ""))))) | 584 | (should (equal (overlay-get (todo-get-overlay 'header) 'display) ""))))) |
| 583 | 585 | ||
| 586 | (defun todo-test--done-items-separator (&optional eol) | ||
| 587 | "Set up test of command interaction with done items separator. | ||
| 588 | With non-nil argument EOL, return the position at the end of the | ||
| 589 | separator, otherwise, return the position at the beginning." | ||
| 590 | (todo-test--show 1) | ||
| 591 | (goto-char (point-max)) | ||
| 592 | ;; See comment about recentering in todo-test-raise-lower-priority. | ||
| 593 | (set-window-buffer nil (current-buffer)) | ||
| 594 | (todo-toggle-view-done-items) | ||
| 595 | ;; FIXME: Point should now be on the first done item, and in batch | ||
| 596 | ;; testing it is, so we have to move back one line to the done items | ||
| 597 | ;; separator; but for some reason, in the graphical test | ||
| 598 | ;; environment, it stays on the last empty line of the todo items | ||
| 599 | ;; section, so there we have to advance one character to the done | ||
| 600 | ;; items separator. | ||
| 601 | (if (display-graphic-p) | ||
| 602 | (forward-char) | ||
| 603 | (forward-line -1)) | ||
| 604 | (if eol (forward-char))) | ||
| 605 | |||
| 606 | (ert-deftest todo-test-done-items-separator01-bol () | ||
| 607 | "Test item copying and here insertion at BOL of separator. | ||
| 608 | Both should be user errors." | ||
| 609 | (with-todo-test | ||
| 610 | (todo-test--done-items-separator) | ||
| 611 | (let* ((copy-err "Item copying is not valid here") | ||
| 612 | (here-err "Item insertion is not valid here") | ||
| 613 | (insert-item-test (lambda (where) | ||
| 614 | (should-error (todo-insert-item--basic | ||
| 615 | nil nil nil nil where))))) | ||
| 616 | (should (string= copy-err (cadr (funcall insert-item-test 'copy)))) | ||
| 617 | (should (string= here-err (cadr (funcall insert-item-test 'here))))))) | ||
| 618 | |||
| 619 | (ert-deftest todo-test-done-items-separator01-eol () | ||
| 620 | "Test item copying and here insertion at EOL of separator. | ||
| 621 | Both should be user errors." | ||
| 622 | (with-todo-test | ||
| 623 | (todo-test--done-items-separator 'eol) | ||
| 624 | (let* ((copy-err "Item copying is not valid here") | ||
| 625 | (here-err "Item insertion is not valid here") | ||
| 626 | (insert-item-test (lambda (where) | ||
| 627 | (should-error (todo-insert-item--basic | ||
| 628 | nil nil nil nil where))))) | ||
| 629 | (should (string= copy-err (cadr (funcall insert-item-test 'copy)))) | ||
| 630 | (should (string= here-err (cadr (funcall insert-item-test 'here))))))) | ||
| 631 | |||
| 632 | (ert-deftest todo-test-done-items-separator02-bol () | ||
| 633 | "Test item editing commands at BOL of done items separator. | ||
| 634 | They should all be noops." | ||
| 635 | (with-todo-test | ||
| 636 | (todo-test--done-items-separator) | ||
| 637 | (should-not (todo-item-done)) | ||
| 638 | (should-not (todo-raise-item-priority)) | ||
| 639 | (should-not (todo-lower-item-priority)) | ||
| 640 | (should-not (called-interactively-p #'todo-set-item-priority)) | ||
| 641 | (should-not (called-interactively-p #'todo-move-item)) | ||
| 642 | (should-not (called-interactively-p #'todo-delete-item)) | ||
| 643 | (should-not (called-interactively-p #'todo-edit-item)))) | ||
| 644 | |||
| 645 | (ert-deftest todo-test-done-items-separator02-eol () | ||
| 646 | "Test item editing command at EOL of done items separator. | ||
| 647 | They should all be noops." | ||
| 648 | (with-todo-test | ||
| 649 | (todo-test--done-items-separator 'eol) | ||
| 650 | (should-not (todo-item-done)) | ||
| 651 | (should-not (todo-raise-item-priority)) | ||
| 652 | (should-not (todo-lower-item-priority)) | ||
| 653 | (should-not (called-interactively-p #'todo-set-item-priority)) | ||
| 654 | (should-not (called-interactively-p #'todo-move-item)) | ||
| 655 | (should-not (called-interactively-p #'todo-delete-item)) | ||
| 656 | (should-not (called-interactively-p #'todo-edit-item)))) | ||
| 657 | |||
| 658 | (ert-deftest todo-test-done-items-separator03-bol () | ||
| 659 | "Test item marking at BOL of done items separator. | ||
| 660 | This should be a noop, adding no marks to the category." | ||
| 661 | (with-todo-test | ||
| 662 | (todo-test--done-items-separator) | ||
| 663 | (call-interactively #'todo-toggle-mark-item) | ||
| 664 | (should-not (assoc (todo-current-category) todo-categories-with-marks)))) | ||
| 665 | |||
| 666 | (ert-deftest todo-test-done-items-separator03-eol () | ||
| 667 | "Test item marking at EOL of done items separator. | ||
| 668 | This should be a noop, adding no marks to the category." | ||
| 669 | (with-todo-test | ||
| 670 | (todo-test--done-items-separator 'eol) | ||
| 671 | (call-interactively #'todo-toggle-mark-item) | ||
| 672 | (should-not (assoc (todo-current-category) todo-categories-with-marks)))) | ||
| 673 | |||
| 674 | (ert-deftest todo-test-done-items-separator04-bol () | ||
| 675 | "Test moving to previous item from BOL of done items separator. | ||
| 676 | This should move point to the last not done todo item." | ||
| 677 | (with-todo-test | ||
| 678 | (todo-test--done-items-separator) | ||
| 679 | (let ((last-item (save-excursion | ||
| 680 | ;; Move to empty line after last todo item. | ||
| 681 | (forward-line -1) | ||
| 682 | (todo-previous-item) | ||
| 683 | (todo-item-string)))) | ||
| 684 | (should (string= last-item (save-excursion | ||
| 685 | (todo-previous-item) | ||
| 686 | (todo-item-string))))))) | ||
| 687 | |||
| 688 | (ert-deftest todo-test-done-items-separator04-eol () | ||
| 689 | "Test moving to previous item from EOL of done items separator. | ||
| 690 | This should move point to the last not done todo item." | ||
| 691 | (with-todo-test | ||
| 692 | (todo-test--done-items-separator 'eol) | ||
| 693 | (let ((last-item (save-excursion | ||
| 694 | ;; Move to empty line after last todo item. | ||
| 695 | (forward-line -1) | ||
| 696 | (todo-previous-item) | ||
| 697 | (todo-item-string)))) | ||
| 698 | (should (string= last-item (save-excursion | ||
| 699 | (todo-previous-item) | ||
| 700 | (todo-item-string))))))) | ||
| 701 | |||
| 702 | (ert-deftest todo-test-done-items-separator05-bol () | ||
| 703 | "Test moving to next item from BOL of done items separator. | ||
| 704 | This should move point to the first done todo item." | ||
| 705 | (with-todo-test | ||
| 706 | (todo-test--done-items-separator) | ||
| 707 | (let ((first-done (save-excursion | ||
| 708 | ;; Move to empty line after last todo item. | ||
| 709 | (forward-line -1) | ||
| 710 | (todo-next-item) | ||
| 711 | (todo-item-string)))) | ||
| 712 | (should (string= first-done (save-excursion | ||
| 713 | (todo-next-item) | ||
| 714 | (todo-item-string))))))) | ||
| 715 | |||
| 716 | (ert-deftest todo-test-done-items-separator05-eol () | ||
| 717 | "Test moving to next item from EOL of done items separator. | ||
| 718 | This should move point to the first done todo item." | ||
| 719 | (with-todo-test | ||
| 720 | (todo-test--done-items-separator 'eol) | ||
| 721 | (let ((first-done (save-excursion | ||
| 722 | ;; Move to empty line after last todo item. | ||
| 723 | (forward-line -1) | ||
| 724 | (todo-next-item) | ||
| 725 | (todo-item-string)))) | ||
| 726 | (should (string= first-done (save-excursion | ||
| 727 | (todo-next-item) | ||
| 728 | (todo-item-string))))))) | ||
| 729 | |||
| 730 | ;; Item highlighting uses hl-line-mode, which enables highlighting in | ||
| 731 | ;; post-command-hook. For some reason, in the test environment, the | ||
| 732 | ;; hook function is not automatically run, so after enabling item | ||
| 733 | ;; highlighting, use ert-simulate-command around the next command, | ||
| 734 | ;; which explicitly runs the hook function. | ||
| 735 | (ert-deftest todo-test-done-items-separator06-bol () | ||
| 736 | "Test enabling item highlighting at BOL of done items separator. | ||
| 737 | Subsequently moving to an item should show it highlighted." | ||
| 738 | (with-todo-test | ||
| 739 | (todo-test--done-items-separator) | ||
| 740 | (call-interactively #'todo-toggle-item-highlighting) | ||
| 741 | (ert-simulate-command '(todo-previous-item)) | ||
| 742 | (should (eq 'hl-line (get-char-property (point) 'face))))) | ||
| 743 | |||
| 744 | (ert-deftest todo-test-done-items-separator06-eol () | ||
| 745 | "Test enabling item highlighting at EOL of done items separator. | ||
| 746 | Subsequently moving to an item should show it highlighted." | ||
| 747 | (with-todo-test | ||
| 748 | (todo-test--done-items-separator 'eol) | ||
| 749 | (todo-toggle-item-highlighting) | ||
| 750 | (forward-line -1) | ||
| 751 | (ert-simulate-command '(todo-previous-item)) | ||
| 752 | (should (eq 'hl-line (get-char-property (point) 'face))))) | ||
| 753 | |||
| 754 | (ert-deftest todo-test-done-items-separator07 () | ||
| 755 | "Test item highlighting when crossing done items separator. | ||
| 756 | The highlighting should remain enabled." | ||
| 757 | (with-todo-test | ||
| 758 | (todo-test--done-items-separator) | ||
| 759 | (todo-previous-item) | ||
| 760 | (todo-toggle-item-highlighting) | ||
| 761 | (todo-next-item) ; Now on empty line above separator. | ||
| 762 | (forward-line) ; Now on separator. | ||
| 763 | (ert-simulate-command '(forward-line)) ; Now on first done item. | ||
| 764 | (should (eq 'hl-line (get-char-property (point) 'face))))) | ||
| 765 | |||
| 584 | 766 | ||
| 585 | (provide 'todo-mode-tests) | 767 | (provide 'todo-mode-tests) |
| 586 | ;;; todo-mode-tests.el ends here | 768 | ;;; todo-mode-tests.el ends here |