-
Notifications
You must be signed in to change notification settings - Fork 17
/
vdiff-test.el
210 lines (194 loc) · 6.12 KB
/
vdiff-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
;;; vdiff-test.el --- tests for vdiff.el -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Free Software Foundation, Inc.
;; Author: Justin Burkett <[email protected]>
;; Maintainer: Justin Burkett <[email protected]>
;; 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)
(defmacro vdiff-test-with-buffers
(a-string b-string operation final-a-string final-b-string &optional after-quit)
`(let ((buffer-a (get-buffer-create "vdiff-tests-buffer-a"))
(buffer-b (get-buffer-create "vdiff-tests-buffer-b"))
(vdiff--testing-mode t))
(unwind-protect
(progn
(with-current-buffer buffer-a
(erase-buffer)
;; this seems necessary for batch mode
(transient-mark-mode 1)
(insert ,(replace-regexp-in-string "|" "\n" a-string)))
(with-current-buffer buffer-b
(erase-buffer)
;; this seems necessary for batch mode
(transient-mark-mode 1)
(insert ,(replace-regexp-in-string "|" "\n" b-string)))
(vdiff-buffers buffer-a buffer-b)
,operation
(with-current-buffer buffer-a
(should (string= (buffer-string)
,(replace-regexp-in-string "|" "\n" final-a-string))))
(with-current-buffer buffer-b
(should (string= (buffer-string)
,(replace-regexp-in-string "|" "\n" final-b-string)))))
(with-current-buffer buffer-a
(vdiff-quit))
,after-quit
(kill-buffer buffer-a)
(kill-buffer buffer-b))))
(ert-deftest vdiff-test-parsing ()
"Test parsing of unified diff format."
(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)))))))
(ert-deftest vdiff-test-setup ()
"Test setting up `vdiff-mode'."
;; Setup does not change buffers
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
nil
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"))
(ert-deftest vdiff-test-movement ()
"Test movement in buffers."
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(call-interactively 'vdiff-next-hunk)
(call-interactively 'vdiff-next-hunk)
(should (looking-at-p "7")))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"))
(ert-deftest vdiff-test-transmiting ()
"Test transmitting changes."
;; Test sending first change
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(call-interactively 'vdiff-next-hunk)
(call-interactively 'vdiff-send-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|3|4|5|6|8|8|9|10|")
;; Test sending everything
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(vdiff-send-changes (point-min) (point-max)))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|3|4|5|6|7|8|9|10|"))
(ert-deftest vdiff-test-receiving ()
"Test receiving changes."
;; Test receiving first change
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
(with-current-buffer buffer-b
(goto-char (point-min))
(call-interactively 'vdiff-next-hunk)
(call-interactively 'vdiff-receive-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|3|4|5|6|8|8|9|10|")
;; Test receiving everything
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|2|4|4|5|6|8|8|9|10|"
(with-current-buffer buffer-b
(vdiff-receive-changes (point-min) (point-max)))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|3|4|5|6|7|8|9|10|"))
(ert-deftest vdiff-test-selective-transmiting ()
"Test transmitting changes when region is active."
;; Test sending first line of first change
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|x|x|x|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(forward-line)
(set-mark (point))
(forward-line)
(call-interactively 'vdiff-send-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|x|x|5|6|8|8|9|10|")
;; Test sending second line of first change
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|x|x|x|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(forward-line 2)
(set-mark (point))
(forward-line)
(call-interactively 'vdiff-send-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|x|3|x|5|6|8|8|9|10|")
;; Test sending first line of first change when region begins before
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|x|x|x|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(set-mark (point))
(forward-line 2)
(call-interactively 'vdiff-send-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|2|x|x|5|6|8|8|9|10|")
;; Test sending last two lines of first change when region ends after
(vdiff-test-with-buffers
"1|2|3|4|5|6|7|8|9|10|"
"1|x|x|x|5|6|8|8|9|10|"
(with-current-buffer buffer-a
(goto-char (point-min))
(forward-line 2)
(set-mark (point))
(forward-line 3)
(call-interactively 'vdiff-send-changes))
"1|2|3|4|5|6|7|8|9|10|"
"1|x|3|4|5|6|8|8|9|10|"))
(provide 'vdiff-test)
;;; vdiff-test.el ends here