forked from OSchip/llvm-project
Make clang-include-fixer--insert-line work when the difference is on an empty line
`clang-include-fixer--insert-line` has an off-by-one error because it uses `(goto-char (point-min)) (forward-char chars)`, which is (goto-char (1+ chars))`. Because of this, when the first difference was on an empty line (i.e. an include was appended to the block of includes), the pointer in the `to` buffer would be on the next line. Also wrapped calls inside another process sentinel inside `with-local-quit`. Patch by Torsten Marek. Differential Revision: https://reviews.llvm.org/D30292 llvm-svn: 295988
This commit is contained in:
parent
2c7169d00c
commit
c38cd69256
|
@ -23,6 +23,18 @@
|
|||
(should (equal (buffer-string) "aa\nab\nac\nad\n")))))
|
||||
(should (equal (buffer-string) "aa\nab\nac\nad\n"))))
|
||||
|
||||
(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()
|
||||
"Unit test for `clang-include-fixer--insert-line'."
|
||||
(with-temp-buffer
|
||||
(insert "aa\nab\n\nac\nad\n")
|
||||
(let ((from (current-buffer)))
|
||||
(with-temp-buffer
|
||||
(insert "aa\n\nac\nad\n")
|
||||
(let ((to (current-buffer)))
|
||||
(should (clang-include-fixer--insert-line from to))
|
||||
(should (equal (buffer-string) "aa\nab\n\nac\nad\n")))))
|
||||
(should (equal (buffer-string) "aa\nab\n\nac\nad\n"))))
|
||||
|
||||
(ert-deftest clang-include-fixer--symbol-at-point ()
|
||||
"Unit test for `clang-include-fixer--symbol-at-point'."
|
||||
(with-temp-buffer
|
||||
|
|
|
@ -213,16 +213,14 @@ return nil. Buffer restrictions are ignored."
|
|||
(if (zerop chars)
|
||||
;; Buffer contents are equal, nothing to do.
|
||||
t
|
||||
(goto-char (point-min))
|
||||
(forward-char chars)
|
||||
(goto-char chars)
|
||||
;; We might have ended up in the middle of a line if the
|
||||
;; current line partially matches. In this case we would
|
||||
;; have to insert more than a line. Move to the beginning of
|
||||
;; the line to avoid this situation.
|
||||
(beginning-of-line)
|
||||
(with-current-buffer from
|
||||
(goto-char (point-min))
|
||||
(forward-char chars)
|
||||
(goto-char chars)
|
||||
(beginning-of-line)
|
||||
(let ((from-begin (point))
|
||||
(from-end (progn (forward-line) (point)))
|
||||
|
@ -268,9 +266,10 @@ clang-include-fixer to insert the selected header."
|
|||
(clang-include-fixer--replace-buffer stdout)
|
||||
(let-alist context
|
||||
(let-alist (car .HeaderInfos)
|
||||
(run-hook-with-args 'clang-include-fixer-add-include-hook
|
||||
(substring .Header 1 -1)
|
||||
(string= (substring .Header 0 1) "<"))))))
|
||||
(with-local-quit
|
||||
(run-hook-with-args 'clang-include-fixer-add-include-hook
|
||||
(substring .Header 1 -1)
|
||||
(string= (substring .Header 0 1) "<")))))))
|
||||
(format "-insert-header=%s"
|
||||
(clang-include-fixer--encode-json context))))))))
|
||||
nil)
|
||||
|
|
Loading…
Reference in New Issue