Skip to content

Commit

Permalink
Fix failed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhge committed Oct 15, 2012
1 parent 9cfd76f commit 962fcdb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
29 changes: 24 additions & 5 deletions iedit-tests.el
Expand Up @@ -2,7 +2,7 @@

;; Copyright (C) 2010, 2011, 2012 Victor Ren

;; Time-stamp: <2012-08-09 17:17:03 Victor Ren>
;; Time-stamp: <2012-10-15 16:12:02 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.97
;; X-URL: http://www.emacswiki.org/emacs/Iedit
Expand Down Expand Up @@ -30,6 +30,7 @@
;;; Code:
(require 'ert)
(require 'iedit)
(require 'iedit-rect)

(ert-deftest iedit-compile-test ()
(let ((byte-compile-error-on-warn t ))
Expand Down Expand Up @@ -128,6 +129,25 @@ foo"
123foo456123foo456
123foo456")))))

(ert-deftest iedit-overlay-at-end-of-buffer ()
(with-iedit-test-fixture
"foo
foo"
(lambda ()
(iedit-mode)
(highlight-changes-mode 1)
(goto-char (point-min))
(goto-char (point-at-eol))
(iedit-mode)
(delete-region (point) (1- (point)))
(should (string= (buffer-string)
"fo
fo"))
(insert "b")
(should (string= (buffer-string)
"fob
fob")))))

(ert-deftest iedit-mode-start-from-isearch-test ()
(with-iedit-test-fixture
"foo
Expand All @@ -143,7 +163,7 @@ foo"
(isearch-process-search-char ?f)
(isearch-process-search-char ?o)
(isearch-process-search-char ?o)
(iedit-mode)
(iedit-mode-from-isearch)
(should (string= iedit-initial-string-local "foo"))
(should (= 4 (length iedit-occurrences-overlays)))
(iedit-mode)
Expand Down Expand Up @@ -342,8 +362,7 @@ foo"
(iedit-mode) ; turn off iedit
(goto-char 2)
(set-mark-command nil)
(forward-char 1)
(forward-line 1)
(goto-char 7)
(iedit-rectangle-mode)
(iedit-blank-occurrences)
(should (string= (buffer-string) "f o
Expand Down Expand Up @@ -463,7 +482,7 @@ arfoo
(should (= 1 (length iedit-occurrences-overlays)))
(iedit-mode)
(goto-char 13)
(iedit-mode-on-function)
(iedit-mode-toggle-on-function)
(should (= 4 (length iedit-occurrences-overlays)))
(iedit-mode)
(iedit-mode)
Expand Down
27 changes: 15 additions & 12 deletions iedit.el
Expand Up @@ -2,7 +2,7 @@

;; Copyright (C) 2010, 2011, 2012 Victor Ren

;; Time-stamp: <2012-09-12 15:22:33 Victor Ren>
;; Time-stamp: <2012-10-15 15:09:14 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.97
Expand Down Expand Up @@ -340,30 +340,32 @@ Keymap used within overlays:
(setq iedit-only-complete-symbol-local complete-symbol)
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(setq iedit-initial-string-local occurrence)
(iedit-start (iedit-regexp-quote occurrence) beg end))))

(defun iedit-mode-from-isearch (regexp)
(defun iedit-mode-from-isearch ()
"Start Iedit mode using last search string as the regexp."
(interactive
(let ((regexp (cond
((functionp isearch-word)
(funcall isearch-word isearch-string))
(interactive)
(let ((regexp (cond
(isearch-word (word-search-regexp isearch-string))
(isearch-regexp isearch-string)
(t (regexp-quote isearch-string)))))
(list regexp)))
(isearch-exit)
(iedit-start regexp (point-min) (point-max))
(if (or isearch-regexp isearch-word)
nil
(setq iedit-initial-string-local isearch-string))
(isearch-exit)
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(iedit-start regexp (point-min) (point-max))
;; TODO: reconsider how to avoid the loop in iedit-same-length
(if (iedit-same-length)
(if (iedit-same-length)
nil
(iedit-done)
(message "Matches are not the same length.")))
(message "Matches are not the same length."))))

(defun iedit-start (occurrence-regexp beg end)
"Start Iedit mode for the `occurrence-regexp' in the current buffer."
(setq iedit-unmatched-lines-invisible iedit-unmatched-lines-invisible-default)
(setq iedit-initial-string-local occurrence-regexp)
(setq iedit-initial-region (list beg end))
(iedit-start2 occurrence-regexp beg end)
(run-hooks 'iedit-mode-hook)
Expand Down Expand Up @@ -401,6 +403,7 @@ the initial string globally."

(iedit-cleanup)

(setq iedit-initial-string-local nil)
(setq iedit-mode nil)
(force-mode-line-update)
(remove-hook 'kbd-macro-termination-hook 'iedit-done t)
Expand Down

0 comments on commit 962fcdb

Please sign in to comment.