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/change_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Diff::LCS::Change do
|
6
|
-
describe
|
6
|
+
describe 'an add' do
|
7
7
|
subject { described_class.new('+', 0, 'element') }
|
8
8
|
it { should_not be_deleting }
|
9
9
|
it { should be_adding }
|
@@ -13,7 +13,7 @@ describe Diff::LCS::Change do
|
|
13
13
|
it { should_not be_finished_b }
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe 'a delete' do
|
17
17
|
subject { described_class.new('-', 0, 'element') }
|
18
18
|
it { should be_deleting }
|
19
19
|
it { should_not be_adding }
|
@@ -23,7 +23,7 @@ describe Diff::LCS::Change do
|
|
23
23
|
it { should_not be_finished_b }
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe 'an unchanged' do
|
27
27
|
subject { described_class.new('=', 0, 'element') }
|
28
28
|
it { should_not be_deleting }
|
29
29
|
it { should_not be_adding }
|
@@ -33,7 +33,7 @@ describe Diff::LCS::Change do
|
|
33
33
|
it { should_not be_finished_b }
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
36
|
+
describe 'a changed' do
|
37
37
|
subject { described_class.new('!', 0, 'element') }
|
38
38
|
it { should_not be_deleting }
|
39
39
|
it { should_not be_adding }
|
@@ -43,7 +43,7 @@ describe Diff::LCS::Change do
|
|
43
43
|
it { should_not be_finished_b }
|
44
44
|
end
|
45
45
|
|
46
|
-
describe
|
46
|
+
describe 'a finished_a' do
|
47
47
|
subject { described_class.new('>', 0, 'element') }
|
48
48
|
it { should_not be_deleting }
|
49
49
|
it { should_not be_adding }
|
@@ -53,7 +53,7 @@ describe Diff::LCS::Change do
|
|
53
53
|
it { should_not be_finished_b }
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
56
|
+
describe 'a finished_b' do
|
57
57
|
subject { described_class.new('<', 0, 'element') }
|
58
58
|
it { should_not be_deleting }
|
59
59
|
it { should_not be_adding }
|
@@ -62,4 +62,28 @@ describe Diff::LCS::Change do
|
|
62
62
|
it { should_not be_finished_a }
|
63
63
|
it { should be_finished_b }
|
64
64
|
end
|
65
|
+
|
66
|
+
describe 'as array' do
|
67
|
+
it 'should be converted' do
|
68
|
+
action, position, element = described_class.new('!', 0, 'element')
|
69
|
+
expect(action).to eq '!'
|
70
|
+
expect(position).to eq 0
|
71
|
+
expect(element).to eq 'element'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe Diff::LCS::ContextChange do
|
77
|
+
describe 'as array' do
|
78
|
+
it 'should be converted' do
|
79
|
+
action, (old_position, old_element), (new_position, new_element) =
|
80
|
+
described_class.new('!', 1, 'old_element', 2, 'new_element')
|
81
|
+
|
82
|
+
expect(action).to eq '!'
|
83
|
+
expect(old_position).to eq 1
|
84
|
+
expect(old_element).to eq 'old_element'
|
85
|
+
expect(new_position).to eq 2
|
86
|
+
expect(new_element).to eq 'new_element'
|
87
|
+
end
|
88
|
+
end
|
65
89
|
end
|
data/spec/diff_spec.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Diff::LCS,
|
5
|
+
describe Diff::LCS, '.diff' do
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'correctly diffs seq1 to seq2' do
|
9
9
|
diff_s1_s2 = Diff::LCS.diff(seq1, seq2)
|
10
10
|
expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'correctly diffs seq2 to seq1' do
|
14
14
|
diff_s2_s1 = Diff::LCS.diff(seq2, seq1)
|
15
15
|
expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'correctly diffs against an empty sequence' do
|
19
19
|
diff = Diff::LCS.diff(word_sequence, [])
|
20
20
|
correct_diff = [
|
21
|
-
[
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
21
|
+
[
|
22
|
+
['-', 0, 'abcd'],
|
23
|
+
['-', 1, 'efgh'],
|
24
|
+
['-', 2, 'ijkl'],
|
25
|
+
['-', 3, 'mnopqrstuvwxyz']
|
26
|
+
]
|
25
27
|
]
|
26
28
|
|
27
29
|
expect(change_diff(correct_diff)).to eq(diff)
|
28
30
|
|
29
31
|
diff = Diff::LCS.diff([], word_sequence)
|
30
|
-
correct_diff.each
|
32
|
+
correct_diff.each do |hunk|
|
33
|
+
hunk.each do |change| change[0] = '+' end
|
34
|
+
end
|
31
35
|
expect(change_diff(correct_diff)).to eq(diff)
|
32
36
|
end
|
33
37
|
|
@@ -37,11 +41,11 @@ describe Diff::LCS, ".diff" do
|
|
37
41
|
expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
|
38
42
|
end
|
39
43
|
|
40
|
-
it
|
44
|
+
it 'returns an empty diff with (hello, hello)' do
|
41
45
|
expect(Diff::LCS.diff(hello, hello)).to be_empty
|
42
46
|
end
|
43
47
|
|
44
|
-
it
|
48
|
+
it 'returns an empty diff with (hello_ary, hello_ary)' do
|
45
49
|
expect(Diff::LCS.diff(hello_ary, hello_ary)).to be_empty
|
46
50
|
end
|
47
51
|
end
|
data/spec/fixtures/aX
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
aX
|
data/spec/fixtures/bXaX
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bXaX
|
@@ -0,0 +1,15 @@
|
|
1
|
+
*** spec/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400
|
2
|
+
--- spec/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400
|
3
|
+
***************
|
4
|
+
*** 1,4 ****
|
5
|
+
{
|
6
|
+
"name": "x",
|
7
|
+
! "description": "hi"
|
8
|
+
}
|
9
|
+
|
10
|
+
--- 1,4 ----
|
11
|
+
{
|
12
|
+
"name": "x",
|
13
|
+
! "description": "lo"
|
14
|
+
}
|
15
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
*** spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
|
2
|
+
--- spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
|
3
|
+
***************
|
4
|
+
*** 1,5 ****
|
5
|
+
recipe[a::default]
|
6
|
+
- recipe[b::default]
|
7
|
+
recipe[c::default]
|
8
|
+
recipe[d::default]
|
9
|
+
recipe[e::default]
|
10
|
+
--- 1,4 ----
|
11
|
+
***************
|
12
|
+
*** 12,14 ****
|
13
|
+
--- 11,17 ----
|
14
|
+
recipe[l::default]
|
15
|
+
recipe[m::default]
|
16
|
+
recipe[n::default]
|
17
|
+
+ recipe[o::new]
|
18
|
+
+ recipe[p::new]
|
19
|
+
+ recipe[q::new]
|
20
|
+
+ recipe[r::new]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
--- spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
|
2
|
+
+++ spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
|
3
|
+
@@ -1,5 +1,4 @@
|
4
|
+
recipe[a::default]
|
5
|
+
-recipe[b::default]
|
6
|
+
recipe[c::default]
|
7
|
+
recipe[d::default]
|
8
|
+
recipe[e::default]
|
9
|
+
@@ -12,3 +11,7 @@
|
10
|
+
recipe[l::default]
|
11
|
+
recipe[m::default]
|
12
|
+
recipe[n::default]
|
13
|
+
+recipe[o::new]
|
14
|
+
+recipe[p::new]
|
15
|
+
+recipe[q::new]
|
16
|
+
+recipe[r::new]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
recipe[a::default]
|
2
|
+
recipe[c::default]
|
3
|
+
recipe[d::default]
|
4
|
+
recipe[e::default]
|
5
|
+
recipe[f::default]
|
6
|
+
recipe[g::default]
|
7
|
+
recipe[h::default]
|
8
|
+
recipe[i::default]
|
9
|
+
recipe[j::default]
|
10
|
+
recipe[k::default]
|
11
|
+
recipe[l::default]
|
12
|
+
recipe[m::default]
|
13
|
+
recipe[n::default]
|
14
|
+
recipe[o::new]
|
15
|
+
recipe[p::new]
|
16
|
+
recipe[q::new]
|
17
|
+
recipe[r::new]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
recipe[a::default]
|
2
|
+
recipe[b::default]
|
3
|
+
recipe[c::default]
|
4
|
+
recipe[d::default]
|
5
|
+
recipe[e::default]
|
6
|
+
recipe[f::default]
|
7
|
+
recipe[g::default]
|
8
|
+
recipe[h::default]
|
9
|
+
recipe[i::default]
|
10
|
+
recipe[j::default]
|
11
|
+
recipe[k::default]
|
12
|
+
recipe[l::default]
|
13
|
+
recipe[m::default]
|
14
|
+
recipe[n::default]
|
data/spec/hunk_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,52 +6,63 @@ if String.method_defined?(:encoding)
|
|
6
6
|
require 'diff/lcs/hunk'
|
7
7
|
|
8
8
|
describe Diff::LCS::Hunk do
|
9
|
-
let(:old_data) { [
|
10
|
-
let(:new_data) { [
|
9
|
+
let(:old_data) { ['Tu a un carté avec {count} itéms'.encode('UTF-16LE')] }
|
10
|
+
let(:new_data) { ['Tu a un carte avec {count} items'.encode('UTF-16LE')] }
|
11
11
|
let(:pieces) { Diff::LCS.diff old_data, new_data }
|
12
12
|
let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
|
13
13
|
|
14
14
|
it 'produces a unified diff from the two pieces' do
|
15
|
-
expected =
|
16
|
-
@@ -1
|
17
|
-
-Tu
|
18
|
-
+Tu
|
19
|
-
|
15
|
+
expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
|
16
|
+
@@ -1 +1 @@
|
17
|
+
-Tu a un carté avec {count} itéms
|
18
|
+
+Tu a un carte avec {count} items
|
19
|
+
EXPECTED
|
20
20
|
|
21
21
|
expect(hunk.diff(:unified)).to eq(expected)
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'produces a unified diff from the two pieces (last entry)' do
|
25
|
+
expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
|
26
|
+
@@ -1 +1 @@
|
27
|
+
-Tu a un carté avec {count} itéms
|
28
|
+
+Tu a un carte avec {count} items
|
29
|
+
\
|
30
|
+
EXPECTED
|
31
|
+
|
32
|
+
expect(hunk.diff(:unified, true)).to eq(expected)
|
33
|
+
end
|
34
|
+
|
24
35
|
it 'produces a context diff from the two pieces' do
|
25
|
-
expected =
|
36
|
+
expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
|
26
37
|
***************
|
27
|
-
*** 1
|
28
|
-
!Tu
|
29
|
-
--- 1
|
30
|
-
!Tu
|
31
|
-
|
38
|
+
*** 1 ****
|
39
|
+
! Tu a un carté avec {count} itéms
|
40
|
+
--- 1 ----
|
41
|
+
! Tu a un carte avec {count} items
|
42
|
+
EXPECTED
|
32
43
|
|
33
44
|
expect(hunk.diff(:context)).to eq(expected)
|
34
45
|
end
|
35
46
|
|
36
47
|
it 'produces an old diff from the two pieces' do
|
37
|
-
expected =
|
38
|
-
|
39
|
-
< Tu
|
48
|
+
expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp
|
49
|
+
1c1
|
50
|
+
< Tu a un carté avec {count} itéms
|
40
51
|
---
|
41
|
-
> Tu
|
52
|
+
> Tu a un carte avec {count} items
|
42
53
|
|
43
|
-
|
54
|
+
EXPECTED
|
44
55
|
|
45
56
|
expect(hunk.diff(:old)).to eq(expected)
|
46
57
|
end
|
47
58
|
|
48
59
|
it 'produces a reverse ed diff from the two pieces' do
|
49
|
-
expected =
|
50
|
-
c1
|
51
|
-
Tu
|
60
|
+
expected = <<-EXPECTED.gsub(/^ +/, '').encode('UTF-16LE').chomp
|
61
|
+
c1
|
62
|
+
Tu a un carte avec {count} items
|
52
63
|
.
|
53
64
|
|
54
|
-
|
65
|
+
EXPECTED
|
55
66
|
|
56
67
|
expect(hunk.diff(:reverse_ed)).to eq(expected)
|
57
68
|
end
|
@@ -60,10 +71,10 @@ if String.method_defined?(:encoding)
|
|
60
71
|
let(:old_data) { [] }
|
61
72
|
|
62
73
|
it 'produces a unified diff' do
|
63
|
-
expected =
|
74
|
+
expected = <<-EXPECTED.gsub(/^\s+/, '').encode('UTF-16LE').chomp
|
64
75
|
@@ -1 +1,2 @@
|
65
|
-
+Tu
|
66
|
-
|
76
|
+
+Tu a un carte avec {count} items
|
77
|
+
EXPECTED
|
67
78
|
|
68
79
|
expect(hunk.diff(:unified)).to eq(expected)
|
69
80
|
end
|
data/spec/issues_spec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require 'diff/lcs/hunk'
|
4
5
|
|
5
|
-
describe
|
6
|
+
describe 'Diff::LCS Issues' do
|
6
7
|
include Diff::LCS::SpecHelper::Matchers
|
7
8
|
|
8
9
|
describe 'issue #1' do
|
@@ -26,24 +27,128 @@ describe "Diff::LCS Issues" do
|
|
26
27
|
|
27
28
|
describe 'string' do
|
28
29
|
it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [
|
29
|
-
[
|
30
|
-
[
|
30
|
+
[
|
31
|
+
['+', 0, 'b'],
|
32
|
+
['+', 1, 'X']
|
33
|
+
]
|
31
34
|
]
|
32
35
|
it_has_behavior 'handles simple diffs', 'bXaX', 'aX', [
|
33
|
-
[
|
34
|
-
[
|
36
|
+
[
|
37
|
+
['-', 0, 'b'],
|
38
|
+
['-', 1, 'X']
|
39
|
+
]
|
35
40
|
]
|
36
41
|
end
|
37
42
|
|
38
43
|
describe 'array' do
|
39
44
|
it_has_behavior 'handles simple diffs', %w(a X), %w(b X a X), [
|
40
|
-
[
|
41
|
-
[
|
45
|
+
[
|
46
|
+
['+', 0, 'b'],
|
47
|
+
['+', 1, 'X']
|
48
|
+
]
|
42
49
|
]
|
43
50
|
it_has_behavior 'handles simple diffs', %w(b X a X), %w(a X), [
|
44
|
-
[
|
45
|
-
[
|
51
|
+
[
|
52
|
+
['-', 0, 'b'],
|
53
|
+
['-', 1, 'X']
|
54
|
+
]
|
46
55
|
]
|
47
56
|
end
|
48
57
|
end
|
58
|
+
|
59
|
+
describe 'issue #57' do
|
60
|
+
it 'should fail with a correct error' do
|
61
|
+
expect {
|
62
|
+
actual = { :category => 'app.rack.request' }
|
63
|
+
expected = { :category => 'rack.middleware', :title => 'Anonymous Middleware' }
|
64
|
+
expect(actual).to eq(expected)
|
65
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'issue #60' do
|
70
|
+
it 'should produce unified output with correct context' do
|
71
|
+
old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp)
|
72
|
+
{
|
73
|
+
"name": "x",
|
74
|
+
"description": "hi"
|
75
|
+
}
|
76
|
+
DATA_OLD
|
77
|
+
|
78
|
+
new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp)
|
79
|
+
{
|
80
|
+
"name": "x",
|
81
|
+
"description": "lo"
|
82
|
+
}
|
83
|
+
DATA_NEW
|
84
|
+
|
85
|
+
diff = ::Diff::LCS.diff(old_data, new_data)
|
86
|
+
hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)
|
87
|
+
|
88
|
+
expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp)
|
89
|
+
@@ -1,5 +1,5 @@
|
90
|
+
{
|
91
|
+
"name": "x",
|
92
|
+
- "description": "hi"
|
93
|
+
+ "description": "lo"
|
94
|
+
}
|
95
|
+
EXPECTED
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'issue #65' do
|
100
|
+
def diff_lines(old_lines, new_lines)
|
101
|
+
file_length_difference = 0
|
102
|
+
previous_hunk = nil
|
103
|
+
output = []
|
104
|
+
|
105
|
+
Diff::LCS.diff(old_lines, new_lines).each do |piece|
|
106
|
+
hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, 3, file_length_difference)
|
107
|
+
file_length_difference = hunk.file_length_difference
|
108
|
+
maybe_contiguous_hunks = (previous_hunk.nil? || hunk.merge(previous_hunk))
|
109
|
+
|
110
|
+
output << "#{previous_hunk.diff(:unified)}\n" unless maybe_contiguous_hunks
|
111
|
+
|
112
|
+
previous_hunk = hunk
|
113
|
+
end
|
114
|
+
output << "#{previous_hunk.diff(:unified, true)}\n" unless previous_hunk.nil?
|
115
|
+
output.join
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should not misplace the new chunk' do
|
119
|
+
old_data = [
|
120
|
+
'recipe[a::default]', 'recipe[b::default]', 'recipe[c::default]',
|
121
|
+
'recipe[d::default]', 'recipe[e::default]', 'recipe[f::default]',
|
122
|
+
'recipe[g::default]', 'recipe[h::default]', 'recipe[i::default]',
|
123
|
+
'recipe[j::default]', 'recipe[k::default]', 'recipe[l::default]',
|
124
|
+
'recipe[m::default]', 'recipe[n::default]'
|
125
|
+
]
|
126
|
+
|
127
|
+
new_data = [
|
128
|
+
'recipe[a::default]', 'recipe[c::default]', 'recipe[d::default]',
|
129
|
+
'recipe[e::default]', 'recipe[f::default]', 'recipe[g::default]',
|
130
|
+
'recipe[h::default]', 'recipe[i::default]', 'recipe[j::default]',
|
131
|
+
'recipe[k::default]', 'recipe[l::default]', 'recipe[m::default]',
|
132
|
+
'recipe[n::default]', 'recipe[o::new]', 'recipe[p::new]',
|
133
|
+
'recipe[q::new]', 'recipe[r::new]'
|
134
|
+
]
|
135
|
+
|
136
|
+
expect(diff_lines(old_data, new_data)).to eq(<<-EODIFF)
|
137
|
+
@@ -1,5 +1,4 @@
|
138
|
+
recipe[a::default]
|
139
|
+
-recipe[b::default]
|
140
|
+
recipe[c::default]
|
141
|
+
recipe[d::default]
|
142
|
+
recipe[e::default]
|
143
|
+
@@ -12,3 +11,7 @@
|
144
|
+
recipe[l::default]
|
145
|
+
recipe[m::default]
|
146
|
+
recipe[n::default]
|
147
|
+
+recipe[o::new]
|
148
|
+
+recipe[p::new]
|
149
|
+
+recipe[q::new]
|
150
|
+
+recipe[r::new]
|
151
|
+
EODIFF
|
152
|
+
end
|
153
|
+
end
|
49
154
|
end
|
data/spec/lcs_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Diff::LCS::Internals,
|
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.
|
@@ -20,37 +20,37 @@ describe Diff::LCS::Internals, ".lcs" do
|
|
20
20
|
expect(x_seq2).to eq(correct_lcs)
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'returns all indexes with (hello, hello)' do
|
24
24
|
expect(Diff::LCS::Internals.lcs(hello, hello)).to \
|
25
25
|
eq((0...hello.size).to_a)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'returns all indexes with (hello_ary, hello_ary)' do
|
29
29
|
expect(Diff::LCS::Internals.lcs(hello_ary, hello_ary)).to \
|
30
30
|
eq((0...hello_ary.size).to_a)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe Diff::LCS,
|
34
|
+
describe Diff::LCS, '.LCS' do
|
35
35
|
include Diff::LCS::SpecHelper::Matchers
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'returns the correct compacted values from Diff::LCS.LCS' do
|
38
38
|
res = Diff::LCS.LCS(seq1, seq2)
|
39
39
|
expect(res).to eq(correct_lcs)
|
40
40
|
expect(res.compact).to eq(res)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'is transitive' do
|
44
44
|
res = Diff::LCS.LCS(seq2, seq1)
|
45
45
|
expect(res).to eq(correct_lcs)
|
46
46
|
expect(res.compact).to eq(res)
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'returns %W(h e l l o) with (hello, hello)' do
|
50
50
|
expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//))
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'returns hello_ary with (hello_ary, hello_ary)' do
|
54
54
|
expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary)
|
55
55
|
end
|
56
56
|
end
|