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