diff-lcs 1.2.3 → 1.3
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 +83 -0
- data/History.md +220 -0
- data/{License.rdoc → License.md} +0 -0
- data/Manifest.txt +7 -9
- data/README.rdoc +18 -21
- data/Rakefile +37 -19
- data/lib/diff/lcs.rb +5 -85
- data/lib/diff/lcs/change.rb +8 -4
- data/lib/diff/lcs/htmldiff.rb +2 -2
- data/lib/diff/lcs/internals.rb +15 -8
- data/lib/diff/lcs/ldiff.rb +14 -42
- data/spec/diff_spec.rb +18 -12
- data/spec/fixtures/ds1.csv +50 -0
- data/spec/fixtures/ds2.csv +51 -0
- data/spec/hunk_spec.rb +17 -17
- data/spec/issues_spec.rb +40 -15
- data/spec/lcs_spec.rb +23 -21
- data/spec/ldiff_spec.rb +47 -0
- data/spec/patch_spec.rb +145 -137
- data/spec/sdiff_spec.rb +16 -4
- data/spec/spec_helper.rb +33 -2
- data/spec/traverse_balanced_spec.rb +8 -8
- data/spec/traverse_sequences_spec.rb +56 -56
- metadata +84 -180
- data.tar.gz.sig +0 -4
- 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 -135
- data/diff-lcs.gemspec +0 -63
- metadata.gz.sig +0 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
1,3
|
2
|
+
2,7
|
3
|
+
3,13
|
4
|
+
4,21
|
5
|
+
5,31
|
6
|
+
6,43
|
7
|
+
7,57
|
8
|
+
8,73
|
9
|
+
9,91
|
10
|
+
10,111
|
11
|
+
11,133
|
12
|
+
12,157
|
13
|
+
13,183
|
14
|
+
14,211
|
15
|
+
15,241
|
16
|
+
16,273
|
17
|
+
17,307
|
18
|
+
18,343
|
19
|
+
19,381
|
20
|
+
20,421
|
21
|
+
21,463
|
22
|
+
22,507
|
23
|
+
23,553
|
24
|
+
24,601
|
25
|
+
25,651
|
26
|
+
26,703
|
27
|
+
27,757
|
28
|
+
28,813
|
29
|
+
29,871
|
30
|
+
30,931
|
31
|
+
31,993
|
32
|
+
32,1057
|
33
|
+
33,1123
|
34
|
+
34,1191
|
35
|
+
35,1261
|
36
|
+
36,1333
|
37
|
+
37,1407
|
38
|
+
38,1483
|
39
|
+
39,1561
|
40
|
+
40,1641
|
41
|
+
41,1723
|
42
|
+
42,1807
|
43
|
+
43,1893
|
44
|
+
44,1981
|
45
|
+
45,2071
|
46
|
+
46,2163
|
47
|
+
47,2257
|
48
|
+
48,2353
|
49
|
+
49,2451
|
50
|
+
50,2500
|
@@ -0,0 +1,51 @@
|
|
1
|
+
1,3
|
2
|
+
2,7
|
3
|
+
3,13
|
4
|
+
4,21
|
5
|
+
5,31
|
6
|
+
6,42
|
7
|
+
7,57
|
8
|
+
8,73
|
9
|
+
9,91
|
10
|
+
10,111
|
11
|
+
11,133
|
12
|
+
12,157
|
13
|
+
13,183
|
14
|
+
14,211
|
15
|
+
15,241
|
16
|
+
16,273
|
17
|
+
17,307
|
18
|
+
18,343
|
19
|
+
19,200
|
20
|
+
20,421
|
21
|
+
21,463
|
22
|
+
22,507
|
23
|
+
23,553
|
24
|
+
24,601
|
25
|
+
25,651
|
26
|
+
26,703
|
27
|
+
27,757
|
28
|
+
28,813
|
29
|
+
29,871
|
30
|
+
30,931
|
31
|
+
31,123
|
32
|
+
32,1057
|
33
|
+
33,1123
|
34
|
+
34,1000
|
35
|
+
35,1261
|
36
|
+
36,1333
|
37
|
+
37,1407
|
38
|
+
38,1483
|
39
|
+
39,1561
|
40
|
+
40,1641
|
41
|
+
41,1723
|
42
|
+
42,1807
|
43
|
+
43,1893
|
44
|
+
44,1981
|
45
|
+
45,2071
|
46
|
+
46,2163
|
47
|
+
47,1524
|
48
|
+
48,2353
|
49
|
+
49,2451
|
50
|
+
50,2500
|
51
|
+
51,2520
|
data/spec/hunk_spec.rb
CHANGED
@@ -2,28 +2,26 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "Diff::LCS::Hunk" do
|
10
|
-
if String.method_defined?(:encoding)
|
5
|
+
if String.method_defined?(:encoding)
|
6
|
+
require 'diff/lcs/hunk'
|
11
7
|
|
8
|
+
describe Diff::LCS::Hunk do
|
12
9
|
let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] }
|
13
10
|
let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] }
|
14
11
|
let(:pieces) { Diff::LCS.diff old_data, new_data }
|
15
12
|
let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
|
16
13
|
|
17
|
-
it '
|
14
|
+
it 'produces a unified diff from the two pieces' do
|
18
15
|
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
|
19
16
|
@@ -1,2 +1,2 @@
|
20
17
|
-Tu avec carté {count} itém has
|
21
18
|
+Tu avec carte {count} item has
|
22
19
|
EOD
|
23
|
-
|
20
|
+
|
21
|
+
expect(hunk.diff(:unified)).to eq(expected)
|
24
22
|
end
|
25
23
|
|
26
|
-
it '
|
24
|
+
it 'produces a context diff from the two pieces' do
|
27
25
|
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
|
28
26
|
***************
|
29
27
|
*** 1,2 ****
|
@@ -32,10 +30,10 @@ describe "Diff::LCS::Hunk" do
|
|
32
30
|
!Tu avec carte {count} item has
|
33
31
|
EOD
|
34
32
|
|
35
|
-
expect(hunk.diff(:context).
|
33
|
+
expect(hunk.diff(:context)).to eq(expected)
|
36
34
|
end
|
37
35
|
|
38
|
-
it '
|
36
|
+
it 'produces an old diff from the two pieces' do
|
39
37
|
expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
|
40
38
|
1,2c1,2
|
41
39
|
< Tu avec carté {count} itém has
|
@@ -43,30 +41,32 @@ describe "Diff::LCS::Hunk" do
|
|
43
41
|
> Tu avec carte {count} item has
|
44
42
|
|
45
43
|
EOD
|
46
|
-
|
44
|
+
|
45
|
+
expect(hunk.diff(:old)).to eq(expected)
|
47
46
|
end
|
48
47
|
|
49
|
-
it '
|
48
|
+
it 'produces a reverse ed diff from the two pieces' do
|
50
49
|
expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
|
51
50
|
c1,2
|
52
51
|
Tu avec carte {count} item has
|
53
52
|
.
|
54
53
|
|
55
54
|
EOD
|
56
|
-
|
55
|
+
|
56
|
+
expect(hunk.diff(:reverse_ed)).to eq(expected)
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'with empty first data set' do
|
60
60
|
let(:old_data) { [] }
|
61
61
|
|
62
|
-
it '
|
62
|
+
it 'produces a unified diff' do
|
63
63
|
expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
|
64
64
|
@@ -1 +1,2 @@
|
65
65
|
+Tu avec carte {count} item has
|
66
66
|
EOD
|
67
|
-
|
67
|
+
|
68
|
+
expect(hunk.diff(:unified)).to eq(expected)
|
68
69
|
end
|
69
70
|
end
|
70
|
-
|
71
71
|
end
|
72
72
|
end
|
data/spec/issues_spec.rb
CHANGED
@@ -5,20 +5,45 @@ require 'spec_helper'
|
|
5
5
|
describe "Diff::LCS Issues" do
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
7
7
|
|
8
|
-
|
9
|
-
s1, s2
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
describe 'issue #1' do
|
9
|
+
shared_examples 'handles simple diffs' do |s1, s2, forward_diff|
|
10
|
+
before do
|
11
|
+
@diff_s1_s2 = Diff::LCS.diff(s1, s2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates the correct diff' do
|
15
|
+
expect(change_diff(forward_diff)).to eq(@diff_s1_s2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'creates the correct patch s1->s2' do
|
19
|
+
expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'creates the correct patch s2->s1' do
|
23
|
+
expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'string' do
|
28
|
+
it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [
|
29
|
+
[ [ '+', 0, 'b' ],
|
30
|
+
[ '+', 1, 'X' ] ],
|
31
|
+
]
|
32
|
+
it_has_behavior 'handles simple diffs', 'bXaX', 'aX', [
|
33
|
+
[ [ '-', 0, 'b' ],
|
34
|
+
[ '-', 1, 'X' ] ],
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'array' do
|
39
|
+
it_has_behavior 'handles simple diffs', %w(a X), %w(b X a X), [
|
40
|
+
[ [ '+', 0, 'b' ],
|
41
|
+
[ '+', 1, 'X' ] ],
|
42
|
+
]
|
43
|
+
it_has_behavior 'handles simple diffs', %w(b X a X), %w(a X), [
|
44
|
+
[ [ '-', 0, 'b' ],
|
45
|
+
[ '-', 1, 'X' ] ],
|
46
|
+
]
|
47
|
+
end
|
23
48
|
end
|
24
49
|
end
|
data/spec/lcs_spec.rb
CHANGED
@@ -2,53 +2,55 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Diff::LCS::Internals, ".lcs" do
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
7
7
|
|
8
|
-
it "
|
8
|
+
it "returns a meaningful LCS array with (seq1, seq2)" do
|
9
9
|
res = Diff::LCS::Internals.lcs(seq1, seq2)
|
10
10
|
# The result of the LCS (less the +nil+ values) must be as long as the
|
11
11
|
# correct result.
|
12
|
-
res.compact.size.
|
13
|
-
res.
|
12
|
+
expect(res.compact.size).to eq(correct_lcs.size)
|
13
|
+
expect(res).to correctly_map_sequence(seq1).to_other_sequence(seq2)
|
14
14
|
|
15
15
|
# Compact these transformations and they should be the correct LCS.
|
16
16
|
x_seq1 = (0...res.size).map { |ix| res[ix] ? seq1[ix] : nil }.compact
|
17
17
|
x_seq2 = (0...res.size).map { |ix| res[ix] ? seq2[res[ix]] : nil }.compact
|
18
18
|
|
19
|
-
x_seq1.
|
20
|
-
x_seq2.
|
19
|
+
expect(x_seq1).to eq(correct_lcs)
|
20
|
+
expect(x_seq2).to eq(correct_lcs)
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
24
|
-
Diff::LCS::Internals.lcs(hello, hello).
|
23
|
+
it "returns all indexes with (hello, hello)" do
|
24
|
+
expect(Diff::LCS::Internals.lcs(hello, hello)).to \
|
25
|
+
eq((0...hello.size).to_a)
|
25
26
|
end
|
26
27
|
|
27
|
-
it "
|
28
|
-
Diff::LCS::Internals.lcs(hello_ary, hello_ary).
|
28
|
+
it "returns all indexes with (hello_ary, hello_ary)" do
|
29
|
+
expect(Diff::LCS::Internals.lcs(hello_ary, hello_ary)).to \
|
30
|
+
eq((0...hello_ary.size).to_a)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
describe
|
34
|
+
describe Diff::LCS, ".LCS" do
|
33
35
|
include Diff::LCS::SpecHelper::Matchers
|
34
36
|
|
35
|
-
it "
|
37
|
+
it "returns the correct compacted values from Diff::LCS.LCS" do
|
36
38
|
res = Diff::LCS.LCS(seq1, seq2)
|
37
|
-
res.
|
38
|
-
res.compact.
|
39
|
+
expect(res).to eq(correct_lcs)
|
40
|
+
expect(res.compact).to eq(res)
|
39
41
|
end
|
40
42
|
|
41
|
-
it "
|
43
|
+
it "is transitive" do
|
42
44
|
res = Diff::LCS.LCS(seq2, seq1)
|
43
|
-
res.
|
44
|
-
res.compact.
|
45
|
+
expect(res).to eq(correct_lcs)
|
46
|
+
expect(res.compact).to eq(res)
|
45
47
|
end
|
46
48
|
|
47
|
-
it "
|
48
|
-
Diff::LCS.LCS(hello, hello).
|
49
|
+
it "returns %W(h e l l o) with (hello, hello)" do
|
50
|
+
expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//))
|
49
51
|
end
|
50
52
|
|
51
|
-
it "
|
52
|
-
Diff::LCS.LCS(hello_ary, hello_ary).
|
53
|
+
it "returns hello_ary with (hello_ary, hello_ary)" do
|
54
|
+
expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary)
|
53
55
|
end
|
54
56
|
end
|
data/spec/ldiff_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Diff::LCS.diff" do
|
6
|
+
include Diff::LCS::SpecHelper::Matchers
|
7
|
+
|
8
|
+
it 'correctly diffs seq1 to seq2' do
|
9
|
+
diff_s1_s2 = Diff::LCS.diff(seq1, seq2)
|
10
|
+
expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'correctly diffs seq2 to seq1' do
|
14
|
+
diff_s2_s1 = Diff::LCS.diff(seq2, seq1)
|
15
|
+
expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'correctly diffs against an empty sequence' do
|
19
|
+
diff = Diff::LCS.diff(word_sequence, [])
|
20
|
+
correct_diff = [
|
21
|
+
[ [ '-', 0, 'abcd' ],
|
22
|
+
[ '-', 1, 'efgh' ],
|
23
|
+
[ '-', 2, 'ijkl' ],
|
24
|
+
[ '-', 3, 'mnopqrstuvwxyz' ] ]
|
25
|
+
]
|
26
|
+
|
27
|
+
expect(change_diff(correct_diff)).to eq(diff)
|
28
|
+
|
29
|
+
diff = Diff::LCS.diff([], word_sequence)
|
30
|
+
correct_diff.each { |hunk| hunk.each { |change| change[0] = '+' } }
|
31
|
+
expect(change_diff(correct_diff)).to eq(diff)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "correctly diffs 'xx' and 'xaxb'" do
|
35
|
+
left = 'xx'
|
36
|
+
right = 'xaxb'
|
37
|
+
expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns an empty diff with (hello, hello)" do
|
41
|
+
expect(Diff::LCS.diff(hello, hello)).to eq([])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns an empty diff with (hello_ary, hello_ary)" do
|
45
|
+
expect(Diff::LCS.diff(hello_ary, hello_ary)).to eq([])
|
46
|
+
end
|
47
|
+
end
|
data/spec/patch_spec.rb
CHANGED
@@ -6,33 +6,35 @@ describe "Diff::LCS.patch" do
|
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
7
7
|
|
8
8
|
shared_examples "patch sequences correctly" do
|
9
|
-
it "
|
10
|
-
Diff::LCS.patch(s1, patch_set).
|
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
28
|
describe "using a Diff::LCS.diff patchset" do
|
29
29
|
describe "an empty patchset returns the source" do
|
30
30
|
it "works on a string (hello)" do
|
31
|
-
|
31
|
+
diff = Diff::LCS.diff(hello, hello)
|
32
|
+
expect(Diff::LCS::patch(hello, diff)).to eq(hello)
|
32
33
|
end
|
33
34
|
|
34
35
|
it "works on an array %W(h e l l o)" do
|
35
|
-
|
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
|
|
@@ -102,11 +104,11 @@ describe "Diff::LCS.patch" do
|
|
102
104
|
describe "using a Diff::LCS.sdiff patchset" do
|
103
105
|
describe "an empty patchset returns the source" do
|
104
106
|
it "works on a string (hello)" do
|
105
|
-
Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello)).
|
107
|
+
expect(Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello)
|
106
108
|
end
|
107
109
|
|
108
110
|
it "works on an array %W(h e l l o)" do
|
109
|
-
Diff::LCS::patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary)).
|
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
|
|
@@ -178,122 +180,126 @@ describe "Diff::LCS.patch" do
|
|
178
180
|
# set. Once the bug in autodiscovery is fixed, this can be converted as
|
179
181
|
# above.
|
180
182
|
describe "fix bug 891: patchsets do not contain the last equal part" do
|
181
|
-
before
|
183
|
+
before :each do
|
182
184
|
@s1 = %w(a b c d e f g h i j k)
|
183
185
|
@s2 = %w(a b c d D e f g h i j k)
|
184
186
|
end
|
185
187
|
|
186
188
|
describe "using Diff::LCS.diff with default diff callbacks" do
|
187
|
-
before
|
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
226
|
describe "using Diff::LCS.diff with context diff callbacks" do
|
225
|
-
before
|
226
|
-
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
|
227
|
-
|
227
|
+
before :each do
|
228
|
+
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
|
229
|
+
Diff::LCS::ContextDiffCallbacks)
|
230
|
+
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1,
|
231
|
+
Diff::LCS::ContextDiffCallbacks)
|
228
232
|
end
|
229
233
|
|
230
|
-
it "
|
234
|
+
it "autodiscovers s1 to s2 patches" do
|
231
235
|
expect do
|
232
|
-
Diff::LCS.patch(@s1, @patch_set_s1_s2).
|
233
|
-
end.to_not raise_error
|
236
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
|
237
|
+
end.to_not raise_error
|
234
238
|
end
|
235
239
|
|
236
|
-
it "
|
240
|
+
it "autodiscovers s2 to s1 patches" do
|
237
241
|
expect do
|
238
|
-
Diff::LCS.patch(@s1, @patch_set_s2_s1).
|
239
|
-
end.to_not raise_error
|
242
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
|
243
|
+
end.to_not raise_error
|
240
244
|
end
|
241
245
|
|
242
|
-
it "
|
243
|
-
Diff::LCS.patch(@s2, @patch_set_s2_s1).
|
244
|
-
Diff::LCS.patch(@s2, @patch_set_s1_s2).
|
246
|
+
it "autodiscovers s2 to s1 the left-to-right patches" do
|
247
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
|
248
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
|
245
249
|
end
|
246
250
|
|
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).
|
251
|
+
it "correctly patches left-to-right (explicit patch)" do
|
252
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
|
253
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
|
254
|
+
expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
|
255
|
+
expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
|
252
256
|
end
|
253
257
|
|
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).
|
258
|
+
it "correctly patches right-to-left (explicit unpatch)" do
|
259
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
|
260
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
|
261
|
+
expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
|
262
|
+
expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
|
259
263
|
end
|
260
264
|
end
|
261
265
|
|
262
266
|
describe "using Diff::LCS.diff with sdiff callbacks" do
|
263
267
|
before(:each) do
|
264
|
-
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
|
265
|
-
|
268
|
+
@patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2,
|
269
|
+
Diff::LCS::SDiffCallbacks)
|
270
|
+
@patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1,
|
271
|
+
Diff::LCS::SDiffCallbacks)
|
266
272
|
end
|
267
273
|
|
268
|
-
it "
|
274
|
+
it "autodiscovers s1 to s2 patches" do
|
269
275
|
expect do
|
270
|
-
Diff::LCS.patch(@s1, @patch_set_s1_s2).
|
271
|
-
end.to_not raise_error
|
276
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
|
277
|
+
end.to_not raise_error
|
272
278
|
end
|
273
279
|
|
274
|
-
it "
|
280
|
+
it "autodiscovers s2 to s1 patches" do
|
275
281
|
expect do
|
276
|
-
Diff::LCS.patch(@s1, @patch_set_s2_s1).
|
277
|
-
end.to_not raise_error
|
282
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
|
283
|
+
end.to_not raise_error
|
278
284
|
end
|
279
285
|
|
280
|
-
it "
|
281
|
-
Diff::LCS.patch(@s2, @patch_set_s2_s1).
|
282
|
-
Diff::LCS.patch(@s2, @patch_set_s1_s2).
|
286
|
+
it "autodiscovers s2 to s1 the left-to-right patches" do
|
287
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
|
288
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
|
283
289
|
end
|
284
290
|
|
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).
|
291
|
+
it "correctly patches left-to-right (explicit patch)" do
|
292
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
|
293
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
|
294
|
+
expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
|
295
|
+
expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
|
290
296
|
end
|
291
297
|
|
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).
|
298
|
+
it "correctly patches right-to-left (explicit unpatch)" do
|
299
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
|
300
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
|
301
|
+
expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
|
302
|
+
expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
|
297
303
|
end
|
298
304
|
end
|
299
305
|
|
@@ -303,73 +309,75 @@ describe "Diff::LCS.patch" do
|
|
303
309
|
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1)
|
304
310
|
end
|
305
311
|
|
306
|
-
it "
|
312
|
+
it "autodiscovers s1 to s2 patches" do
|
307
313
|
expect do
|
308
|
-
Diff::LCS.patch(@s1, @patch_set_s1_s2).
|
309
|
-
end.to_not raise_error
|
314
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
|
315
|
+
end.to_not raise_error
|
310
316
|
end
|
311
317
|
|
312
|
-
it "
|
318
|
+
it "autodiscovers s2 to s1 patches" do
|
313
319
|
expect do
|
314
|
-
Diff::LCS.patch(@s1, @patch_set_s2_s1).
|
315
|
-
end.to_not raise_error
|
320
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
|
321
|
+
end.to_not raise_error
|
316
322
|
end
|
317
323
|
|
318
|
-
it "
|
319
|
-
Diff::LCS.patch(@s2, @patch_set_s2_s1).
|
320
|
-
Diff::LCS.patch(@s2, @patch_set_s1_s2).
|
324
|
+
it "autodiscovers s2 to s1 the left-to-right patches" do
|
325
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
|
326
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
|
321
327
|
end
|
322
328
|
|
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).
|
329
|
+
it "correctly patches left-to-right (explicit patch)" do
|
330
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
|
331
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
|
332
|
+
expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
|
333
|
+
expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
|
328
334
|
end
|
329
335
|
|
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).
|
336
|
+
it "correctly patches right-to-left (explicit unpatch)" do
|
337
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
|
338
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
|
339
|
+
expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
|
340
|
+
expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
|
335
341
|
end
|
336
342
|
end
|
337
343
|
|
338
344
|
describe "using Diff::LCS.sdiff with context diff callbacks" do
|
339
345
|
before(:each) do
|
340
|
-
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2,
|
341
|
-
|
346
|
+
@patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2,
|
347
|
+
Diff::LCS::ContextDiffCallbacks)
|
348
|
+
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1,
|
349
|
+
Diff::LCS::ContextDiffCallbacks)
|
342
350
|
end
|
343
351
|
|
344
|
-
it "
|
352
|
+
it "autodiscovers s1 to s2 patches" do
|
345
353
|
expect do
|
346
|
-
Diff::LCS.patch(@s1, @patch_set_s1_s2).
|
347
|
-
end.to_not raise_error
|
354
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
|
355
|
+
end.to_not raise_error
|
348
356
|
end
|
349
357
|
|
350
|
-
it "
|
358
|
+
it "autodiscovers s2 to s1 patches" do
|
351
359
|
expect do
|
352
|
-
Diff::LCS.patch(@s1, @patch_set_s2_s1).
|
353
|
-
end.to_not raise_error
|
360
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
|
361
|
+
end.to_not raise_error
|
354
362
|
end
|
355
363
|
|
356
|
-
it "
|
357
|
-
Diff::LCS.patch(@s2, @patch_set_s2_s1).
|
358
|
-
Diff::LCS.patch(@s2, @patch_set_s1_s2).
|
364
|
+
it "autodiscovers s2 to s1 the left-to-right patches" do
|
365
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
|
366
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
|
359
367
|
end
|
360
368
|
|
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).
|
369
|
+
it "correctly patches left-to-right (explicit patch)" do
|
370
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
|
371
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
|
372
|
+
expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
|
373
|
+
expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
|
366
374
|
end
|
367
375
|
|
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).
|
376
|
+
it "correctly patches right-to-left (explicit unpatch)" do
|
377
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
|
378
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
|
379
|
+
expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
|
380
|
+
expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
|
373
381
|
end
|
374
382
|
end
|
375
383
|
|
@@ -379,35 +387,35 @@ describe "Diff::LCS.patch" do
|
|
379
387
|
@patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks)
|
380
388
|
end
|
381
389
|
|
382
|
-
it "
|
390
|
+
it "autodiscovers s1 to s2 patches" do
|
383
391
|
expect do
|
384
|
-
Diff::LCS.patch(@s1, @patch_set_s1_s2).
|
385
|
-
end.to_not raise_error
|
392
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2)
|
393
|
+
end.to_not raise_error
|
386
394
|
end
|
387
395
|
|
388
|
-
it "
|
396
|
+
it "autodiscovers s2 to s1 patches" do
|
389
397
|
expect do
|
390
|
-
Diff::LCS.patch(@s1, @patch_set_s2_s1).
|
391
|
-
end.to_not raise_error
|
398
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2)
|
399
|
+
end.to_not raise_error
|
392
400
|
end
|
393
401
|
|
394
|
-
it "
|
395
|
-
Diff::LCS.patch(@s2, @patch_set_s2_s1).
|
396
|
-
Diff::LCS.patch(@s2, @patch_set_s1_s2).
|
402
|
+
it "autodiscovers s2 to s1 the left-to-right patches" do
|
403
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1)
|
404
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1)
|
397
405
|
end
|
398
406
|
|
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).
|
407
|
+
it "correctly patches left-to-right (explicit patch)" do
|
408
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2)
|
409
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1)
|
410
|
+
expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2)
|
411
|
+
expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1)
|
404
412
|
end
|
405
413
|
|
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).
|
414
|
+
it "correctly patches right-to-left (explicit unpatch)" do
|
415
|
+
expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1)
|
416
|
+
expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2)
|
417
|
+
expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1)
|
418
|
+
expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2)
|
411
419
|
end
|
412
420
|
end
|
413
421
|
end
|