aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-07-29 09:47:10 -0700
committerPaul Eggert2018-07-29 09:47:10 -0700
commitd7052cf393ffd1ab57fd7f7d92abdd00a5b5df8c (patch)
treeaa2a6123173a7b94c2f6790b610194c796881382
parent4e47050df4a61654646bc58cfed79a709c117d2f (diff)
parent39d3e8b6bc465df7a9400165a4d813af8af37237 (diff)
downloademacs-d7052cf393ffd1ab57fd7f7d92abdd00a5b5df8c.tar.gz
emacs-d7052cf393ffd1ab57fd7f7d92abdd00a5b5df8c.zip
Merge from origin/emacs-26
39d3e8b Fix last change in 'char_width' 67679f0 Add initial tests for wdired.el
-rw-r--r--src/character.c11
-rw-r--r--test/lisp/wdired-tests.el105
2 files changed, 112 insertions, 4 deletions
diff --git a/src/character.c b/src/character.c
index b17f44b1422..8920da2748f 100644
--- a/src/character.c
+++ b/src/character.c
@@ -289,15 +289,18 @@ char_width (int c, struct Lisp_Char_Table *dp)
289 if (VECTORP (disp)) 289 if (VECTORP (disp))
290 for (i = 0, width = 0; i < ASIZE (disp); i++) 290 for (i = 0, width = 0; i < ASIZE (disp); i++)
291 { 291 {
292 int c; 292 int c = -1;
293 ch = AREF (disp, i); 293 ch = AREF (disp, i);
294 if (GLYPH_CODE_P (ch)) 294 if (GLYPH_CODE_P (ch))
295 c = GLYPH_CODE_CHAR (ch); 295 c = GLYPH_CODE_CHAR (ch);
296 else if (CHARACTERP (ch)) 296 else if (CHARACTERP (ch))
297 c = XFASTINT (ch); 297 c = XFASTINT (ch);
298 int w = CHARACTER_WIDTH (c); 298 if (c >= 0)
299 if (INT_ADD_WRAPV (width, w, &width)) 299 {
300 string_overflow (); 300 int w = CHARACTER_WIDTH (c);
301 if (INT_ADD_WRAPV (width, w, &width))
302 string_overflow ();
303 }
301 } 304 }
302 } 305 }
303 return width; 306 return width;
diff --git a/test/lisp/wdired-tests.el b/test/lisp/wdired-tests.el
new file mode 100644
index 00000000000..7199470ea96
--- /dev/null
+++ b/test/lisp/wdired-tests.el
@@ -0,0 +1,105 @@
1;;; wdired-tests.el --- tests for wdired.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2018 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(require 'dired)
24
25(ert-deftest wdired-test-bug32173-01 ()
26 "Test using non-nil wdired-use-interactive-rename.
27Partially modifying a file name should succeed."
28 (let* ((test-dir (make-temp-file "test-dir-" t))
29 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
30 (replace "bar")
31 (new-file (replace-regexp-in-string "foo" replace test-file))
32 (wdired-use-interactive-rename t))
33 (write-region "" nil test-file nil 'silent)
34 (advice-add 'dired-query ; Don't ask confirmation to overwrite a file.
35 :override
36 (lambda (_sym _prompt &rest _args) (setq dired-query t))
37 '((name . "advice-dired-query")))
38 (let ((buf (find-file-noselect test-dir)))
39 (unwind-protect
40 (with-current-buffer buf
41 (should (equal (dired-file-name-at-point) test-file))
42 (dired-toggle-read-only)
43 (kill-region (point) (progn (search-forward ".")
44 (forward-char -1) (point)))
45 (insert replace)
46 (wdired-finish-edit)
47 (should (equal (dired-file-name-at-point) new-file)))
48 (if buf (kill-buffer buf))
49 (delete-directory test-dir t)))))
50
51(ert-deftest wdired-test-bug32173-02 ()
52 "Test using non-nil wdired-use-interactive-rename.
53Aborting an edit should leaving original file name unchanged."
54 (let* ((test-dir (make-temp-file "test-dir-" t))
55 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
56 (wdired-use-interactive-rename t))
57 (write-region "" nil test-file nil 'silent)
58 ;; Make dired-do-create-files-regexp a noop to mimic typing C-g
59 ;; at its prompt before wdired-finish-edit returns.
60 (advice-add 'dired-do-create-files-regexp
61 :override
62 (lambda (&rest _) (ignore))
63 '((name . "advice-dired-do-create-files-regexp")))
64 (let ((buf (find-file-noselect test-dir)))
65 (unwind-protect
66 (with-current-buffer buf
67 (should (equal (dired-file-name-at-point) test-file))
68 (dired-toggle-read-only)
69 (kill-region (point) (progn (search-forward ".")
70 (forward-char -1) (point)))
71 (insert "bar")
72 (wdired-finish-edit)
73 (should (equal (dired-get-filename) test-file)))
74 (if buf (kill-buffer buf))
75 (delete-directory test-dir t)))))
76
77(ert-deftest wdired-test-unfinished-edit-01 ()
78 "Test editing a file name without saving the change.
79Finding the new name should be possible while still in
80wdired-mode."
81 :expected-result (if (< emacs-major-version 27) :failed :passed)
82 (let* ((test-dir (make-temp-file "test-dir-" t))
83 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
84 (replace "bar")
85 (new-file (replace-regexp-in-string "foo" replace test-file)))
86 (write-region "" nil test-file nil 'silent)
87 (let ((buf (find-file-noselect test-dir)))
88 (unwind-protect
89 (with-current-buffer buf
90 (should (equal (dired-file-name-at-point) test-file))
91 (dired-toggle-read-only)
92 (kill-region (point) (progn (search-forward ".")
93 (forward-char -1) (point)))
94 (insert replace)
95 (should (equal (dired-get-filename) new-file))))
96 (when buf
97 (with-current-buffer buf
98 ;; Prevent kill-buffer-query-functions from chiming in.
99 (set-buffer-modified-p nil)
100 (kill-buffer buf)))
101 (delete-directory test-dir t))))
102
103
104(provide 'wdired-tests)
105;;; wdired-tests.el ends here