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
data/lib/diff-lcs.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "diff/lcs"
|
data/mise.toml
ADDED
data/spec/change_spec.rb
CHANGED
|
@@ -1,65 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
5
|
describe Diff::LCS::Change do
|
|
6
6
|
describe "an add" do
|
|
7
|
-
subject { described_class.new(
|
|
8
|
-
it { should_not be_deleting
|
|
9
|
-
it { should
|
|
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(
|
|
18
|
-
it { should
|
|
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(
|
|
28
|
-
it { should_not be_deleting
|
|
29
|
-
it { should_not be_adding
|
|
30
|
-
it { should
|
|
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(
|
|
38
|
-
it { should_not be_deleting
|
|
39
|
-
it { should_not be_adding
|
|
40
|
-
it { should_not be_unchanged
|
|
41
|
-
it { should
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
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
|
-
[
|
|
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 { |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 =
|
|
36
|
-
right =
|
|
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/123_x
ADDED
data/spec/fixtures/456_x
ADDED
data/spec/fixtures/aX
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aX
|
data/spec/fixtures/bXaX
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bXaX
|
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
|