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