diff-lcs 1.4.4 → 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 +4 -4
- 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 +76 -6
- data/README.md +92 -0
- data/Rakefile +83 -42
- data/SECURITY.md +41 -0
- data/bin/htmldiff +4 -4
- data/docs/artistic.txt +1 -1
- data/lib/diff/lcs/array.rb +1 -1
- data/lib/diff/lcs/backports.rb +6 -2
- data/lib/diff/lcs/block.rb +4 -4
- data/lib/diff/lcs/callbacks.rb +9 -7
- data/lib/diff/lcs/change.rb +22 -22
- data/lib/diff/lcs/htmldiff.rb +26 -16
- data/lib/diff/lcs/hunk.rb +66 -45
- data/lib/diff/lcs/internals.rb +24 -20
- data/lib/diff/lcs/ldiff.rb +93 -75
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +86 -83
- data/lib/diff-lcs.rb +1 -1
- data/mise.toml +5 -0
- data/spec/change_spec.rb +50 -50
- data/spec/diff_spec.rb +14 -14
- data/spec/fixtures/123_x +2 -0
- data/spec/fixtures/456_x +2 -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.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 +20 -20
- data/spec/issues_spec.rb +76 -70
- data/spec/lcs_spec.rb +11 -11
- data/spec/ldiff_spec.rb +30 -17
- data/spec/patch_spec.rb +84 -84
- data/spec/sdiff_spec.rb +111 -109
- data/spec/spec_helper.rb +162 -161
- data/spec/traverse_balanced_spec.rb +191 -189
- data/spec/traverse_sequences_spec.rb +31 -33
- metadata +112 -63
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -118
- data/History.md +0 -319
- data/README.rdoc +0 -84
- data/autotest/discover.rb +0 -3
data/spec/diff_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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
21
|
[
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
22
|
+
["-", 0, "abcd"],
|
23
|
+
["-", 1, "efgh"],
|
24
|
+
["-", 2, "ijkl"],
|
25
|
+
["-", 3, "mnopqrstuvwxyz"]
|
26
26
|
]
|
27
27
|
]
|
28
28
|
|
@@ -30,22 +30,22 @@ describe Diff::LCS, '.diff' do
|
|
30
30
|
|
31
31
|
diff = Diff::LCS.diff([], word_sequence)
|
32
32
|
correct_diff.each do |hunk|
|
33
|
-
hunk.each
|
33
|
+
hunk.each { |change| change[0] = "+" }
|
34
34
|
end
|
35
35
|
expect(change_diff(correct_diff)).to eq(diff)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "correctly diffs 'xx' and 'xaxb'" do
|
39
|
-
left =
|
40
|
-
right =
|
39
|
+
left = "xx"
|
40
|
+
right = "xaxb"
|
41
41
|
expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it "returns an empty diff with (hello, hello)" do
|
45
45
|
expect(Diff::LCS.diff(hello, hello)).to be_empty
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "returns an empty diff with (hello_ary, hello_ary)" do
|
49
49
|
expect(Diff::LCS.diff(hello_ary, hello_ary)).to be_empty
|
50
50
|
end
|
51
51
|
end
|
data/spec/fixtures/123_x
ADDED
data/spec/fixtures/456_x
ADDED
data/spec/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
|
@@ -0,0 +1 @@
|
|
1
|
+
<new_file>: No newline at end of file
|
@@ -0,0 +1 @@
|
|
1
|
+
<new_file>: No newline at end of file
|
@@ -0,0 +1 @@
|
|
1
|
+
<old_file>: No newline at end of file
|
@@ -0,0 +1 @@
|
|
1
|
+
<old_file>: No newline at end of file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Binary files spec/fixtures/file1.bin and spec/fixtures/file2.bin differ
|
@@ -0,0 +1 @@
|
|
1
|
+
Binary files spec/fixtures/file1.bin and spec/fixtures/file2.bin differ
|
@@ -0,0 +1 @@
|
|
1
|
+
Binary files spec/fixtures/file1.bin and spec/fixtures/file2.bin differ
|
@@ -0,0 +1 @@
|
|
1
|
+
Binary files spec/fixtures/file1.bin and spec/fixtures/file2.bin differ
|
@@ -0,0 +1 @@
|
|
1
|
+
Binary files spec/fixtures/file1.bin and spec/fixtures/file2.bin differ
|
@@ -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 @@
|
|
1
|
+
1,4d
|
@@ -0,0 +1 @@
|
|
1
|
+
d1 4
|
@@ -0,0 +1,14 @@
|
|
1
|
+
*** spec/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
|
2
|
+
--- spec/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
|
3
|
+
***************
|
4
|
+
*** 1,4 ****
|
5
|
+
one
|
6
|
+
two
|
7
|
+
three
|
8
|
+
! four
|
9
|
+
--- 1,4 ----
|
10
|
+
one
|
11
|
+
two
|
12
|
+
three
|
13
|
+
! four
|
14
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
*** spec/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
|
2
|
+
--- spec/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
|
3
|
+
***************
|
4
|
+
*** 1,4 ****
|
5
|
+
one
|
6
|
+
two
|
7
|
+
three
|
8
|
+
! four
|
9
|
+
|
10
|
+
--- 1,4 ----
|
11
|
+
one
|
12
|
+
two
|
13
|
+
three
|
14
|
+
! four
|
File without changes
|
File without changes
|
@@ -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,18 +1,18 @@
|
|
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) { [
|
10
|
-
let(:new_data) { [
|
11
|
-
let(:pieces)
|
12
|
-
let(:hunk)
|
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
13
|
|
14
|
-
it
|
15
|
-
expected = <<-EXPECTED.gsub(/^\s+/,
|
14
|
+
it "produces a unified diff from the two pieces" do
|
15
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
16
16
|
@@ -1 +1 @@
|
17
17
|
-Tu a un carté avec {count} itéms
|
18
18
|
+Tu a un carte avec {count} items
|
@@ -21,8 +21,8 @@ if String.method_defined?(:encoding)
|
|
21
21
|
expect(hunk.diff(:unified)).to eq(expected)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
expected = <<-EXPECTED.gsub(/^\s+/,
|
24
|
+
it "produces a unified diff from the two pieces (last entry)" do
|
25
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
26
26
|
@@ -1 +1 @@
|
27
27
|
-Tu a un carté avec {count} itéms
|
28
28
|
+Tu a un carte avec {count} items
|
@@ -32,8 +32,8 @@ if String.method_defined?(:encoding)
|
|
32
32
|
expect(hunk.diff(:unified, true)).to eq(expected)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
expected = <<-EXPECTED.gsub(/^\s+/,
|
35
|
+
it "produces a context diff from the two pieces" do
|
36
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
37
37
|
***************
|
38
38
|
*** 1 ****
|
39
39
|
! Tu a un carté avec {count} itéms
|
@@ -44,8 +44,8 @@ if String.method_defined?(:encoding)
|
|
44
44
|
expect(hunk.diff(:context)).to eq(expected)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
expected = <<-EXPECTED.gsub(/^ +/,
|
47
|
+
it "produces an old diff from the two pieces" do
|
48
|
+
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
|
49
49
|
1c1
|
50
50
|
< Tu a un carté avec {count} itéms
|
51
51
|
---
|
@@ -56,8 +56,8 @@ if String.method_defined?(:encoding)
|
|
56
56
|
expect(hunk.diff(:old)).to eq(expected)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
expected = <<-EXPECTED.gsub(/^ +/,
|
59
|
+
it "produces a reverse ed diff from the two pieces" do
|
60
|
+
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
|
61
61
|
c1
|
62
62
|
Tu a un carte avec {count} items
|
63
63
|
.
|
@@ -67,12 +67,12 @@ if String.method_defined?(:encoding)
|
|
67
67
|
expect(hunk.diff(:reverse_ed)).to eq(expected)
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
70
|
+
context "with empty first data set" do
|
71
71
|
let(:old_data) { [] }
|
72
72
|
|
73
|
-
it
|
74
|
-
expected = <<-EXPECTED.gsub(/^\s+/,
|
75
|
-
@@ -
|
73
|
+
it "produces a unified diff" do
|
74
|
+
expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
|
75
|
+
@@ -0,0 +1 @@
|
76
76
|
+Tu a un carte avec {count} items
|
77
77
|
EXPECTED
|
78
78
|
|