|
3 | 3 | ;; Author: Mats Lidell <[email protected]>
|
4 | 4 | ;;
|
5 | 5 | ;; Orig-Date: 30-Jan-21 at 12:00:00
|
6 |
| -;; Last-Mod: 15-Nov-23 at 01:57:15 by Bob Weiner |
| 6 | +;; Last-Mod: 30-Nov-23 at 19:53:31 by Mats Lidell |
7 | 7 | ;;
|
8 | 8 | ;; SPDX-License-Identifier: GPL-3.0-or-later
|
9 | 9 | ;;
|
@@ -831,6 +831,107 @@ With point on label suggest that ibut for rename."
|
831 | 831 | (hy-delete-file-and-buffer filea)
|
832 | 832 | (hy-delete-file-and-buffer fileb))))
|
833 | 833 |
|
| 834 | +(ert-deftest hui--ebut-link-directly-to-file () |
| 835 | + "Create a direct link to a file." |
| 836 | + (let ((filea (make-temp-file "hypb" nil ".txt")) |
| 837 | + (fileb (make-temp-file "hypb" nil ".txt" "1234567890"))) |
| 838 | + (unwind-protect |
| 839 | + (progn |
| 840 | + (delete-other-windows) |
| 841 | + (find-file fileb) |
| 842 | + (goto-char (point-max)) |
| 843 | + (split-window) |
| 844 | + (find-file filea) |
| 845 | + (with-simulated-input "button RET" |
| 846 | + (hui:ebut-link-directly (get-buffer-window) |
| 847 | + (get-buffer-window (get-file-buffer fileb))) |
| 848 | + (should (string= (buffer-string) "<(button)>")) |
| 849 | + (hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-file |
| 850 | + :args (list fileb 11) |
| 851 | + :loc filea |
| 852 | + :lbl-key "button"))) |
| 853 | + (hy-delete-file-and-buffer filea) |
| 854 | + (hy-delete-file-and-buffer fileb)))) |
| 855 | + |
| 856 | +(ert-deftest hui--ebut-link-directly-to-dired () |
| 857 | + "Create a direct link to a directory in Dired." |
| 858 | + (let* ((file (make-temp-file "hypb" nil ".txt")) |
| 859 | + (dir hyperb:dir) |
| 860 | + dir-buf) |
| 861 | + (unwind-protect |
| 862 | + (progn |
| 863 | + (delete-other-windows) |
| 864 | + (setq dir-buf (dired dir)) |
| 865 | + (goto-char (point-min)) |
| 866 | + ;; Move point just prior to last colon on the first dired directory line; |
| 867 | + ;; With some dired formats, there may be text after the last colon. |
| 868 | + (goto-char (line-end-position)) |
| 869 | + (skip-chars-backward "^:") |
| 870 | + (when (/= (point) (point-min)) |
| 871 | + (goto-char (1- (point)))) |
| 872 | + (split-window) |
| 873 | + (find-file file) |
| 874 | + (with-simulated-input "button RET" |
| 875 | + (hui:ebut-link-directly (get-buffer-window) (get-buffer-window dir-buf)) |
| 876 | + ;; Implicit link should be the `dir' dired directory, |
| 877 | + ;; possibly minus the final directory '/'. |
| 878 | + (should (string= (buffer-string) "<(button)>")) |
| 879 | + (hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-directory |
| 880 | + :args (list (directory-file-name hyperb:dir)) ; Remove trailing slash!? |
| 881 | + :loc file |
| 882 | + :lbl-key "button"))) |
| 883 | + (hy-delete-file-and-buffer file)))) |
| 884 | + |
| 885 | +(ert-deftest hui--buf-writable-err () |
| 886 | + "Verify error is signaled if buffer is not writable." |
| 887 | + (with-temp-buffer |
| 888 | + (read-only-mode) |
| 889 | + (condition-case err |
| 890 | + (hui:buf-writable-err (current-buffer) "func") |
| 891 | + (error |
| 892 | + (progn |
| 893 | + (should (equal (car err) 'error)) |
| 894 | + (should (string-match |
| 895 | + "(func) Read-only error in Hyperbole button buffer" |
| 896 | + (cadr err)))))))) |
| 897 | + |
| 898 | +(ert-deftest hui--gbut-link-directly-ibut () |
| 899 | + "Verify an ibut is created last in the global but file." |
| 900 | + (defvar global-but-file) |
| 901 | + (let ((global-but-file (make-temp-file "gbut" nil ".txt" "First\n")) |
| 902 | + (file (make-temp-file "hypb" nil ".txt"))) |
| 903 | + (unwind-protect |
| 904 | + (mocklet ((gbut:file => global-but-file)) |
| 905 | + (delete-other-windows) |
| 906 | + (find-file file) |
| 907 | + (with-simulated-input "button RET" |
| 908 | + (hui:gbut-link-directly t) |
| 909 | + (with-current-buffer (find-buffer-visiting global-but-file) |
| 910 | + (should (string= (buffer-string) |
| 911 | + (concat "First\n<[button]> - \"" file ":1\"")))))) |
| 912 | + (hy-delete-file-and-buffer global-but-file) |
| 913 | + (hy-delete-file-and-buffer file)))) |
| 914 | + |
| 915 | +(ert-deftest hui--gbut-link-directly-ebut () |
| 916 | + "Verify an ebut is created last in the global but file." |
| 917 | + (defvar global-but-file) |
| 918 | + (let ((global-but-file (make-temp-file "gbut" nil ".txt" "First\n")) |
| 919 | + (file (make-temp-file "hypb" nil ".txt"))) |
| 920 | + (unwind-protect |
| 921 | + (mocklet ((gbut:file => global-but-file)) |
| 922 | + (delete-other-windows) |
| 923 | + (find-file file) |
| 924 | + (with-simulated-input "button RET" |
| 925 | + (hui:gbut-link-directly) |
| 926 | + (with-current-buffer (find-buffer-visiting global-but-file) |
| 927 | + (should (string= (buffer-string) "First\n<(button)>\n")) |
| 928 | + (hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-file |
| 929 | + :args (list file 1) |
| 930 | + :loc global-but-file |
| 931 | + :lbl-key "button")))) |
| 932 | + (hy-delete-file-and-buffer global-but-file) |
| 933 | + (hy-delete-file-and-buffer file)))) |
| 934 | + |
834 | 935 | ;; This file can't be byte-compiled without `with-simulated-input' which
|
835 | 936 | ;; is not part of the actual dependencies, so:
|
836 | 937 | ;; Local Variables:
|
|
0 commit comments