[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c1525a8 05/57: Fix problems with diff -u parser at beg and
From: |
Justin Burkett |
Subject: |
[elpa] master c1525a8 05/57: Fix problems with diff -u parser at beg and end of file |
Date: |
Tue, 3 Nov 2020 14:32:17 -0500 (EST) |
branch: master
commit c1525a86618fc89904d399e5cecb3c435fe1211b
Author: Justin Burkett <justin@burkett.cc>
Commit: Justin Burkett <justin@burkett.cc>
Fix problems with diff -u parser at beg and end of file
Add a test as well.
---
vdiff-tests.el | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
vdiff.el | 33 +++++++++++++++++---------------
2 files changed, 78 insertions(+), 15 deletions(-)
diff --git a/vdiff-tests.el b/vdiff-tests.el
new file mode 100644
index 0000000..ad71e73
--- /dev/null
+++ b/vdiff-tests.el
@@ -0,0 +1,60 @@
+;;; vdiff-tests.el --- tests for vdiff.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+
+;; Author: Justin Burkett <justin@burkett.cc>
+;; Maintainer: Justin Burkett <justin@burkett.cc>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'vdiff)
+
+(ert-deftest vdiff-test-parsing ()
+ ""
+ (with-temp-buffer
+ (insert "--- test1.txt 2018-04-13 11:11:41.000000000 -0400
++++ test2.txt 2018-04-13 11:11:46.000000000 -0400
+@@ -1,3 +1,6 @@
++
++
++
+ 1
+ 2
+ 3
+@@ -9,6 +12,8 @@
+ 9
+ 10
+ 11
++11
++11
+ 12
+ 13
+ 14
+@@ -16,7 +21,8 @@
+ 16
+ 17
+ 18
+-19
+-20
++18
++29
+ 21
+ 22
++23
+")
+ (should (equal (vdiff--parse-diff-u (current-buffer))
+ '(((1) (1 . 3)) ((12) (15 . 16)) ((19 . 20) (24 . 25))
((23) (28 . 28)))))))
diff --git a/vdiff.el b/vdiff.el
index 8c6e378..700f311 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -567,9 +567,11 @@ an addition when compared to other vdiff buffers."
(forward-line)
(let ((a (car lines))
(b (cdr lines)))
- (cond ((looking-at-p " ") (cons (1+ a) (1+ b)))
- ((looking-at-p "+") (cons a (1+ b)))
- ((looking-at-p "-") (cons (1+ a) b)))))
+ (prog1
+ (cond ((or (looking-at-p " ") (eobp)) (cons (1+ a) (1+ b)))
+ ((looking-at-p "+") (cons a (1+ b)))
+ ((looking-at-p "-") (cons (1+ a) b)))
+ (message "a:%s b:%s l:%s" a b (buffer-substring (point)
(line-end-position))))))
(defun vdiff--parse-diff-u (buf)
"Parse diff -u output in BUF and return list of hunks."
@@ -584,17 +586,17 @@ an addition when compared to other vdiff buffers."
(lines (cons start-line-a start-line-b)))
(while (and (not (looking-at-p "@"))
(not (eobp)))
- (setq lines (vdiff--inc-lines lines))
(cond ((looking-at-p "+")
;; addition
(let ((beg-a (car lines))
(beg-b (cdr lines)))
(while (looking-at-p "+")
(setq lines (vdiff--inc-lines lines)))
- (cl-assert (looking-at-p " "))
+ (cl-assert (or (looking-at-p " ") (eobp)))
(push
- (list (vdiff--encode-range t beg-a)
- (vdiff--encode-range nil beg-b (1- (cdr lines))))
+ ;; there's no context lines at the beginning of the file
+ (list (cons (if (= beg-a 1) 1 (1+ beg-a)) nil)
+ (cons beg-b (1- (cdr lines))))
res)))
((looking-at-p "-")
;; subtraction or change
@@ -602,21 +604,22 @@ an addition when compared to other vdiff buffers."
(beg-b (cdr lines)))
(while (looking-at-p "-")
(setq lines (vdiff--inc-lines lines)))
- (if (looking-at-p " ")
+ (if (or (looking-at-p " ") (eobp))
;; subtraction
(push
- (list (vdiff--encode-range nil beg-a (1- (car
lines)))
- (vdiff--encode-range t beg-b))
+ (list (cons beg-a (if (= (car lines) 1) 1 (1- (car
lines))))
+ (cons nil beg-b))
res)
- (cl-assert (looking-at-p "+"))
+ (cl-assert (or (looking-at-p "+") (eobp)))
(let ((beg-b (cdr lines)))
(while (looking-at-p "+")
(setq lines (vdiff--inc-lines lines)))
- (cl-assert (looking-at-p " "))
+ (cl-assert (or (looking-at-p " ") (eobp)))
(push
- (list (vdiff--encode-range nil beg-a (1- (car
lines)))
- (vdiff--encode-range nil beg-b (1- (cdr
lines))))
- res))))))))))
+ (list (cons beg-a (1- (car lines)))
+ (cons beg-b (1- (cdr lines))))
+ res))))))
+ (setq lines (vdiff--inc-lines lines))))))
(nreverse res)))
(defun vdiff--parse-diff3 (buf)
- [elpa] master updated (3bfaa7a -> 185e803), Justin Burkett, 2020/11/03
- [elpa] master 66ae1ac 03/57: README: Note new option, Justin Burkett, 2020/11/03
- [elpa] master 52b7e04 04/57: Switch to using unified diff output (diff -u), Justin Burkett, 2020/11/03
- [elpa] master fb21cc6 08/57: Fix parsing of subtractions in diff -u, Justin Burkett, 2020/11/03
- [elpa] master f0de403 21/57: Add emacs-26.1 for Travis, Justin Burkett, 2020/11/03
- [elpa] master af74300 01/57: Add vdiff-disable-folding user option, Justin Burkett, 2020/11/03
- [elpa] master 41c2d0a 02/57: Handle error when no overlay at point, Justin Burkett, 2020/11/03
- [elpa] master c1525a8 05/57: Fix problems with diff -u parser at beg and end of file,
Justin Burkett <=
- [elpa] master 0312ac8 06/57: Update copyright years, Justin Burkett, 2020/11/03
- [elpa] master bc5e1a7 07/57: Remove debugging message, Justin Burkett, 2020/11/03
- [elpa] master b15b020 10/57: Add diff --minimal as algorithm and fix case args for git, Justin Burkett, 2020/11/03
- [elpa] master 992d07b 14/57: Add travis support, Justin Burkett, 2020/11/03
- [elpa] master 0bfb259 11/57: Add vdiff-debug flag, Justin Burkett, 2020/11/03
- [elpa] master 106a69f 20/57: Fix previous tests for Travis, Justin Burkett, 2020/11/03
- [elpa] master c803bd6 17/57: Add warnings for obsolete variables, Justin Burkett, 2020/11/03
- [elpa] master 5f7d3fd 22/57: Add Travis badge, Justin Burkett, 2020/11/03
- [elpa] master 348d1a7 27/57: Add after-quit arg to vdiff-test-with-buffers, Justin Burkett, 2020/11/03
- [elpa] master fd6ec8e 25/57: Test that both buffers are correct by default, Justin Burkett, 2020/11/03