diff-lcs 1.5.1 → 2.0.0
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 +4 -4
- data/CHANGELOG.md +581 -0
- data/CODE_OF_CONDUCT.md +166 -0
- data/CONTRIBUTING.md +127 -0
- data/CONTRIBUTORS.md +59 -0
- data/LICENCE.md +68 -0
- data/Manifest.txt +99 -35
- data/README.md +105 -0
- data/Rakefile +107 -96
- data/SECURITY.md +36 -0
- data/integration/compare/array_diff_spec.rb +10 -0
- data/integration/compare/hash_diff_spec.rb +25 -0
- data/integration/compare/string_diff_spec.rb +10 -0
- data/integration/rspec_differ_spec.rb +26 -0
- data/integration/rspec_expectations_spec.rb +32 -0
- data/integration/runner +20 -0
- data/lib/diff/lcs/block.rb +29 -24
- data/lib/diff/lcs/callbacks.rb +240 -242
- data/lib/diff/lcs/change.rb +102 -104
- data/lib/diff/lcs/hunk.rb +110 -157
- data/lib/diff/lcs/internals.rb +92 -96
- data/lib/diff/lcs/ldiff.rb +81 -73
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +440 -466
- data/{docs → licenses}/artistic.txt +1 -1
- data/licenses/dco.txt +34 -0
- data/spec/hunk_spec.rb +33 -46
- data/spec/issues_spec.rb +32 -32
- data/spec/lcs_spec.rb +6 -6
- data/spec/ldiff_spec.rb +27 -16
- data/spec/patch_spec.rb +1 -1
- data/spec/spec_helper.rb +98 -108
- data/test/fixtures/123_x +2 -0
- data/test/fixtures/456_x +2 -0
- data/test/fixtures/empty +0 -0
- data/test/fixtures/file1.bin +0 -0
- data/test/fixtures/file2.bin +0 -0
- data/test/fixtures/four_lines +4 -0
- data/test/fixtures/four_lines_with_missing_new_line +4 -0
- data/test/fixtures/ldiff/diff.missing_new_line1-e +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line1-f +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line2-e +1 -0
- data/test/fixtures/ldiff/diff.missing_new_line2-f +1 -0
- data/test/fixtures/ldiff/error.diff.chef-e +2 -0
- data/test/fixtures/ldiff/error.diff.chef-f +2 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
- data/test/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
- data/test/fixtures/ldiff/output.diff-c +7 -0
- data/test/fixtures/ldiff/output.diff-u +5 -0
- data/test/fixtures/ldiff/output.diff.bin1 +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-c +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-e +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-f +0 -0
- data/test/fixtures/ldiff/output.diff.bin1-u +0 -0
- data/test/fixtures/ldiff/output.diff.bin2 +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-c +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-e +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-f +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-u +1 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef-c +2 -2
- data/test/fixtures/ldiff/output.diff.chef-u +9 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-c +2 -2
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-u +2 -2
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
- data/{spec/fixtures/ldiff/output.diff-e → test/fixtures/ldiff/output.diff.issue95_trailing_context-e} +1 -1
- data/{spec/fixtures/ldiff/output.diff-f → test/fixtures/ldiff/output.diff.issue95_trailing_context-f} +1 -1
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
- data/test/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
- data/test/test_block.rb +34 -0
- data/test/test_change.rb +234 -0
- data/test/test_diff.rb +53 -0
- data/test/test_helper.rb +225 -0
- data/test/test_hunk.rb +72 -0
- data/test/test_issues.rb +168 -0
- data/test/test_lcs.rb +47 -0
- data/test/test_ldiff.rb +89 -0
- data/test/test_patch.rb +362 -0
- data/test/test_sdiff.rb +167 -0
- data/test/test_traverse_balanced.rb +322 -0
- data/test/test_traverse_sequences.rb +187 -0
- metadata +211 -103
- data/.rspec +0 -1
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -121
- data/History.md +0 -431
- data/License.md +0 -41
- data/README.rdoc +0 -84
- data/bin/htmldiff +0 -35
- data/lib/diff/lcs/backports.rb +0 -9
- data/lib/diff/lcs/htmldiff.rb +0 -158
- data/spec/fixtures/ldiff/output.diff-c +0 -7
- data/spec/fixtures/ldiff/output.diff-u +0 -5
- data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-u +0 -9
- data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
- data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
- /data/{docs → licenses}/COPYING.txt +0 -0
- /data/{spec → test}/fixtures/aX +0 -0
- /data/{spec → test}/fixtures/bXaX +0 -0
- /data/{spec → test}/fixtures/ds1.csv +0 -0
- /data/{spec → test}/fixtures/ds2.csv +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2-d +0 -0
- /data/{spec → test}/fixtures/new-chef +0 -0
- /data/{spec → test}/fixtures/new-chef2 +0 -0
- /data/{spec → test}/fixtures/old-chef +0 -0
- /data/{spec → test}/fixtures/old-chef2 +0 -0
|
@@ -122,6 +122,6 @@ products derived from this software without specific prior written permission.
|
|
|
122
122
|
|
|
123
123
|
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
|
124
124
|
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
125
|
-
WARRANTIES OF
|
|
125
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
126
126
|
|
|
127
127
|
The End
|
data/licenses/dco.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Developer Certificate of Origin
|
|
2
|
+
Version 1.1
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
7
|
+
license document, but changing it is not allowed.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Developer's Certificate of Origin 1.1
|
|
11
|
+
|
|
12
|
+
By making a contribution to this project, I certify that:
|
|
13
|
+
|
|
14
|
+
(a) The contribution was created in whole or in part by me and I
|
|
15
|
+
have the right to submit it under the open source license
|
|
16
|
+
indicated in the file; or
|
|
17
|
+
|
|
18
|
+
(b) The contribution is based upon previous work that, to the best
|
|
19
|
+
of my knowledge, is covered under an appropriate open source
|
|
20
|
+
license and I have the right under that license to submit that
|
|
21
|
+
work with modifications, whether created in whole or in part
|
|
22
|
+
by me, under the same open source license (unless I am
|
|
23
|
+
permitted to submit under a different license), as indicated
|
|
24
|
+
in the file; or
|
|
25
|
+
|
|
26
|
+
(c) The contribution was provided directly to me by some other
|
|
27
|
+
person who certified (a), (b) or (c) and I have not modified
|
|
28
|
+
it.
|
|
29
|
+
|
|
30
|
+
(d) I understand and agree that this project and the contribution
|
|
31
|
+
are public and that a record of the contribution (including all
|
|
32
|
+
personal information I submit with it, including my sign-off) is
|
|
33
|
+
maintained indefinitely and may be redistributed consistent with
|
|
34
|
+
this project or the open source license(s) involved.
|
data/spec/hunk_spec.rb
CHANGED
|
@@ -2,82 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
require "diff/lcs/hunk"
|
|
5
|
+
require "diff/lcs/hunk"
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
describe Diff::LCS::Hunk do
|
|
8
|
+
let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] }
|
|
9
|
+
let(:new_data) { ["Tu a un carte avec {count} items".encode("UTF-16LE")] }
|
|
10
|
+
let(:pieces) { Diff::LCS.diff old_data, new_data }
|
|
11
|
+
let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
it "produces a unified diff from the two pieces" do
|
|
14
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
|
16
15
|
@@ -1 +1 @@
|
|
17
16
|
-Tu a un carté avec {count} itéms
|
|
18
17
|
+Tu a un carte avec {count} items
|
|
19
|
-
|
|
18
|
+
EXPECTED
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
expect(hunk.diff(:unified)).to eq(expected)
|
|
21
|
+
end
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
it "produces a unified diff from the two pieces (last entry)" do
|
|
24
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
|
26
25
|
@@ -1 +1 @@
|
|
27
26
|
-Tu a un carté avec {count} itéms
|
|
28
27
|
+Tu a un carte avec {count} items
|
|
29
28
|
\
|
|
30
|
-
|
|
29
|
+
EXPECTED
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
expect(hunk.diff(:unified, true)).to eq(expected)
|
|
32
|
+
end
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
it "produces a context diff from the two pieces" do
|
|
35
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
|
37
36
|
***************
|
|
38
37
|
*** 1 ****
|
|
39
38
|
! Tu a un carté avec {count} itéms
|
|
40
39
|
--- 1 ----
|
|
41
40
|
! Tu a un carte avec {count} items
|
|
42
|
-
|
|
41
|
+
EXPECTED
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
expect(hunk.diff(:context)).to eq(expected)
|
|
44
|
+
end
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
it "produces an old diff from the two pieces" do
|
|
47
|
+
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
|
|
49
48
|
1c1
|
|
50
49
|
< Tu a un carté avec {count} itéms
|
|
51
50
|
---
|
|
52
51
|
> Tu a un carte avec {count} items
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(hunk.diff(:old)).to eq(expected)
|
|
57
|
-
end
|
|
58
|
-
|
|
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
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
EXPECTED
|
|
53
|
+
EXPECTED
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
expect(hunk.diff(:old)).to eq(expected)
|
|
56
|
+
end
|
|
69
57
|
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
context "with empty first data set" do
|
|
59
|
+
let(:old_data) { [] }
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@@ -
|
|
61
|
+
it "produces a unified diff" do
|
|
62
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
|
63
|
+
@@ -0,0 +1 @@
|
|
76
64
|
+Tu a un carte avec {count} items
|
|
77
|
-
|
|
65
|
+
EXPECTED
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
end
|
|
67
|
+
expect(hunk.diff(:unified)).to eq(expected)
|
|
81
68
|
end
|
|
82
69
|
end
|
|
83
70
|
end
|
data/spec/issues_spec.rb
CHANGED
|
@@ -68,38 +68,6 @@ describe "Diff::LCS Issues" do
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
describe "issue #60" do
|
|
72
|
-
it "should produce unified output with correct context" do
|
|
73
|
-
# standard:disable Layout/HeredocIndentation
|
|
74
|
-
old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp)
|
|
75
|
-
{
|
|
76
|
-
"name": "x",
|
|
77
|
-
"description": "hi"
|
|
78
|
-
}
|
|
79
|
-
DATA_OLD
|
|
80
|
-
|
|
81
|
-
new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp)
|
|
82
|
-
{
|
|
83
|
-
"name": "x",
|
|
84
|
-
"description": "lo"
|
|
85
|
-
}
|
|
86
|
-
DATA_NEW
|
|
87
|
-
|
|
88
|
-
diff = ::Diff::LCS.diff(old_data, new_data)
|
|
89
|
-
hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)
|
|
90
|
-
|
|
91
|
-
expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp)
|
|
92
|
-
@@ -1,5 +1,5 @@
|
|
93
|
-
{
|
|
94
|
-
"name": "x",
|
|
95
|
-
- "description": "hi"
|
|
96
|
-
+ "description": "lo"
|
|
97
|
-
}
|
|
98
|
-
EXPECTED
|
|
99
|
-
# standard:enable Layout/HeredocIndentation
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
71
|
describe "issue #65" do
|
|
104
72
|
def diff_lines(old_lines, new_lines)
|
|
105
73
|
file_length_difference = 0
|
|
@@ -157,4 +125,36 @@ describe "Diff::LCS Issues" do
|
|
|
157
125
|
# standard:enable Layout/HeredocIndentation
|
|
158
126
|
end
|
|
159
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
|
|
160
160
|
end
|
data/spec/lcs_spec.rb
CHANGED
|
@@ -31,26 +31,26 @@ describe Diff::LCS::Internals, ".lcs" do
|
|
|
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 "returns the correct compacted values from Diff::LCS.
|
|
38
|
-
res = Diff::LCS.
|
|
37
|
+
it "returns the correct compacted values from Diff::LCS.lcs" do
|
|
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
43
|
it "is transitive" do
|
|
44
|
-
res = Diff::LCS.
|
|
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
49
|
it "returns %W(h e l l o) with (hello, hello)" do
|
|
50
|
-
expect(Diff::LCS.
|
|
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
|
|
54
|
-
expect(Diff::LCS.
|
|
54
|
+
expect(Diff::LCS.lcs(hello_ary, hello_ary)).to eq(hello_ary)
|
|
55
55
|
end
|
|
56
56
|
end
|
data/spec/ldiff_spec.rb
CHANGED
|
@@ -7,10 +7,17 @@ RSpec.describe "bin/ldiff" do
|
|
|
7
7
|
|
|
8
8
|
# standard:disable Style/HashSyntax
|
|
9
9
|
fixtures = [
|
|
10
|
-
{:name => "
|
|
11
|
-
{:name => "
|
|
12
|
-
{:name => "
|
|
13
|
-
|
|
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, "-c", "-u"]).map { |(fixture, flag)|
|
|
14
21
|
fixture = fixture.dup
|
|
15
22
|
fixture[:flag] = flag
|
|
16
23
|
fixture
|
|
@@ -20,15 +27,18 @@ RSpec.describe "bin/ldiff" do
|
|
|
20
27
|
def self.test_ldiff(fixture)
|
|
21
28
|
desc = [
|
|
22
29
|
fixture[:flag],
|
|
23
|
-
"
|
|
24
|
-
"
|
|
30
|
+
"test/fixtures/#{fixture[:left]}",
|
|
31
|
+
"test/fixtures/#{fixture[:right]}",
|
|
25
32
|
"#",
|
|
26
33
|
"=>",
|
|
27
|
-
"
|
|
34
|
+
"test/fixtures/ldiff/output.#{fixture[:name]}#{fixture[:flag]}"
|
|
28
35
|
].join(" ")
|
|
29
36
|
|
|
30
37
|
it desc do
|
|
31
|
-
|
|
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))
|
|
32
42
|
end
|
|
33
43
|
end
|
|
34
44
|
|
|
@@ -36,10 +46,13 @@ RSpec.describe "bin/ldiff" do
|
|
|
36
46
|
test_ldiff(fixture)
|
|
37
47
|
end
|
|
38
48
|
|
|
39
|
-
def read_fixture(options)
|
|
49
|
+
def read_fixture(options, mode: "output", allow_missing: false)
|
|
40
50
|
fixture = options.fetch(:name)
|
|
41
51
|
flag = options.fetch(:flag)
|
|
42
|
-
name = "
|
|
52
|
+
name = "test/fixtures/ldiff/#{mode}.#{fixture}#{flag}"
|
|
53
|
+
|
|
54
|
+
return "" if !::File.exist?(name) && allow_missing
|
|
55
|
+
|
|
43
56
|
data = IO.__send__(IO.respond_to?(:binread) ? :binread : :read, name)
|
|
44
57
|
clean_data(data, flag)
|
|
45
58
|
end
|
|
@@ -61,7 +74,7 @@ RSpec.describe "bin/ldiff" do
|
|
|
61
74
|
^
|
|
62
75
|
[-+*]{3}
|
|
63
76
|
\s*
|
|
64
|
-
|
|
77
|
+
test/fixtures/(\S+)
|
|
65
78
|
\s*
|
|
66
79
|
\d{4}-\d\d-\d\d
|
|
67
80
|
\s*
|
|
@@ -69,7 +82,7 @@ RSpec.describe "bin/ldiff" do
|
|
|
69
82
|
\s*
|
|
70
83
|
(?:[-+]\d{4}|Z)
|
|
71
84
|
}x,
|
|
72
|
-
'***
|
|
85
|
+
'*** test/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000'
|
|
73
86
|
)
|
|
74
87
|
end
|
|
75
88
|
|
|
@@ -79,11 +92,9 @@ RSpec.describe "bin/ldiff" do
|
|
|
79
92
|
right = options.fetch(:right)
|
|
80
93
|
|
|
81
94
|
stdout, stderr = capture_subprocess_io do
|
|
82
|
-
system("ruby -Ilib bin/ldiff #{flag}
|
|
95
|
+
system("ruby -Ilib bin/ldiff #{flag} test/fixtures/#{left} test/fixtures/#{right}")
|
|
83
96
|
end
|
|
84
97
|
|
|
85
|
-
|
|
86
|
-
expect(stdout).not_to be_empty
|
|
87
|
-
clean_data(stdout, flag)
|
|
98
|
+
[clean_data(stdout, flag), stderr, $?.exitstatus]
|
|
88
99
|
end
|
|
89
100
|
end
|
data/spec/patch_spec.rb
CHANGED
|
@@ -181,7 +181,7 @@ 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[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] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
185
185
|
@s2 = %w[a b c d D e f g h i j k]
|
|
186
186
|
end
|
|
187
187
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,42 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require "pathname"
|
|
5
|
-
|
|
6
|
-
require "psych" if RUBY_VERSION >= "1.9"
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path(__dir__, "../lib")
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def require_do(resource)
|
|
12
|
-
require resource
|
|
13
|
-
yield if block_given?
|
|
14
|
-
rescue LoadError
|
|
15
|
-
nil
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
|
5
|
+
require "rubygems"
|
|
6
|
+
require "simplecov"
|
|
7
|
+
require "simplecov-lcov"
|
|
19
8
|
|
|
20
|
-
|
|
21
|
-
formatters << SimpleCov::Formatter::RcovFormatter
|
|
22
|
-
}
|
|
23
|
-
require_do("simplecov-vim/formatter") {
|
|
24
|
-
formatters << SimpleCov::Formatter::VimFormatter
|
|
25
|
-
}
|
|
26
|
-
require_do("simplecov-sublime-ruby-coverage") {
|
|
27
|
-
formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter
|
|
28
|
-
}
|
|
9
|
+
require "diff/lcs"
|
|
29
10
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
|
12
|
+
config.report_with_single_file = true
|
|
13
|
+
config.lcov_file_name = "lcov.info"
|
|
33
14
|
end
|
|
34
15
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
SimpleCov.start "test_frameworks" do
|
|
17
|
+
enable_coverage :branch
|
|
18
|
+
primary_coverage :branch
|
|
19
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
20
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
21
|
+
SimpleCov::Formatter::LcovFormatter,
|
|
22
|
+
SimpleCov::Formatter::SimpleFormatter
|
|
23
|
+
])
|
|
24
|
+
end
|
|
40
25
|
|
|
41
26
|
module CaptureSubprocessIO
|
|
42
27
|
def _synchronize
|
|
@@ -71,8 +56,6 @@ module CaptureSubprocessIO
|
|
|
71
56
|
private :_capture_subprocess_io
|
|
72
57
|
end
|
|
73
58
|
|
|
74
|
-
require "diff-lcs"
|
|
75
|
-
|
|
76
59
|
module Diff::LCS::SpecHelper
|
|
77
60
|
def hello
|
|
78
61
|
"hello"
|
|
@@ -250,100 +233,107 @@ module Diff::LCS::SpecHelper
|
|
|
250
233
|
new_result
|
|
251
234
|
end
|
|
252
235
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
attr_reader :matched_b
|
|
258
|
-
attr_reader :discards_a
|
|
259
|
-
attr_reader :discards_b
|
|
260
|
-
attr_reader :done_a
|
|
261
|
-
attr_reader :done_b
|
|
262
|
-
|
|
263
|
-
def reset
|
|
264
|
-
@matched_a = []
|
|
265
|
-
@matched_b = []
|
|
266
|
-
@discards_a = []
|
|
267
|
-
@discards_b = []
|
|
268
|
-
@done_a = []
|
|
269
|
-
@done_b = []
|
|
270
|
-
end
|
|
236
|
+
class SimpleCallback
|
|
237
|
+
def initialize
|
|
238
|
+
reset
|
|
239
|
+
end
|
|
271
240
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
241
|
+
attr_reader :matched_a
|
|
242
|
+
attr_reader :matched_b
|
|
243
|
+
attr_reader :discards_a
|
|
244
|
+
attr_reader :discards_b
|
|
245
|
+
attr_reader :done_a
|
|
246
|
+
attr_reader :done_b
|
|
247
|
+
|
|
248
|
+
def reset
|
|
249
|
+
@matched_a = []
|
|
250
|
+
@matched_b = []
|
|
251
|
+
@discards_a = []
|
|
252
|
+
@discards_b = []
|
|
253
|
+
@done_a = []
|
|
254
|
+
@done_b = []
|
|
255
|
+
self
|
|
256
|
+
end
|
|
276
257
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
258
|
+
def match(event)
|
|
259
|
+
@matched_a << event.old_element
|
|
260
|
+
@matched_b << event.new_element
|
|
261
|
+
end
|
|
280
262
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
263
|
+
def discard_b(event)
|
|
264
|
+
@discards_b << event.new_element
|
|
265
|
+
end
|
|
284
266
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
event.new_element, event.new_position
|
|
289
|
-
]
|
|
290
|
-
end
|
|
267
|
+
def discard_a(event)
|
|
268
|
+
@discards_a << event.old_element
|
|
269
|
+
end
|
|
291
270
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
271
|
+
def finished_a(event)
|
|
272
|
+
@done_a << [
|
|
273
|
+
event.old_element, event.old_position,
|
|
274
|
+
event.new_element, event.new_position
|
|
275
|
+
]
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def finished_b(event)
|
|
279
|
+
@done_b << [
|
|
280
|
+
event.old_element, event.old_position,
|
|
281
|
+
event.new_element, event.new_position
|
|
282
|
+
]
|
|
298
283
|
end
|
|
299
|
-
|
|
300
|
-
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def simple_callback
|
|
287
|
+
SimpleCallback.new
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
class SimpleCallbackNoFinishers < SimpleCallback
|
|
291
|
+
undef :finished_a
|
|
292
|
+
undef :finished_b
|
|
301
293
|
end
|
|
302
294
|
|
|
303
295
|
def simple_callback_no_finishers
|
|
304
|
-
|
|
305
|
-
class << simple
|
|
306
|
-
undef :finished_a
|
|
307
|
-
undef :finished_b
|
|
308
|
-
end
|
|
309
|
-
simple
|
|
296
|
+
SimpleCallbackNoFinishers.new
|
|
310
297
|
end
|
|
311
298
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
299
|
+
class BalancedCallback
|
|
300
|
+
def initialize
|
|
301
|
+
reset
|
|
302
|
+
end
|
|
316
303
|
|
|
317
|
-
|
|
318
|
-
@result = []
|
|
319
|
-
end
|
|
304
|
+
attr_reader :result
|
|
320
305
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
306
|
+
def reset
|
|
307
|
+
@result = []
|
|
308
|
+
end
|
|
324
309
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
310
|
+
def match(event)
|
|
311
|
+
@result << ["=", event.old_position, event.new_position]
|
|
312
|
+
end
|
|
328
313
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
314
|
+
def discard_a(event)
|
|
315
|
+
@result << ["<", event.old_position, event.new_position]
|
|
316
|
+
end
|
|
332
317
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
318
|
+
def discard_b(event)
|
|
319
|
+
@result << [">", event.old_position, event.new_position]
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def change(event)
|
|
323
|
+
@result << ["!", event.old_position, event.new_position]
|
|
336
324
|
end
|
|
337
|
-
|
|
338
|
-
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def balanced_callback
|
|
328
|
+
BalancedCallback.new
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
class BalancedCallbackNoChange < BalancedCallback
|
|
332
|
+
undef :change
|
|
339
333
|
end
|
|
340
334
|
|
|
341
335
|
def balanced_callback_no_change
|
|
342
|
-
|
|
343
|
-
class << balanced
|
|
344
|
-
undef :change
|
|
345
|
-
end
|
|
346
|
-
balanced
|
|
336
|
+
BalancedCallbackNoChange.new
|
|
347
337
|
end
|
|
348
338
|
|
|
349
339
|
module Matchers
|
data/test/fixtures/123_x
ADDED
data/test/fixtures/456_x
ADDED
data/test/fixtures/empty
ADDED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
No newline at end of file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
No newline at end of file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
No newline at end of file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
No newline at end of file
|