diff-lcs 1.3 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/Contributing.md +86 -48
  3. data/History.md +370 -159
  4. data/License.md +6 -4
  5. data/Manifest.txt +23 -1
  6. data/README.rdoc +10 -10
  7. data/Rakefile +109 -36
  8. data/bin/htmldiff +9 -6
  9. data/bin/ldiff +4 -1
  10. data/lib/diff/lcs/array.rb +2 -2
  11. data/lib/diff/lcs/backports.rb +9 -0
  12. data/lib/diff/lcs/block.rb +5 -5
  13. data/lib/diff/lcs/callbacks.rb +22 -17
  14. data/lib/diff/lcs/change.rb +42 -49
  15. data/lib/diff/lcs/htmldiff.rb +21 -12
  16. data/lib/diff/lcs/hunk.rb +160 -73
  17. data/lib/diff/lcs/internals.rb +57 -56
  18. data/lib/diff/lcs/ldiff.rb +63 -57
  19. data/lib/diff/lcs/string.rb +1 -1
  20. data/lib/diff/lcs.rb +226 -210
  21. data/lib/diff-lcs.rb +2 -2
  22. data/spec/change_spec.rb +58 -34
  23. data/spec/diff_spec.rb +13 -9
  24. data/spec/fixtures/aX +1 -0
  25. data/spec/fixtures/bXaX +1 -0
  26. data/spec/fixtures/ldiff/output.diff +4 -0
  27. data/spec/fixtures/ldiff/output.diff-c +7 -0
  28. data/spec/fixtures/ldiff/output.diff-e +3 -0
  29. data/spec/fixtures/ldiff/output.diff-f +3 -0
  30. data/spec/fixtures/ldiff/output.diff-u +5 -0
  31. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  32. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  33. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  34. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  35. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  36. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  37. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  38. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  39. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  40. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  41. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  42. data/spec/fixtures/new-chef +4 -0
  43. data/spec/fixtures/new-chef2 +17 -0
  44. data/spec/fixtures/old-chef +4 -0
  45. data/spec/fixtures/old-chef2 +14 -0
  46. data/spec/hunk_spec.rb +48 -37
  47. data/spec/issues_spec.rb +132 -21
  48. data/spec/lcs_spec.rb +3 -3
  49. data/spec/ldiff_spec.rb +74 -32
  50. data/spec/patch_spec.rb +14 -20
  51. data/spec/sdiff_spec.rb +83 -81
  52. data/spec/spec_helper.rb +146 -91
  53. data/spec/traverse_balanced_spec.rb +138 -136
  54. data/spec/traverse_sequences_spec.rb +7 -9
  55. metadata +76 -48
  56. data/autotest/discover.rb +0 -1
data/lib/diff-lcs.rb CHANGED
@@ -1,3 +1,3 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'diff/lcs'
3
+ require "diff/lcs"
data/spec/change_spec.rb CHANGED
@@ -1,65 +1,89 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Diff::LCS::Change do
6
6
  describe "an add" do
7
- subject { described_class.new('+', 0, 'element') }
8
- it { should_not be_deleting }
9
- it { should be_adding }
10
- it { should_not be_unchanged }
11
- it { should_not be_changed }
7
+ subject { described_class.new("+", 0, "element") }
8
+ it { should_not be_deleting }
9
+ it { should be_adding }
10
+ it { should_not be_unchanged }
11
+ it { should_not be_changed }
12
12
  it { should_not be_finished_a }
13
13
  it { should_not be_finished_b }
14
14
  end
15
15
 
16
16
  describe "a delete" do
17
- subject { described_class.new('-', 0, 'element') }
18
- it { should be_deleting }
19
- it { should_not be_adding }
20
- it { should_not be_unchanged }
21
- it { should_not be_changed }
17
+ subject { described_class.new("-", 0, "element") }
18
+ it { should be_deleting }
19
+ it { should_not be_adding }
20
+ it { should_not be_unchanged }
21
+ it { should_not be_changed }
22
22
  it { should_not be_finished_a }
23
23
  it { should_not be_finished_b }
24
24
  end
25
25
 
26
26
  describe "an unchanged" do
27
- subject { described_class.new('=', 0, 'element') }
28
- it { should_not be_deleting }
29
- it { should_not be_adding }
30
- it { should be_unchanged }
31
- it { should_not be_changed }
27
+ subject { described_class.new("=", 0, "element") }
28
+ it { should_not be_deleting }
29
+ it { should_not be_adding }
30
+ it { should be_unchanged }
31
+ it { should_not be_changed }
32
32
  it { should_not be_finished_a }
33
33
  it { should_not be_finished_b }
34
34
  end
35
35
 
36
36
  describe "a changed" do
37
- subject { described_class.new('!', 0, 'element') }
38
- it { should_not be_deleting }
39
- it { should_not be_adding }
40
- it { should_not be_unchanged }
41
- it { should be_changed }
37
+ subject { described_class.new("!", 0, "element") }
38
+ it { should_not be_deleting }
39
+ it { should_not be_adding }
40
+ it { should_not be_unchanged }
41
+ it { should be_changed }
42
42
  it { should_not be_finished_a }
43
43
  it { should_not be_finished_b }
44
44
  end
45
45
 
46
46
  describe "a finished_a" do
47
- subject { described_class.new('>', 0, 'element') }
48
- it { should_not be_deleting }
49
- it { should_not be_adding }
50
- it { should_not be_unchanged }
51
- it { should_not be_changed }
52
- it { should be_finished_a }
47
+ subject { described_class.new(">", 0, "element") }
48
+ it { should_not be_deleting }
49
+ it { should_not be_adding }
50
+ it { should_not be_unchanged }
51
+ it { should_not be_changed }
52
+ it { should be_finished_a }
53
53
  it { should_not be_finished_b }
54
54
  end
55
55
 
56
56
  describe "a finished_b" do
57
- subject { described_class.new('<', 0, 'element') }
58
- it { should_not be_deleting }
59
- it { should_not be_adding }
60
- it { should_not be_unchanged }
61
- it { should_not be_changed }
57
+ subject { described_class.new("<", 0, "element") }
58
+ it { should_not be_deleting }
59
+ it { should_not be_adding }
60
+ it { should_not be_unchanged }
61
+ it { should_not be_changed }
62
62
  it { should_not be_finished_a }
63
- it { should be_finished_b }
63
+ it { should be_finished_b }
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
64
88
  end
65
89
  end
data/spec/diff_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Diff::LCS, ".diff" do
6
6
  include Diff::LCS::SpecHelper::Matchers
@@ -18,22 +18,26 @@ describe Diff::LCS, ".diff" do
18
18
  it "correctly diffs against an empty sequence" do
19
19
  diff = Diff::LCS.diff(word_sequence, [])
20
20
  correct_diff = [
21
- [ [ '-', 0, 'abcd' ],
22
- [ '-', 1, 'efgh' ],
23
- [ '-', 2, 'ijkl' ],
24
- [ '-', 3, 'mnopqrstuvwxyz' ] ]
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 { |hunk| hunk.each { |change| change[0] = '+' } }
32
+ correct_diff.each do |hunk|
33
+ hunk.each { |change| change[0] = "+" }
34
+ end
31
35
  expect(change_diff(correct_diff)).to eq(diff)
32
36
  end
33
37
 
34
38
  it "correctly diffs 'xx' and 'xaxb'" do
35
- left = 'xx'
36
- right = 'xaxb'
39
+ left = "xx"
40
+ right = "xaxb"
37
41
  expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
38
42
  end
39
43
 
data/spec/fixtures/aX ADDED
@@ -0,0 +1 @@
1
+ aX
@@ -0,0 +1 @@
1
+ bXaX
@@ -0,0 +1,4 @@
1
+ 1c1
2
+ < aX
3
+ ---
4
+ > bXaX
@@ -0,0 +1,7 @@
1
+ *** spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
+ --- spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
+ ***************
4
+ *** 1 ****
5
+ ! aX
6
+ --- 1 ----
7
+ ! bXaX
@@ -0,0 +1,3 @@
1
+ 1c
2
+ bXaX
3
+ .
@@ -0,0 +1,3 @@
1
+ c1
2
+ bXaX
3
+ .
@@ -0,0 +1,5 @@
1
+ --- spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
+ +++ spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
+ @@ -1 +1 @@
4
+ -aX
5
+ +bXaX
@@ -0,0 +1,4 @@
1
+ 3c3
2
+ < "description": "hi"
3
+ ---
4
+ > "description": "lo"
@@ -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,3 @@
1
+ 3c
2
+ "description": "lo"
3
+ .
@@ -0,0 +1,3 @@
1
+ c3
2
+ "description": "lo"
3
+ .
@@ -0,0 +1,9 @@
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
+ @@ -1,4 +1,4 @@
4
+ {
5
+ "name": "x",
6
+ - "description": "hi"
7
+ + "description": "lo"
8
+ }
9
+
@@ -0,0 +1,7 @@
1
+ 2d1
2
+ < recipe[b::default]
3
+ 14a14,17
4
+ > recipe[o::new]
5
+ > recipe[p::new]
6
+ > recipe[q::new]
7
+ > recipe[r::new]
@@ -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,7 @@
1
+ d2
2
+ a14
3
+ recipe[o::new]
4
+ recipe[p::new]
5
+ recipe[q::new]
6
+ recipe[r::new]
7
+ .
@@ -0,0 +1,7 @@
1
+ 14a
2
+ recipe[o::new]
3
+ recipe[p::new]
4
+ recipe[q::new]
5
+ recipe[r::new]
6
+ .
7
+ 2d
@@ -0,0 +1,7 @@
1
+ d2
2
+ a14
3
+ recipe[o::new]
4
+ recipe[p::new]
5
+ recipe[q::new]
6
+ recipe[r::new]
7
+ .
@@ -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,4 @@
1
+ {
2
+ "name": "x",
3
+ "description": "lo"
4
+ }
@@ -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,4 @@
1
+ {
2
+ "name": "x",
3
+ "description": "hi"
4
+ }
@@ -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,69 +1,80 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  if String.method_defined?(:encoding)
6
- require 'diff/lcs/hunk'
6
+ require "diff/lcs/hunk"
7
7
 
8
8
  describe Diff::LCS::Hunk do
9
- let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] }
10
- let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] }
11
- let(:pieces) { Diff::LCS.diff old_data, new_data }
12
- let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
13
-
14
- it 'produces a unified diff from the two pieces' do
15
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
16
- @@ -1,2 +1,2 @@
17
- -Tu avec carté {count} itém has
18
- +Tu avec carte {count} item has
19
- EOD
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
+ let(:pieces) { Diff::LCS.diff old_data, new_data }
12
+ let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
13
+
14
+ it "produces a unified diff from the two pieces" do
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 context diff from the two pieces' do
25
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
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
+
35
+ it "produces a context diff from the two pieces" do
36
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
26
37
  ***************
27
- *** 1,2 ****
28
- !Tu avec carté {count} itém has
29
- --- 1,2 ----
30
- !Tu avec carte {count} item has
31
- EOD
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
- it 'produces an old diff from the two pieces' do
37
- expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
38
- 1,2c1,2
39
- < Tu avec carté {count} itém has
47
+ it "produces an old diff from the two pieces" do
48
+ expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
49
+ 1c1
50
+ < Tu a un carté avec {count} itéms
40
51
  ---
41
- > Tu avec carte {count} item has
52
+ > Tu a un carte avec {count} items
42
53
 
43
- EOD
54
+ EXPECTED
44
55
 
45
56
  expect(hunk.diff(:old)).to eq(expected)
46
57
  end
47
58
 
48
- it 'produces a reverse ed diff from the two pieces' do
49
- expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
50
- c1,2
51
- Tu avec carte {count} item has
59
+ it "produces a reverse ed diff from the two pieces" do
60
+ expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
61
+ c1
62
+ Tu a un carte avec {count} items
52
63
  .
53
64
 
54
- EOD
65
+ EXPECTED
55
66
 
56
67
  expect(hunk.diff(:reverse_ed)).to eq(expected)
57
68
  end
58
69
 
59
- context 'with empty first data set' do
70
+ context "with empty first data set" do
60
71
  let(:old_data) { [] }
61
72
 
62
- it 'produces a unified diff' do
63
- expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
73
+ it "produces a unified diff" do
74
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
64
75
  @@ -1 +1,2 @@
65
- +Tu avec carte {count} item has
66
- EOD
76
+ +Tu a un carte avec {count} items
77
+ EXPECTED
67
78
 
68
79
  expect(hunk.diff(:unified)).to eq(expected)
69
80
  end