-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for ebut-link-directly and gbut-link-directly #410
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
2023-11-30 Mats Lidell <[email protected]> | ||
|
||
* test/hui-tests.el (hui--ebut-link-directly-to-file) | ||
(hui--ebut-link-directly-to-dired, hui--buf-writable-err) | ||
(hui--gbut-link-directly-ibut, hui--gbut-link-directly-ebut): Add | ||
tests for ebut-link-directly. | ||
|
||
2023-11-25 Mats Lidell <[email protected]> | ||
|
||
* hyrolo.el: Move private variables before their first use to remove | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
;; Author: Mats Lidell <[email protected]> | ||
;; | ||
;; Orig-Date: 30-Jan-21 at 12:00:00 | ||
;; Last-Mod: 15-Nov-23 at 01:57:15 by Bob Weiner | ||
;; Last-Mod: 30-Nov-23 at 19:53:31 by Mats Lidell | ||
;; | ||
;; SPDX-License-Identifier: GPL-3.0-or-later | ||
;; | ||
|
@@ -831,6 +831,107 @@ With point on label suggest that ibut for rename." | |
(hy-delete-file-and-buffer filea) | ||
(hy-delete-file-and-buffer fileb)))) | ||
|
||
(ert-deftest hui--ebut-link-directly-to-file () | ||
"Create a direct link to a file." | ||
(let ((filea (make-temp-file "hypb" nil ".txt")) | ||
(fileb (make-temp-file "hypb" nil ".txt" "1234567890"))) | ||
(unwind-protect | ||
(progn | ||
(delete-other-windows) | ||
(find-file fileb) | ||
(goto-char (point-max)) | ||
(split-window) | ||
(find-file filea) | ||
(with-simulated-input "button RET" | ||
(hui:ebut-link-directly (get-buffer-window) | ||
(get-buffer-window (get-file-buffer fileb))) | ||
(should (string= (buffer-string) "<(button)>")) | ||
(hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-file | ||
:args (list fileb 11) | ||
:loc filea | ||
:lbl-key "button"))) | ||
(hy-delete-file-and-buffer filea) | ||
(hy-delete-file-and-buffer fileb)))) | ||
|
||
(ert-deftest hui--ebut-link-directly-to-dired () | ||
"Create a direct link to a directory in Dired." | ||
(let* ((file (make-temp-file "hypb" nil ".txt")) | ||
(dir hyperb:dir) | ||
dir-buf) | ||
(unwind-protect | ||
(progn | ||
(delete-other-windows) | ||
(setq dir-buf (dired dir)) | ||
(goto-char (point-min)) | ||
;; Move point just prior to last colon on the first dired directory line; | ||
;; With some dired formats, there may be text after the last colon. | ||
(goto-char (line-end-position)) | ||
(skip-chars-backward "^:") | ||
(when (/= (point) (point-min)) | ||
(goto-char (1- (point)))) | ||
(split-window) | ||
(find-file file) | ||
(with-simulated-input "button RET" | ||
(hui:ebut-link-directly (get-buffer-window) (get-buffer-window dir-buf)) | ||
;; Implicit link should be the `dir' dired directory, | ||
;; possibly minus the final directory '/'. | ||
(should (string= (buffer-string) "<(button)>")) | ||
(hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-directory | ||
:args (list (directory-file-name hyperb:dir)) ; Remove trailing slash!? | ||
:loc file | ||
:lbl-key "button"))) | ||
(hy-delete-file-and-buffer file)))) | ||
|
||
(ert-deftest hui--buf-writable-err () | ||
"Verify error is signaled if buffer is not writable." | ||
(with-temp-buffer | ||
(read-only-mode) | ||
(condition-case err | ||
(hui:buf-writable-err (current-buffer) "func") | ||
(error | ||
(progn | ||
(should (equal (car err) 'error)) | ||
(should (string-match | ||
"(func) Read-only error in Hyperbole button buffer" | ||
(cadr err)))))))) | ||
|
||
(ert-deftest hui--gbut-link-directly-ibut () | ||
"Verify an ibut is created last in the global but file." | ||
(defvar global-but-file) | ||
(let ((global-but-file (make-temp-file "gbut" nil ".txt" "First\n")) | ||
(file (make-temp-file "hypb" nil ".txt"))) | ||
(unwind-protect | ||
(mocklet ((gbut:file => global-but-file)) | ||
(delete-other-windows) | ||
(find-file file) | ||
(with-simulated-input "button RET" | ||
(hui:gbut-link-directly t) | ||
(with-current-buffer (find-buffer-visiting global-but-file) | ||
(should (string= (buffer-string) | ||
(concat "First\n<[button]> - \"" file ":1\"")))))) | ||
(hy-delete-file-and-buffer global-but-file) | ||
(hy-delete-file-and-buffer file)))) | ||
|
||
(ert-deftest hui--gbut-link-directly-ebut () | ||
"Verify an ebut is created last in the global but file." | ||
(defvar global-but-file) | ||
(let ((global-but-file (make-temp-file "gbut" nil ".txt" "First\n")) | ||
(file (make-temp-file "hypb" nil ".txt"))) | ||
(unwind-protect | ||
(mocklet ((gbut:file => global-but-file)) | ||
(delete-other-windows) | ||
(find-file file) | ||
(with-simulated-input "button RET" | ||
(hui:gbut-link-directly) | ||
(with-current-buffer (find-buffer-visiting global-but-file) | ||
(should (string= (buffer-string) "First\n<(button)>\n")) | ||
(hy-test-helpers-verify-hattr-at-p :actype 'actypes::link-to-file | ||
:args (list file 1) | ||
:loc global-but-file | ||
:lbl-key "button")))) | ||
(hy-delete-file-and-buffer global-but-file) | ||
(hy-delete-file-and-buffer file)))) | ||
|
||
;; This file can't be byte-compiled without `with-simulated-input' which | ||
;; is not part of the actual dependencies, so: | ||
;; Local Variables: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copied from the ibut test case. @rswgnu Why the possibly? Apparently a directory can be without a trailing slash in the ebut args, but why?
I transformed it in this test case to a file name so the test will pass but that feels a bit hacky. Should we not make sure all link-to-directory ebuts have a trailing slash?
Can this be related to that environment variables can be inserted in the ebut args and that it could make it hard to be consistent? Do we need to relax the requirement for a trailing slash here so that the helper function,
hy-test-helpers-verify-hattr-at-p
, should ignore the trailing slash difference?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. There are too many code paths where a dir without a final slash could come in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Will update the general helper check so that when verifying a link-to-directory both versions, with and without slash i checked.