aboutsummaryrefslogtreecommitdiff
path: root/tests/test-custom-buffer-file-move-buffer-and-file.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-03 19:24:40 -0500
committerCraig Jennings <c@cjennings.net>2026-05-03 19:24:40 -0500
commit389e85c020e7e59977e3c832a281f8b7844fecd4 (patch)
tree6ae03c43882120a7dcd534d0a09a91fe609fdbd5 /tests/test-custom-buffer-file-move-buffer-and-file.el
parentc2f355bf601fd9b7db0107c163c64432a7ae9a80 (diff)
downloaddotemacs-389e85c020e7e59977e3c832a281f8b7844fecd4.tar.gz
dotemacs-389e85c020e7e59977e3c832a281f8b7844fecd4.zip
fix: use file basename when moving buffer + file
`cj/--move-buffer-and-file` was building the destination as `(concat dir "/" (buffer-name))`. If the buffer had been renamed via `M-x rename-buffer`, or uniquified by Emacs with a `<2>` suffix when a second buffer visited the same filename, the move wrote a file with the wrong name on disk. I derived the destination basename from `buffer-file-name` instead, in both the internal helper and the interactive wrapper. The wrapper's overwrite-prompt now also formats the real target filename rather than the buffer name. I added two regression tests: one for a renamed buffer visiting `original.txt`, and one for a `<2>` uniquified buffer with a trailing-slash target directory.
Diffstat (limited to 'tests/test-custom-buffer-file-move-buffer-and-file.el')
-rw-r--r--tests/test-custom-buffer-file-move-buffer-and-file.el40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test-custom-buffer-file-move-buffer-and-file.el b/tests/test-custom-buffer-file-move-buffer-and-file.el
index e8f4563d..8331db5c 100644
--- a/tests/test-custom-buffer-file-move-buffer-and-file.el
+++ b/tests/test-custom-buffer-file-move-buffer-and-file.el
@@ -225,6 +225,46 @@
(kill-buffer (current-buffer)))
(test-move-buffer-and-file-teardown)))
+(ert-deftest test-move-buffer-and-file-renamed-buffer-uses-file-basename ()
+ "Should use visited file basename when buffer name differs."
+ (test-move-buffer-and-file-setup)
+ (unwind-protect
+ (let* ((source-dir (cj/create-test-subdirectory "source"))
+ (target-dir (cj/create-test-subdirectory "target"))
+ (source-file (expand-file-name "original.txt" source-dir))
+ (target-file (expand-file-name "original.txt" target-dir))
+ (wrong-target (expand-file-name "renamed-buffer" target-dir)))
+ (with-temp-file source-file
+ (insert "content"))
+ (find-file source-file)
+ (rename-buffer "renamed-buffer")
+ (cj/--move-buffer-and-file target-dir)
+ (should (file-exists-p target-file))
+ (should-not (file-exists-p wrong-target))
+ (should (string= (buffer-file-name) target-file))
+ (kill-buffer (current-buffer)))
+ (test-move-buffer-and-file-teardown)))
+
+(ert-deftest test-move-buffer-and-file-uniquified-buffer-uses-file-basename ()
+ "Should not use uniquified buffer names such as <2> as filenames."
+ (test-move-buffer-and-file-setup)
+ (unwind-protect
+ (let* ((source-dir (cj/create-test-subdirectory "source"))
+ (target-dir (cj/create-test-subdirectory "target"))
+ (source-file (expand-file-name "duplicate.txt" source-dir))
+ (target-file (expand-file-name "duplicate.txt" target-dir))
+ (wrong-target (expand-file-name "duplicate.txt<2>" target-dir)))
+ (with-temp-file source-file
+ (insert "content"))
+ (find-file source-file)
+ (rename-buffer "duplicate.txt<2>")
+ (cj/--move-buffer-and-file (concat target-dir "/"))
+ (should (file-exists-p target-file))
+ (should-not (file-exists-p wrong-target))
+ (should (string= (buffer-file-name) target-file))
+ (kill-buffer (current-buffer)))
+ (test-move-buffer-and-file-teardown)))
+
(ert-deftest test-move-buffer-and-file-deeply-nested-target ()
"Should move to deeply nested target directory."
(test-move-buffer-and-file-setup)