diff-lcs 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/{ChangeLog → History.rdoc} +23 -15
- data/License.rdoc +38 -0
- data/Manifest.txt +27 -0
- data/README.rdoc +72 -0
- data/Rakefile +16 -106
- data/bin/htmldiff +21 -101
- data/bin/ldiff +2 -41
- data/diff-lcs.gemspec +51 -0
- data/docs/COPYING.txt +340 -0
- data/docs/artistic.html +289 -0
- data/lib/diff-lcs.rb +5 -0
- data/lib/diff/lcs.rb +471 -471
- data/lib/diff/lcs/array.rb +1 -1
- data/lib/diff/lcs/block.rb +1 -1
- data/lib/diff/lcs/callbacks.rb +1 -1
- data/lib/diff/lcs/change.rb +1 -1
- data/lib/diff/lcs/htmldiff.rb +151 -0
- data/lib/diff/lcs/hunk.rb +1 -16
- data/lib/diff/lcs/ldiff.rb +37 -53
- data/lib/diff/lcs/string.rb +1 -1
- data/spec/diff_spec.rb +35 -0
- data/spec/lcs_spec.rb +36 -0
- data/spec/patch_spec.rb +390 -0
- data/spec/sdiff_spec.rb +204 -0
- data/spec/spec_helper.rb +284 -0
- data/spec/traverse_balanced_spec.rb +286 -0
- data/spec/traverse_sequences_spec.rb +83 -0
- metadata +136 -58
- data/Install +0 -6
- data/README +0 -76
- data/tests/00test.rb +0 -626
data/spec/patch_spec.rb
ADDED
@@ -0,0 +1,390 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Diff::LCS.patch" do
|
6
|
+
include Diff::LCS::SpecHelper::Matchers
|
7
|
+
|
8
|
+
shared_examples "patch sequences correctly" do
|
9
|
+
it "should correctly patch left-to-right (patch autodiscovery)" do
|
10
|
+
Diff::LCS.patch(s1, patch_set).should == s2
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
14
|
+
Diff::LCS.patch(s1, patch_set, :patch).should == s2
|
15
|
+
Diff::LCS.patch!(s1, patch_set).should == s2
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should correctly patch right-to-left (unpatch autodiscovery)" do
|
19
|
+
Diff::LCS.patch(s2, patch_set).should == s1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
23
|
+
Diff::LCS.patch(s2, patch_set, :unpatch).should == s1
|
24
|
+
Diff::LCS.unpatch!(s2, patch_set).should == s1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "using a Diff::LCS.diff patchset" do
|
29
|
+
describe "with default diff callbacks (DiffCallbacks)" do
|
30
|
+
describe "forward (s1 -> s2)" do
|
31
|
+
it_has_behavior "patch sequences correctly" do
|
32
|
+
let(:s1) { seq1 }
|
33
|
+
let(:s2) { seq2 }
|
34
|
+
let(:patch_set) { Diff::LCS.diff(seq1, seq2) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "reverse (s2 -> s1)" do
|
39
|
+
it_has_behavior "patch sequences correctly" do
|
40
|
+
let(:s1) { seq2 }
|
41
|
+
let(:s2) { seq1 }
|
42
|
+
let(:patch_set) { Diff::LCS.diff(seq2, seq1) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with context diff callbacks (ContextDiffCallbacks)" do
|
48
|
+
describe "forward (s1 -> s2)" do
|
49
|
+
it_has_behavior "patch sequences correctly" do
|
50
|
+
let(:s1) { seq1 }
|
51
|
+
let(:s2) { seq2 }
|
52
|
+
let(:patch_set) {
|
53
|
+
Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "reverse (s2 -> s1)" do
|
59
|
+
it_has_behavior "patch sequences correctly" do
|
60
|
+
let(:s1) { seq2 }
|
61
|
+
let(:s2) { seq1 }
|
62
|
+
let(:patch_set) {
|
63
|
+
Diff::LCS.diff(seq2, seq1, Diff::LCS::ContextDiffCallbacks)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "with sdiff callbacks (SDiffCallbacks)" do
|
70
|
+
describe "forward (s1 -> s2)" do
|
71
|
+
it_has_behavior "patch sequences correctly" do
|
72
|
+
let(:s1) { seq1 }
|
73
|
+
let(:s2) { seq2 }
|
74
|
+
let(:patch_set) {
|
75
|
+
Diff::LCS.diff(seq1, seq2, Diff::LCS::SDiffCallbacks)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "reverse (s2 -> s1)" do
|
81
|
+
it_has_behavior "patch sequences correctly" do
|
82
|
+
let(:s1) { seq2 }
|
83
|
+
let(:s2) { seq1 }
|
84
|
+
let(:patch_set) {
|
85
|
+
Diff::LCS.diff(seq2, seq1, Diff::LCS::SDiffCallbacks)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "using a Diff::LCS.sdiff patchset" do
|
93
|
+
describe "with default diff callbacks (DiffCallbacks)" do
|
94
|
+
describe "forward (s1 -> s2)" do
|
95
|
+
it_has_behavior "patch sequences correctly" do
|
96
|
+
let(:s1) { seq1 }
|
97
|
+
let(:s2) { seq2 }
|
98
|
+
let(:patch_set) {
|
99
|
+
Diff::LCS.sdiff(seq1, seq2, Diff::LCS::DiffCallbacks)
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "reverse (s2 -> s1)" do
|
105
|
+
it_has_behavior "patch sequences correctly" do
|
106
|
+
let(:s1) { seq2 }
|
107
|
+
let(:s2) { seq1 }
|
108
|
+
let(:patch_set) {
|
109
|
+
Diff::LCS.sdiff(seq2, seq1, Diff::LCS::DiffCallbacks)
|
110
|
+
}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "with context diff callbacks (DiffCallbacks)" do
|
116
|
+
describe "forward (s1 -> s2)" do
|
117
|
+
it_has_behavior "patch sequences correctly" do
|
118
|
+
let(:s1) { seq1 }
|
119
|
+
let(:s2) { seq2 }
|
120
|
+
let(:patch_set) {
|
121
|
+
Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "reverse (s2 -> s1)" do
|
127
|
+
it_has_behavior "patch sequences correctly" do
|
128
|
+
let(:s1) { seq2 }
|
129
|
+
let(:s2) { seq1 }
|
130
|
+
let(:patch_set) {
|
131
|
+
Diff::LCS.sdiff(seq2, seq1, Diff::LCS::ContextDiffCallbacks)
|
132
|
+
}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "with sdiff callbacks (SDiffCallbacks)" do
|
138
|
+
describe "forward (s1 -> s2)" do
|
139
|
+
it_has_behavior "patch sequences correctly" do
|
140
|
+
let(:s1) { seq1 }
|
141
|
+
let(:s2) { seq2 }
|
142
|
+
let(:patch_set) { Diff::LCS.sdiff(seq1, seq2) }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "reverse (s2 -> s1)" do
|
147
|
+
it_has_behavior "patch sequences correctly" do
|
148
|
+
let(:s1) { seq2 }
|
149
|
+
let(:s2) { seq1 }
|
150
|
+
let(:patch_set) { Diff::LCS.sdiff(seq2, seq1) }
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Note: because of the error in autodiscovery ("does not autodiscover s1
|
157
|
+
# to s2 patches"), this cannot use the "patch sequences correctly" shared
|
158
|
+
# set. Once the bug in autodiscovery is fixed, this can be converted as
|
159
|
+
# above.
|
160
|
+
describe "fix bug 891: patchsets do not contain the last equal part" do
|
161
|
+
before(:each) do
|
162
|
+
@s1 = %w(a b c d e f g h i j k)
|
163
|
+
@s2 = %w(a b c d D e f g h i j k)
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "using Diff::LCS.diff with default diff callbacks" do
|
167
|
+
before(:each) do
|
168
|
+
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2)
|
169
|
+
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "does not autodiscover s1 to s2 patches" do
|
173
|
+
# It should, but it doesn't.
|
174
|
+
expect do
|
175
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
176
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
177
|
+
|
178
|
+
expect do
|
179
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
180
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
184
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
185
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
189
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
190
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
191
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
192
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
196
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
197
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
198
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
199
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "using Diff::LCS.diff with context diff callbacks" do
|
204
|
+
before(:each) do
|
205
|
+
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::ContextDiffCallbacks)
|
206
|
+
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::ContextDiffCallbacks)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "does not autodiscover s1 to s2 patches" do
|
210
|
+
# It should, but it doesn't.
|
211
|
+
expect do
|
212
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
213
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
214
|
+
|
215
|
+
expect do
|
216
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
217
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
221
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
222
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
226
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
227
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
228
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
229
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
233
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
234
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
235
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
236
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "using Diff::LCS.diff with sdiff callbacks" do
|
241
|
+
before(:each) do
|
242
|
+
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::SDiffCallbacks)
|
243
|
+
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::SDiffCallbacks)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "does not autodiscover s1 to s2 patches" do
|
247
|
+
# It should, but it doesn't.
|
248
|
+
expect do
|
249
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
250
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
251
|
+
|
252
|
+
expect do
|
253
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
254
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
258
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
259
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
263
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
264
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
265
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
266
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
270
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
271
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
272
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
273
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe "using Diff::LCS.sdiff with default sdiff callbacks" do
|
278
|
+
before(:each) do
|
279
|
+
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2)
|
280
|
+
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "does not autodiscover s1 to s2 patches" do
|
284
|
+
# It should, but it doesn't.
|
285
|
+
expect do
|
286
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
287
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
288
|
+
|
289
|
+
expect do
|
290
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
291
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
295
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
296
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
300
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
301
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
302
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
303
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
307
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
308
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
309
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
310
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "using Diff::LCS.sdiff with context diff callbacks" do
|
315
|
+
before(:each) do
|
316
|
+
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::ContextDiffCallbacks)
|
317
|
+
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::ContextDiffCallbacks)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "does not autodiscover s1 to s2 patches" do
|
321
|
+
# It should, but it doesn't.
|
322
|
+
expect do
|
323
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
324
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
325
|
+
|
326
|
+
expect do
|
327
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
328
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
332
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
333
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
337
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
338
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
339
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
340
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
344
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
345
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
346
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
347
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
describe "using Diff::LCS.sdiff with default diff callbacks" do
|
352
|
+
before(:each) do
|
353
|
+
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::DiffCallbacks)
|
354
|
+
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks)
|
355
|
+
end
|
356
|
+
|
357
|
+
it "does not autodiscover s1 to s2 patches" do
|
358
|
+
# It should, but it doesn't.
|
359
|
+
expect do
|
360
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2).should == @s2
|
361
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
362
|
+
|
363
|
+
expect do
|
364
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1).should == @s2
|
365
|
+
end.to raise_error(RuntimeError, /provided patchset/)
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should autodiscover s2 to s1 the left-to-right patches" do
|
369
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1).should == @s1
|
370
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2).should == @s1
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should correctly patch left-to-right (explicit patch)" do
|
374
|
+
Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch).should == @s2
|
375
|
+
Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch).should == @s1
|
376
|
+
Diff::LCS.patch!(@s1, @patch_set_s1_s2).should == @s2
|
377
|
+
Diff::LCS.patch!(@s2, @patch_set_s2_s1).should == @s1
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should correctly patch right-to-left (explicit unpatch)" do
|
381
|
+
Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch).should == @s1
|
382
|
+
Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch).should == @s2
|
383
|
+
Diff::LCS.unpatch!(@s2, @patch_set_s1_s2).should == @s1
|
384
|
+
Diff::LCS.unpatch!(@s1, @patch_set_s2_s1).should == @s2
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
# vim: ft=ruby
|
data/spec/sdiff_spec.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Diff::LCS.sdiff" do
|
6
|
+
include Diff::LCS::SpecHelper::Matchers
|
7
|
+
|
8
|
+
shared_examples "compare sequences correctly" do
|
9
|
+
it "should compare s1 -> s2 correctly" do
|
10
|
+
Diff::LCS.sdiff(s1, s2).should == context_diff(result)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should compare s2 -> s1 correctly" do
|
14
|
+
Diff::LCS.sdiff(s2, s1).should == context_diff(reverse_sdiff(result))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "using seq1 & seq2" do
|
19
|
+
let(:s1) { seq1 }
|
20
|
+
let(:s2) { seq2 }
|
21
|
+
let(:result) { correct_forward_sdiff }
|
22
|
+
|
23
|
+
it_has_behavior "compare sequences correctly"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do
|
27
|
+
let(:s1) { %w(abc def yyy xxx ghi jkl) }
|
28
|
+
let(:s2) { %w(abc dxf xxx ghi jkl) }
|
29
|
+
let(:result) {
|
30
|
+
[
|
31
|
+
[ '=', [ 0, 'abc' ], [ 0, 'abc' ] ],
|
32
|
+
[ '!', [ 1, 'def' ], [ 1, 'dxf' ] ],
|
33
|
+
[ '-', [ 2, 'yyy' ], [ 2, nil ] ],
|
34
|
+
[ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ],
|
35
|
+
[ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ],
|
36
|
+
[ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ]
|
37
|
+
]
|
38
|
+
}
|
39
|
+
|
40
|
+
it_has_behavior "compare sequences correctly"
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "using %w(a b c d e) & %w(a e)" do
|
44
|
+
let(:s1) { %w(a b c d e) }
|
45
|
+
let(:s2) { %w(a e) }
|
46
|
+
let(:result) {
|
47
|
+
[
|
48
|
+
[ '=', [ 0, 'a' ], [ 0, 'a' ] ],
|
49
|
+
[ '-', [ 1, 'b' ], [ 1, nil ] ],
|
50
|
+
[ '-', [ 2, 'c' ], [ 1, nil ] ],
|
51
|
+
[ '-', [ 3, 'd' ], [ 1, nil ] ],
|
52
|
+
[ '=', [ 4, 'e' ], [ 1, 'e' ] ]
|
53
|
+
]
|
54
|
+
}
|
55
|
+
|
56
|
+
it_has_behavior "compare sequences correctly"
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "using %w(a e) & %w(a b c d e)" do
|
60
|
+
let(:s1) { %w(a e) }
|
61
|
+
let(:s2) { %w(a b c d e) }
|
62
|
+
let(:result) {
|
63
|
+
[
|
64
|
+
[ '=', [ 0, 'a' ], [ 0, 'a' ] ],
|
65
|
+
[ '+', [ 1, nil ], [ 1, 'b' ] ],
|
66
|
+
[ '+', [ 1, nil ], [ 2, 'c' ] ],
|
67
|
+
[ '+', [ 1, nil ], [ 3, 'd' ] ],
|
68
|
+
[ '=', [ 1, 'e' ], [ 4, 'e' ] ]
|
69
|
+
]
|
70
|
+
}
|
71
|
+
|
72
|
+
it_has_behavior "compare sequences correctly"
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "using %w(v x a e) & %w(w y a b c d e)" do
|
76
|
+
let(:s1) { %w(v x a e) }
|
77
|
+
let(:s2) { %w(w y a b c d e) }
|
78
|
+
let(:result) {
|
79
|
+
[
|
80
|
+
[ '!', [ 0, 'v' ], [ 0, 'w' ] ],
|
81
|
+
[ '!', [ 1, 'x' ], [ 1, 'y' ] ],
|
82
|
+
[ '=', [ 2, 'a' ], [ 2, 'a' ] ],
|
83
|
+
[ '+', [ 3, nil ], [ 3, 'b' ] ],
|
84
|
+
[ '+', [ 3, nil ], [ 4, 'c' ] ],
|
85
|
+
[ '+', [ 3, nil ], [ 5, 'd' ] ],
|
86
|
+
[ '=', [ 3, 'e' ], [ 6, 'e' ] ]
|
87
|
+
]
|
88
|
+
}
|
89
|
+
|
90
|
+
it_has_behavior "compare sequences correctly"
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "using %w(x a e) & %w(a b c d e)" do
|
94
|
+
let(:s1) { %w(x a e) }
|
95
|
+
let(:s2) { %w(a b c d e) }
|
96
|
+
let(:result) {
|
97
|
+
[
|
98
|
+
[ '-', [ 0, 'x' ], [ 0, nil ] ],
|
99
|
+
[ '=', [ 1, 'a' ], [ 0, 'a' ] ],
|
100
|
+
[ '+', [ 2, nil ], [ 1, 'b' ] ],
|
101
|
+
[ '+', [ 2, nil ], [ 2, 'c' ] ],
|
102
|
+
[ '+', [ 2, nil ], [ 3, 'd' ] ],
|
103
|
+
[ '=', [ 2, 'e' ], [ 4, 'e' ] ]
|
104
|
+
]
|
105
|
+
}
|
106
|
+
|
107
|
+
it_has_behavior "compare sequences correctly"
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "using %w(a e) & %w(x a b c d e)" do
|
111
|
+
let(:s1) { %w(a e) }
|
112
|
+
let(:s2) { %w(x a b c d e) }
|
113
|
+
let(:result) {
|
114
|
+
[
|
115
|
+
[ '+', [ 0, nil ], [ 0, 'x' ] ],
|
116
|
+
[ '=', [ 0, 'a' ], [ 1, 'a' ] ],
|
117
|
+
[ '+', [ 1, nil ], [ 2, 'b' ] ],
|
118
|
+
[ '+', [ 1, nil ], [ 3, 'c' ] ],
|
119
|
+
[ '+', [ 1, nil ], [ 4, 'd' ] ],
|
120
|
+
[ '=', [ 1, 'e' ], [ 5, 'e' ] ]
|
121
|
+
]
|
122
|
+
}
|
123
|
+
|
124
|
+
it_has_behavior "compare sequences correctly"
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "using %w(a e v) & %w(x a b c d e w x)" do
|
128
|
+
let(:s1) { %w(a e v) }
|
129
|
+
let(:s2) { %w(x a b c d e w x) }
|
130
|
+
let(:result) {
|
131
|
+
[
|
132
|
+
[ '+', [ 0, nil ], [ 0, 'x' ] ],
|
133
|
+
[ '=', [ 0, 'a' ], [ 1, 'a' ] ],
|
134
|
+
[ '+', [ 1, nil ], [ 2, 'b' ] ],
|
135
|
+
[ '+', [ 1, nil ], [ 3, 'c' ] ],
|
136
|
+
[ '+', [ 1, nil ], [ 4, 'd' ] ],
|
137
|
+
[ '=', [ 1, 'e' ], [ 5, 'e' ] ],
|
138
|
+
[ '!', [ 2, 'v' ], [ 6, 'w' ] ],
|
139
|
+
[ '+', [ 3, nil ], [ 7, 'x' ] ]
|
140
|
+
]
|
141
|
+
}
|
142
|
+
|
143
|
+
it_has_behavior "compare sequences correctly"
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "using %w() & %w(a b c)" do
|
147
|
+
let(:s1) { %w() }
|
148
|
+
let(:s2) { %w(a b c) }
|
149
|
+
let(:result) {
|
150
|
+
[
|
151
|
+
[ '+', [ 0, nil ], [ 0, 'a' ] ],
|
152
|
+
[ '+', [ 0, nil ], [ 1, 'b' ] ],
|
153
|
+
[ '+', [ 0, nil ], [ 2, 'c' ] ]
|
154
|
+
]
|
155
|
+
}
|
156
|
+
|
157
|
+
it_has_behavior "compare sequences correctly"
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "using %w(a b c) & %w(1)" do
|
161
|
+
let(:s1) { %w(a b c) }
|
162
|
+
let(:s2) { %w(1) }
|
163
|
+
let(:result) {
|
164
|
+
[
|
165
|
+
[ '!', [ 0, 'a' ], [ 0, '1' ] ],
|
166
|
+
[ '-', [ 1, 'b' ], [ 1, nil ] ],
|
167
|
+
[ '-', [ 2, 'c' ], [ 1, nil ] ]
|
168
|
+
]
|
169
|
+
}
|
170
|
+
|
171
|
+
it_has_behavior "compare sequences correctly"
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "using %w(a b c) & %w(c)" do
|
175
|
+
let(:s1) { %w(a b c) }
|
176
|
+
let(:s2) { %w(c) }
|
177
|
+
let(:result) {
|
178
|
+
[
|
179
|
+
[ '-', [ 0, 'a' ], [ 0, nil ] ],
|
180
|
+
[ '-', [ 1, 'b' ], [ 0, nil ] ],
|
181
|
+
[ '=', [ 2, 'c' ], [ 0, 'c' ] ]
|
182
|
+
]
|
183
|
+
}
|
184
|
+
|
185
|
+
it_has_behavior "compare sequences correctly"
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "using %w(abcd efgh ijkl mnop) & []" do
|
189
|
+
let(:s1) { %w(abcd efgh ijkl mnop) }
|
190
|
+
let(:s2) { [] }
|
191
|
+
let(:result) {
|
192
|
+
[
|
193
|
+
[ '-', [ 0, 'abcd' ], [ 0, nil ] ],
|
194
|
+
[ '-', [ 1, 'efgh' ], [ 0, nil ] ],
|
195
|
+
[ '-', [ 2, 'ijkl' ], [ 0, nil ] ],
|
196
|
+
[ '-', [ 3, 'mnop' ], [ 0, nil ] ]
|
197
|
+
]
|
198
|
+
}
|
199
|
+
|
200
|
+
it_has_behavior "compare sequences correctly"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# vim: ft=ruby
|