diff-lcs 1.3 → 1.6.2
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +518 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/CONTRIBUTORS.md +49 -0
- data/{License.md → LICENCE.md} +21 -20
- data/Manifest.txt +84 -6
- data/README.md +92 -0
- data/Rakefile +104 -46
- data/SECURITY.md +41 -0
- data/bin/htmldiff +9 -6
- data/bin/ldiff +4 -1
- data/docs/artistic.txt +1 -1
- data/lib/diff/lcs/array.rb +2 -2
- data/lib/diff/lcs/backports.rb +13 -0
- data/lib/diff/lcs/block.rb +5 -5
- data/lib/diff/lcs/callbacks.rb +22 -17
- data/lib/diff/lcs/change.rb +44 -51
- data/lib/diff/lcs/htmldiff.rb +25 -14
- data/lib/diff/lcs/hunk.rb +174 -71
- data/lib/diff/lcs/internals.rb +57 -56
- data/lib/diff/lcs/ldiff.rb +101 -79
- data/lib/diff/lcs/string.rb +1 -1
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +229 -212
- data/lib/diff-lcs.rb +2 -2
- data/mise.toml +5 -0
- data/spec/change_spec.rb +58 -34
- data/spec/diff_spec.rb +13 -9
- data/spec/fixtures/123_x +2 -0
- data/spec/fixtures/456_x +2 -0
- data/spec/fixtures/aX +1 -0
- data/spec/fixtures/bXaX +1 -0
- data/spec/fixtures/empty +0 -0
- data/spec/fixtures/file1.bin +0 -0
- data/spec/fixtures/file2.bin +0 -0
- data/spec/fixtures/four_lines +4 -0
- data/spec/fixtures/four_lines_with_missing_new_line +4 -0
- data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
- data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
- data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +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.bin1 +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
- data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-u +1 -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/ldiff/output.diff.empty.vs.four_lines +5 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -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 +49 -38
- data/spec/issues_spec.rb +132 -21
- data/spec/lcs_spec.rb +3 -3
- data/spec/ldiff_spec.rb +83 -30
- data/spec/patch_spec.rb +14 -20
- data/spec/sdiff_spec.rb +83 -81
- data/spec/spec_helper.rb +220 -165
- data/spec/traverse_balanced_spec.rb +138 -136
- data/spec/traverse_sequences_spec.rb +7 -9
- metadata +127 -77
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -83
- data/History.md +0 -220
- data/README.rdoc +0 -84
- data/autotest/discover.rb +0 -1
|
@@ -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,69 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
5
|
if String.method_defined?(:encoding)
|
|
6
|
-
require
|
|
6
|
+
require "diff/lcs/hunk"
|
|
7
7
|
|
|
8
8
|
describe Diff::LCS::Hunk do
|
|
9
|
-
let(:old_data) { ["Tu
|
|
10
|
-
let(:new_data) { ["Tu
|
|
11
|
-
let(:pieces)
|
|
12
|
-
let(:hunk)
|
|
13
|
-
|
|
14
|
-
it
|
|
15
|
-
expected =
|
|
16
|
-
@@ -1
|
|
17
|
-
-Tu
|
|
18
|
-
+Tu
|
|
19
|
-
|
|
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
|
|
25
|
-
expected =
|
|
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
|
|
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
|
-
it
|
|
37
|
-
expected =
|
|
38
|
-
|
|
39
|
-
< Tu
|
|
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
|
|
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
|
-
it
|
|
49
|
-
expected =
|
|
50
|
-
c1
|
|
51
|
-
Tu
|
|
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
|
-
|
|
65
|
+
EXPECTED
|
|
55
66
|
|
|
56
67
|
expect(hunk.diff(:reverse_ed)).to eq(expected)
|
|
57
68
|
end
|
|
58
69
|
|
|
59
|
-
context
|
|
70
|
+
context "with empty first data set" do
|
|
60
71
|
let(:old_data) { [] }
|
|
61
72
|
|
|
62
|
-
it
|
|
63
|
-
expected =
|
|
64
|
-
@@ -
|
|
65
|
-
+Tu
|
|
66
|
-
|
|
73
|
+
it "produces a unified diff" do
|
|
74
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
|
75
|
+
@@ -0,0 +1 @@
|
|
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,49 +1,160 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "diff/lcs/hunk"
|
|
4
5
|
|
|
5
6
|
describe "Diff::LCS Issues" do
|
|
6
7
|
include Diff::LCS::SpecHelper::Matchers
|
|
7
8
|
|
|
8
|
-
describe
|
|
9
|
-
shared_examples
|
|
9
|
+
describe "issue #1" do
|
|
10
|
+
shared_examples "handles simple diffs" do |s1, s2, forward_diff|
|
|
10
11
|
before do
|
|
11
12
|
@diff_s1_s2 = Diff::LCS.diff(s1, s2)
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
it
|
|
15
|
+
it "creates the correct diff" do
|
|
15
16
|
expect(change_diff(forward_diff)).to eq(@diff_s1_s2)
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
it
|
|
19
|
+
it "creates the correct patch s1->s2" do
|
|
19
20
|
expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
it
|
|
23
|
+
it "creates the correct patch s2->s1" do
|
|
23
24
|
expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1)
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
describe
|
|
28
|
-
it_has_behavior
|
|
29
|
-
[
|
|
30
|
-
[
|
|
28
|
+
describe "string" do
|
|
29
|
+
it_has_behavior "handles simple diffs", "aX", "bXaX", [
|
|
30
|
+
[
|
|
31
|
+
["+", 0, "b"],
|
|
32
|
+
["+", 1, "X"]
|
|
33
|
+
]
|
|
31
34
|
]
|
|
32
|
-
it_has_behavior
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
+
it_has_behavior "handles simple diffs", "bXaX", "aX", [
|
|
36
|
+
[
|
|
37
|
+
["-", 0, "b"],
|
|
38
|
+
["-", 1, "X"]
|
|
39
|
+
]
|
|
35
40
|
]
|
|
36
41
|
end
|
|
37
42
|
|
|
38
|
-
describe
|
|
39
|
-
it_has_behavior
|
|
40
|
-
[
|
|
41
|
-
[
|
|
43
|
+
describe "array" do
|
|
44
|
+
it_has_behavior "handles simple diffs", %w[a X], %w[b X a X], [
|
|
45
|
+
[
|
|
46
|
+
["+", 0, "b"],
|
|
47
|
+
["+", 1, "X"]
|
|
48
|
+
]
|
|
42
49
|
]
|
|
43
|
-
it_has_behavior
|
|
44
|
-
[
|
|
45
|
-
[
|
|
50
|
+
it_has_behavior "handles simple diffs", %w[b X a X], %w[a X], [
|
|
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
|
+
# standard:disable Style/HashSyntax
|
|
62
|
+
expect {
|
|
63
|
+
actual = {:category => "app.rack.request"}
|
|
64
|
+
expected = {:category => "rack.middleware", :title => "Anonymous Middleware"}
|
|
65
|
+
expect(actual).to eq(expected)
|
|
66
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
|
67
|
+
# standard:enable Style/HashSyntax
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "issue #65" do
|
|
72
|
+
def diff_lines(old_lines, new_lines)
|
|
73
|
+
file_length_difference = 0
|
|
74
|
+
previous_hunk = nil
|
|
75
|
+
output = []
|
|
76
|
+
|
|
77
|
+
Diff::LCS.diff(old_lines, new_lines).each do |piece|
|
|
78
|
+
hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, 3, file_length_difference)
|
|
79
|
+
file_length_difference = hunk.file_length_difference
|
|
80
|
+
maybe_contiguous_hunks = previous_hunk.nil? || hunk.merge(previous_hunk)
|
|
81
|
+
|
|
82
|
+
output << "#{previous_hunk.diff(:unified)}\n" unless maybe_contiguous_hunks
|
|
83
|
+
|
|
84
|
+
previous_hunk = hunk
|
|
85
|
+
end
|
|
86
|
+
output << "#{previous_hunk.diff(:unified, true)}\n" unless previous_hunk.nil?
|
|
87
|
+
output.join
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should not misplace the new chunk" do
|
|
91
|
+
old_data = [
|
|
92
|
+
"recipe[a::default]", "recipe[b::default]", "recipe[c::default]",
|
|
93
|
+
"recipe[d::default]", "recipe[e::default]", "recipe[f::default]",
|
|
94
|
+
"recipe[g::default]", "recipe[h::default]", "recipe[i::default]",
|
|
95
|
+
"recipe[j::default]", "recipe[k::default]", "recipe[l::default]",
|
|
96
|
+
"recipe[m::default]", "recipe[n::default]"
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
new_data = [
|
|
100
|
+
"recipe[a::default]", "recipe[c::default]", "recipe[d::default]",
|
|
101
|
+
"recipe[e::default]", "recipe[f::default]", "recipe[g::default]",
|
|
102
|
+
"recipe[h::default]", "recipe[i::default]", "recipe[j::default]",
|
|
103
|
+
"recipe[k::default]", "recipe[l::default]", "recipe[m::default]",
|
|
104
|
+
"recipe[n::default]", "recipe[o::new]", "recipe[p::new]",
|
|
105
|
+
"recipe[q::new]", "recipe[r::new]"
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
# standard:disable Layout/HeredocIndentation
|
|
109
|
+
expect(diff_lines(old_data, new_data)).to eq(<<-EODIFF)
|
|
110
|
+
@@ -1,5 +1,4 @@
|
|
111
|
+
recipe[a::default]
|
|
112
|
+
-recipe[b::default]
|
|
113
|
+
recipe[c::default]
|
|
114
|
+
recipe[d::default]
|
|
115
|
+
recipe[e::default]
|
|
116
|
+
@@ -12,3 +11,7 @@
|
|
117
|
+
recipe[l::default]
|
|
118
|
+
recipe[m::default]
|
|
119
|
+
recipe[n::default]
|
|
120
|
+
+recipe[o::new]
|
|
121
|
+
+recipe[p::new]
|
|
122
|
+
+recipe[q::new]
|
|
123
|
+
+recipe[r::new]
|
|
124
|
+
EODIFF
|
|
125
|
+
# standard:enable Layout/HeredocIndentation
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe "issue #107 (replaces issue #60)" do
|
|
130
|
+
it "should produce unified output with correct context" do
|
|
131
|
+
# standard:disable Layout/HeredocIndentation
|
|
132
|
+
old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp)
|
|
133
|
+
{
|
|
134
|
+
"name": "x",
|
|
135
|
+
"description": "hi"
|
|
136
|
+
}
|
|
137
|
+
DATA_OLD
|
|
138
|
+
|
|
139
|
+
new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp)
|
|
140
|
+
{
|
|
141
|
+
"name": "x",
|
|
142
|
+
"description": "lo"
|
|
143
|
+
}
|
|
144
|
+
DATA_NEW
|
|
145
|
+
|
|
146
|
+
diff = ::Diff::LCS.diff(old_data, new_data)
|
|
147
|
+
hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)
|
|
148
|
+
|
|
149
|
+
expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp)
|
|
150
|
+
@@ -1,4 +1,4 @@
|
|
151
|
+
{
|
|
152
|
+
"name": "x",
|
|
153
|
+
- "description": "hi"
|
|
154
|
+
+ "description": "lo"
|
|
155
|
+
}
|
|
156
|
+
EXPECTED
|
|
157
|
+
# standard:enable Layout/HeredocIndentation
|
|
158
|
+
end
|
|
159
|
+
end
|
|
49
160
|
end
|
data/spec/lcs_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
5
|
describe Diff::LCS::Internals, ".lcs" do
|
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
|
@@ -47,7 +47,7 @@ describe Diff::LCS, ".LCS" do
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "returns %W(h e l l o) with (hello, hello)" do
|
|
50
|
-
expect(Diff::LCS.LCS(hello, hello)).to eq(hello.
|
|
50
|
+
expect(Diff::LCS.LCS(hello, hello)).to eq(hello.chars)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "returns hello_ary with (hello_ary, hello_ary)" do
|
data/spec/ldiff_spec.rb
CHANGED
|
@@ -1,47 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
describe "
|
|
6
|
-
include
|
|
5
|
+
RSpec.describe "bin/ldiff" do
|
|
6
|
+
include CaptureSubprocessIO
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
# standard:disable Style/HashSyntax
|
|
9
|
+
fixtures = [
|
|
10
|
+
{:name => "diff", :left => "aX", :right => "bXaX", :diff => 1},
|
|
11
|
+
{:name => "diff.missing_new_line1", :left => "four_lines", :right => "four_lines_with_missing_new_line", :diff => 1},
|
|
12
|
+
{:name => "diff.missing_new_line2", :left => "four_lines_with_missing_new_line", :right => "four_lines", :diff => 1},
|
|
13
|
+
{:name => "diff.issue95_trailing_context", :left => "123_x", :right => "456_x", :diff => 1},
|
|
14
|
+
{:name => "diff.four_lines.vs.empty", :left => "four_lines", :right => "empty", :diff => 1},
|
|
15
|
+
{:name => "diff.empty.vs.four_lines", :left => "empty", :right => "four_lines", :diff => 1},
|
|
16
|
+
{:name => "diff.bin1", :left => "file1.bin", :right => "file1.bin", :diff => 0},
|
|
17
|
+
{:name => "diff.bin2", :left => "file1.bin", :right => "file2.bin", :diff => 1},
|
|
18
|
+
{:name => "diff.chef", :left => "old-chef", :right => "new-chef", :diff => 1},
|
|
19
|
+
{:name => "diff.chef2", :left => "old-chef2", :right => "new-chef2", :diff => 1}
|
|
20
|
+
].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)|
|
|
21
|
+
fixture = fixture.dup
|
|
22
|
+
fixture[:flag] = flag
|
|
23
|
+
fixture
|
|
24
|
+
}
|
|
25
|
+
# standard:enable Style/HashSyntax
|
|
26
|
+
|
|
27
|
+
def self.test_ldiff(fixture)
|
|
28
|
+
desc = [
|
|
29
|
+
fixture[:flag],
|
|
30
|
+
"spec/fixtures/#{fixture[:left]}",
|
|
31
|
+
"spec/fixtures/#{fixture[:right]}",
|
|
32
|
+
"#",
|
|
33
|
+
"=>",
|
|
34
|
+
"spec/fixtures/ldiff/output.#{fixture[:name]}#{fixture[:flag]}"
|
|
35
|
+
].join(" ")
|
|
36
|
+
|
|
37
|
+
it desc do
|
|
38
|
+
stdout, stderr, status = run_ldiff(fixture)
|
|
39
|
+
expect(status).to eq(fixture[:diff])
|
|
40
|
+
expect(stderr).to eq(read_fixture(fixture, mode: "error", allow_missing: true))
|
|
41
|
+
expect(stdout).to eq(read_fixture(fixture, mode: "output", allow_missing: false))
|
|
42
|
+
end
|
|
11
43
|
end
|
|
12
44
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1)
|
|
45
|
+
fixtures.each do |fixture|
|
|
46
|
+
test_ldiff(fixture)
|
|
16
47
|
end
|
|
17
48
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[ '-', 1, 'efgh' ],
|
|
23
|
-
[ '-', 2, 'ijkl' ],
|
|
24
|
-
[ '-', 3, 'mnopqrstuvwxyz' ] ]
|
|
25
|
-
]
|
|
49
|
+
def read_fixture(options, mode: "output", allow_missing: false)
|
|
50
|
+
fixture = options.fetch(:name)
|
|
51
|
+
flag = options.fetch(:flag)
|
|
52
|
+
name = "spec/fixtures/ldiff/#{mode}.#{fixture}#{flag}"
|
|
26
53
|
|
|
27
|
-
|
|
54
|
+
return "" if !::File.exist?(name) && allow_missing
|
|
28
55
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
expect(change_diff(correct_diff)).to eq(diff)
|
|
56
|
+
data = IO.__send__(IO.respond_to?(:binread) ? :binread : :read, name)
|
|
57
|
+
clean_data(data, flag)
|
|
32
58
|
end
|
|
33
59
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
60
|
+
def clean_data(data, flag)
|
|
61
|
+
data =
|
|
62
|
+
case flag
|
|
63
|
+
when "-c", "-u"
|
|
64
|
+
clean_output_timestamp(data)
|
|
65
|
+
else
|
|
66
|
+
data
|
|
67
|
+
end
|
|
68
|
+
data.gsub(/\r\n?/, "\n")
|
|
38
69
|
end
|
|
39
70
|
|
|
40
|
-
|
|
41
|
-
|
|
71
|
+
def clean_output_timestamp(data)
|
|
72
|
+
data.gsub(
|
|
73
|
+
%r{
|
|
74
|
+
^
|
|
75
|
+
[-+*]{3}
|
|
76
|
+
\s*
|
|
77
|
+
spec/fixtures/(\S+)
|
|
78
|
+
\s*
|
|
79
|
+
\d{4}-\d\d-\d\d
|
|
80
|
+
\s*
|
|
81
|
+
\d\d:\d\d:\d\d(?:\.\d+)
|
|
82
|
+
\s*
|
|
83
|
+
(?:[-+]\d{4}|Z)
|
|
84
|
+
}x,
|
|
85
|
+
'*** spec/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000'
|
|
86
|
+
)
|
|
42
87
|
end
|
|
43
88
|
|
|
44
|
-
|
|
45
|
-
|
|
89
|
+
def run_ldiff(options)
|
|
90
|
+
flag = options.fetch(:flag)
|
|
91
|
+
left = options.fetch(:left)
|
|
92
|
+
right = options.fetch(:right)
|
|
93
|
+
|
|
94
|
+
stdout, stderr = capture_subprocess_io do
|
|
95
|
+
system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/fixtures/#{right}")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
[clean_data(stdout, flag), stderr, $?.exitstatus]
|
|
46
99
|
end
|
|
47
100
|
end
|
data/spec/patch_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
5
|
describe "Diff::LCS.patch" do
|
|
6
6
|
include Diff::LCS::SpecHelper::Matchers
|
|
@@ -29,12 +29,12 @@ describe "Diff::LCS.patch" 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
|
|
32
|
+
expect(Diff::LCS.patch(hello, diff)).to eq(hello)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
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
|
|
|
@@ -104,11 +104,11 @@ describe "Diff::LCS.patch" do
|
|
|
104
104
|
describe "using a Diff::LCS.sdiff patchset" do
|
|
105
105
|
describe "an empty patchset returns the source" do
|
|
106
106
|
it "works on a string (hello)" do
|
|
107
|
-
expect(Diff::LCS
|
|
107
|
+
expect(Diff::LCS.patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
it "works on an array %W(h e l l o)" do
|
|
111
|
-
expect(Diff::LCS
|
|
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
|
|
|
@@ -181,8 +181,8 @@ describe "Diff::LCS.patch" do
|
|
|
181
181
|
# above.
|
|
182
182
|
describe "fix bug 891: patchsets do not contain the last equal part" do
|
|
183
183
|
before :each do
|
|
184
|
-
@s1 = %w
|
|
185
|
-
@s2 = %w
|
|
184
|
+
@s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
185
|
+
@s2 = %w[a b c d D e f g h i j k]
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
describe "using Diff::LCS.diff with default diff callbacks" do
|
|
@@ -225,10 +225,8 @@ describe "Diff::LCS.patch" do
|
|
|
225
225
|
|
|
226
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
232
|
it "autodiscovers s1 to s2 patches" do
|
|
@@ -265,10 +263,8 @@ describe "Diff::LCS.patch" do
|
|
|
265
263
|
|
|
266
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
270
|
it "autodiscovers s1 to s2 patches" do
|
|
@@ -343,10 +339,8 @@ describe "Diff::LCS.patch" do
|
|
|
343
339
|
|
|
344
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
346
|
it "autodiscovers s1 to s2 patches" do
|