Skip to content

Commit 3692855

Browse files
authored
Merge pull request #410 from rswgnu/add-tests-for-ebut-link-directly
Add tests for ebut-link-directly and gbut-link-directly
2 parents ae55b5c + 12c2f5d commit 3692855

File tree

2 files changed

+110
-2
lines changed

2 files changed

+110
-2
lines changed

ChangeLog

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2023-11-30 Mats Lidell <[email protected]>
2+
3+
* test/hui-tests.el (hui--ebut-link-directly-to-file)
4+
(hui--ebut-link-directly-to-dired, hui--buf-writable-err)
5+
(hui--gbut-link-directly-ibut, hui--gbut-link-directly-ebut): Add
6+
tests for ebut-link-directly.
7+
18
2023-11-29 Mats Lidell <[email protected]>
29

310
* test/hyrolo-tests.el (hyrolo-fgrep-and-goto-next-visible-org-heading)
@@ -7,7 +14,7 @@
714
(hyrolo-fgrep-and-goto-next-visible-kotl-heading-level-2)
815
(hyrolo-fgrep-and-goto-next-visible-kotl-heading-cell-2): Add test for
916
moving to next header and that action-key then brings you to the
10-
matching record.
17+
matchi
1118

1219
2023-11-25 Mats Lidell <[email protected]>
1320

test/hui-tests.el

+102-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Mats Lidell <[email protected]>
44
;;
55
;; 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
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -831,6 +831,107 @@ With point on label suggest that ibut for rename."
831831
(hy-delete-file-and-buffer filea)
832832
(hy-delete-file-and-buffer fileb))))
833833

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+
834935
;; This file can't be byte-compiled without `with-simulated-input' which
835936
;; is not part of the actual dependencies, so:
836937
;; Local Variables:

0 commit comments

Comments
 (0)