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