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.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +518 -0
  3. data/CODE_OF_CONDUCT.md +128 -0
  4. data/CONTRIBUTING.md +71 -0
  5. data/CONTRIBUTORS.md +49 -0
  6. data/{License.md → LICENCE.md} +21 -20
  7. data/Manifest.txt +84 -6
  8. data/README.md +92 -0
  9. data/Rakefile +104 -46
  10. data/SECURITY.md +41 -0
  11. data/bin/htmldiff +9 -6
  12. data/bin/ldiff +4 -1
  13. data/docs/artistic.txt +1 -1
  14. data/lib/diff/lcs/array.rb +2 -2
  15. data/lib/diff/lcs/backports.rb +13 -0
  16. data/lib/diff/lcs/block.rb +5 -5
  17. data/lib/diff/lcs/callbacks.rb +22 -17
  18. data/lib/diff/lcs/change.rb +44 -51
  19. data/lib/diff/lcs/htmldiff.rb +25 -14
  20. data/lib/diff/lcs/hunk.rb +174 -71
  21. data/lib/diff/lcs/internals.rb +57 -56
  22. data/lib/diff/lcs/ldiff.rb +101 -79
  23. data/lib/diff/lcs/string.rb +1 -1
  24. data/lib/diff/lcs/version.rb +7 -0
  25. data/lib/diff/lcs.rb +229 -212
  26. data/lib/diff-lcs.rb +2 -2
  27. data/mise.toml +5 -0
  28. data/spec/change_spec.rb +58 -34
  29. data/spec/diff_spec.rb +13 -9
  30. data/spec/fixtures/123_x +2 -0
  31. data/spec/fixtures/456_x +2 -0
  32. data/spec/fixtures/aX +1 -0
  33. data/spec/fixtures/bXaX +1 -0
  34. data/spec/fixtures/empty +0 -0
  35. data/spec/fixtures/file1.bin +0 -0
  36. data/spec/fixtures/file2.bin +0 -0
  37. data/spec/fixtures/four_lines +4 -0
  38. data/spec/fixtures/four_lines_with_missing_new_line +4 -0
  39. data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  40. data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  41. data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  42. data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  43. data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
  44. data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
  45. data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  46. data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  47. data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  48. data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  49. data/spec/fixtures/ldiff/output.diff +4 -0
  50. data/spec/fixtures/ldiff/output.diff-c +7 -0
  51. data/spec/fixtures/ldiff/output.diff-e +3 -0
  52. data/spec/fixtures/ldiff/output.diff-f +3 -0
  53. data/spec/fixtures/ldiff/output.diff-u +5 -0
  54. data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
  55. data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
  56. data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
  57. data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
  58. data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
  59. data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
  60. data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
  61. data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
  62. data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
  63. data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
  64. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  65. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  66. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  67. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  68. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  69. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  70. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  71. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  72. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  73. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  74. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  75. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  76. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  77. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  78. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  79. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  80. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  81. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  82. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  83. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  84. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  85. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  86. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  87. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
  88. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
  89. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  90. data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  91. data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  92. data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  93. data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  94. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  95. data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  96. data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  97. data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  98. data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  99. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  100. data/spec/fixtures/new-chef +4 -0
  101. data/spec/fixtures/new-chef2 +17 -0
  102. data/spec/fixtures/old-chef +4 -0
  103. data/spec/fixtures/old-chef2 +14 -0
  104. data/spec/hunk_spec.rb +49 -38
  105. data/spec/issues_spec.rb +132 -21
  106. data/spec/lcs_spec.rb +3 -3
  107. data/spec/ldiff_spec.rb +83 -30
  108. data/spec/patch_spec.rb +14 -20
  109. data/spec/sdiff_spec.rb +83 -81
  110. data/spec/spec_helper.rb +220 -165
  111. data/spec/traverse_balanced_spec.rb +138 -136
  112. data/spec/traverse_sequences_spec.rb +7 -9
  113. metadata +127 -77
  114. data/Code-of-Conduct.md +0 -74
  115. data/Contributing.md +0 -83
  116. data/History.md +0 -220
  117. data/README.rdoc +0 -84
  118. data/autotest/discover.rb +0 -1
data/spec/sdiff_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.sdiff" do
6
6
  include Diff::LCS::SpecHelper::Matchers
@@ -24,32 +24,34 @@ describe "Diff::LCS.sdiff" do
24
24
  end
25
25
 
26
26
  describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do
27
- let(:s1) { %w(abc def yyy xxx ghi jkl) }
28
- let(:s2) { %w(abc dxf xxx ghi jkl) }
27
+ let(:s1) { %w[abc def yyy xxx ghi jkl] }
28
+ let(:s2) { %w[abc dxf xxx ghi jkl] }
29
29
  let(:result) {
30
+ # standard:disable Layout/ExtraSpacing
30
31
  [
31
- [ '=', [ 0, 'abc' ], [ 0, 'abc' ] ],
32
- [ '!', [ 1, 'def' ], [ 1, 'dxf' ] ],
33
- [ '-', [ 2, 'yyy' ], [ 2, nil ] ],
34
- [ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ],
35
- [ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ],
36
- [ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ]
32
+ ["=", [0, "abc"], [0, "abc"]],
33
+ ["!", [1, "def"], [1, "dxf"]],
34
+ ["-", [2, "yyy"], [2, nil]],
35
+ ["=", [3, "xxx"], [2, "xxx"]],
36
+ ["=", [4, "ghi"], [3, "ghi"]],
37
+ ["=", [5, "jkl"], [4, "jkl"]]
37
38
  ]
39
+ # standard:enable Layout/ExtraSpacing
38
40
  }
39
41
 
40
42
  it_has_behavior "compare sequences correctly"
41
43
  end
42
44
 
43
45
  describe "using %w(a b c d e) & %w(a e)" do
44
- let(:s1) { %w(a b c d e) }
45
- let(:s2) { %w(a e) }
46
+ let(:s1) { %w[a b c d e] }
47
+ let(:s2) { %w[a e] }
46
48
  let(:result) {
47
49
  [
48
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
49
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
50
- [ '-', [ 2, 'c' ], [ 1, nil ] ],
51
- [ '-', [ 3, 'd' ], [ 1, nil ] ],
52
- [ '=', [ 4, 'e' ], [ 1, 'e' ] ]
50
+ ["=", [0, "a"], [0, "a"]],
51
+ ["-", [1, "b"], [1, nil]],
52
+ ["-", [2, "c"], [1, nil]],
53
+ ["-", [3, "d"], [1, nil]],
54
+ ["=", [4, "e"], [1, "e"]]
53
55
  ]
54
56
  }
55
57
 
@@ -57,15 +59,15 @@ describe "Diff::LCS.sdiff" do
57
59
  end
58
60
 
59
61
  describe "using %w(a e) & %w(a b c d e)" do
60
- let(:s1) { %w(a e) }
61
- let(:s2) { %w(a b c d e) }
62
+ let(:s1) { %w[a e] }
63
+ let(:s2) { %w[a b c d e] }
62
64
  let(:result) {
63
65
  [
64
- [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
65
- [ '+', [ 1, nil ], [ 1, 'b' ] ],
66
- [ '+', [ 1, nil ], [ 2, 'c' ] ],
67
- [ '+', [ 1, nil ], [ 3, 'd' ] ],
68
- [ '=', [ 1, 'e' ], [ 4, 'e' ] ]
66
+ ["=", [0, "a"], [0, "a"]],
67
+ ["+", [1, nil], [1, "b"]],
68
+ ["+", [1, nil], [2, "c"]],
69
+ ["+", [1, nil], [3, "d"]],
70
+ ["=", [1, "e"], [4, "e"]]
69
71
  ]
70
72
  }
71
73
 
@@ -73,17 +75,17 @@ describe "Diff::LCS.sdiff" do
73
75
  end
74
76
 
75
77
  describe "using %w(v x a e) & %w(w y a b c d e)" do
76
- let(:s1) { %w(v x a e) }
77
- let(:s2) { %w(w y a b c d e) }
78
+ let(:s1) { %w[v x a e] }
79
+ let(:s2) { %w[w y a b c d e] }
78
80
  let(:result) {
79
81
  [
80
- [ '!', [ 0, 'v' ], [ 0, 'w' ] ],
81
- [ '!', [ 1, 'x' ], [ 1, 'y' ] ],
82
- [ '=', [ 2, 'a' ], [ 2, 'a' ] ],
83
- [ '+', [ 3, nil ], [ 3, 'b' ] ],
84
- [ '+', [ 3, nil ], [ 4, 'c' ] ],
85
- [ '+', [ 3, nil ], [ 5, 'd' ] ],
86
- [ '=', [ 3, 'e' ], [ 6, 'e' ] ]
82
+ ["!", [0, "v"], [0, "w"]],
83
+ ["!", [1, "x"], [1, "y"]],
84
+ ["=", [2, "a"], [2, "a"]],
85
+ ["+", [3, nil], [3, "b"]],
86
+ ["+", [3, nil], [4, "c"]],
87
+ ["+", [3, nil], [5, "d"]],
88
+ ["=", [3, "e"], [6, "e"]]
87
89
  ]
88
90
  }
89
91
 
@@ -91,16 +93,16 @@ describe "Diff::LCS.sdiff" do
91
93
  end
92
94
 
93
95
  describe "using %w(x a e) & %w(a b c d e)" do
94
- let(:s1) { %w(x a e) }
95
- let(:s2) { %w(a b c d e) }
96
+ let(:s1) { %w[x a e] }
97
+ let(:s2) { %w[a b c d e] }
96
98
  let(:result) {
97
99
  [
98
- [ '-', [ 0, 'x' ], [ 0, nil ] ],
99
- [ '=', [ 1, 'a' ], [ 0, 'a' ] ],
100
- [ '+', [ 2, nil ], [ 1, 'b' ] ],
101
- [ '+', [ 2, nil ], [ 2, 'c' ] ],
102
- [ '+', [ 2, nil ], [ 3, 'd' ] ],
103
- [ '=', [ 2, 'e' ], [ 4, 'e' ] ]
100
+ ["-", [0, "x"], [0, nil]],
101
+ ["=", [1, "a"], [0, "a"]],
102
+ ["+", [2, nil], [1, "b"]],
103
+ ["+", [2, nil], [2, "c"]],
104
+ ["+", [2, nil], [3, "d"]],
105
+ ["=", [2, "e"], [4, "e"]]
104
106
  ]
105
107
  }
106
108
 
@@ -108,16 +110,16 @@ describe "Diff::LCS.sdiff" do
108
110
  end
109
111
 
110
112
  describe "using %w(a e) & %w(x a b c d e)" do
111
- let(:s1) { %w(a e) }
112
- let(:s2) { %w(x a b c d e) }
113
+ let(:s1) { %w[a e] }
114
+ let(:s2) { %w[x a b c d e] }
113
115
  let(:result) {
114
116
  [
115
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
116
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
117
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
118
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
119
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
120
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ]
117
+ ["+", [0, nil], [0, "x"]],
118
+ ["=", [0, "a"], [1, "a"]],
119
+ ["+", [1, nil], [2, "b"]],
120
+ ["+", [1, nil], [3, "c"]],
121
+ ["+", [1, nil], [4, "d"]],
122
+ ["=", [1, "e"], [5, "e"]]
121
123
  ]
122
124
  }
123
125
 
@@ -125,18 +127,18 @@ describe "Diff::LCS.sdiff" do
125
127
  end
126
128
 
127
129
  describe "using %w(a e v) & %w(x a b c d e w x)" do
128
- let(:s1) { %w(a e v) }
129
- let(:s2) { %w(x a b c d e w x) }
130
+ let(:s1) { %w[a e v] }
131
+ let(:s2) { %w[x a b c d e w x] }
130
132
  let(:result) {
131
133
  [
132
- [ '+', [ 0, nil ], [ 0, 'x' ] ],
133
- [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
134
- [ '+', [ 1, nil ], [ 2, 'b' ] ],
135
- [ '+', [ 1, nil ], [ 3, 'c' ] ],
136
- [ '+', [ 1, nil ], [ 4, 'd' ] ],
137
- [ '=', [ 1, 'e' ], [ 5, 'e' ] ],
138
- [ '!', [ 2, 'v' ], [ 6, 'w' ] ],
139
- [ '+', [ 3, nil ], [ 7, 'x' ] ]
134
+ ["+", [0, nil], [0, "x"]],
135
+ ["=", [0, "a"], [1, "a"]],
136
+ ["+", [1, nil], [2, "b"]],
137
+ ["+", [1, nil], [3, "c"]],
138
+ ["+", [1, nil], [4, "d"]],
139
+ ["=", [1, "e"], [5, "e"]],
140
+ ["!", [2, "v"], [6, "w"]],
141
+ ["+", [3, nil], [7, "x"]]
140
142
  ]
141
143
  }
142
144
 
@@ -144,13 +146,13 @@ describe "Diff::LCS.sdiff" do
144
146
  end
145
147
 
146
148
  describe "using %w() & %w(a b c)" do
147
- let(:s1) { %w() }
148
- let(:s2) { %w(a b c) }
149
+ let(:s1) { %w[] }
150
+ let(:s2) { %w[a b c] }
149
151
  let(:result) {
150
152
  [
151
- [ '+', [ 0, nil ], [ 0, 'a' ] ],
152
- [ '+', [ 0, nil ], [ 1, 'b' ] ],
153
- [ '+', [ 0, nil ], [ 2, 'c' ] ]
153
+ ["+", [0, nil], [0, "a"]],
154
+ ["+", [0, nil], [1, "b"]],
155
+ ["+", [0, nil], [2, "c"]]
154
156
  ]
155
157
  }
156
158
 
@@ -158,13 +160,13 @@ describe "Diff::LCS.sdiff" do
158
160
  end
159
161
 
160
162
  describe "using %w(a b c) & %w(1)" do
161
- let(:s1) { %w(a b c) }
162
- let(:s2) { %w(1) }
163
+ let(:s1) { %w[a b c] }
164
+ let(:s2) { %w[1] }
163
165
  let(:result) {
164
166
  [
165
- [ '!', [ 0, 'a' ], [ 0, '1' ] ],
166
- [ '-', [ 1, 'b' ], [ 1, nil ] ],
167
- [ '-', [ 2, 'c' ], [ 1, nil ] ]
167
+ ["!", [0, "a"], [0, "1"]],
168
+ ["-", [1, "b"], [1, nil]],
169
+ ["-", [2, "c"], [1, nil]]
168
170
  ]
169
171
  }
170
172
 
@@ -172,13 +174,13 @@ describe "Diff::LCS.sdiff" do
172
174
  end
173
175
 
174
176
  describe "using %w(a b c) & %w(c)" do
175
- let(:s1) { %w(a b c) }
176
- let(:s2) { %w(c) }
177
+ let(:s1) { %w[a b c] }
178
+ let(:s2) { %w[c] }
177
179
  let(:result) {
178
180
  [
179
- [ '-', [ 0, 'a' ], [ 0, nil ] ],
180
- [ '-', [ 1, 'b' ], [ 0, nil ] ],
181
- [ '=', [ 2, 'c' ], [ 0, 'c' ] ]
181
+ ["-", [0, "a"], [0, nil]],
182
+ ["-", [1, "b"], [0, nil]],
183
+ ["=", [2, "c"], [0, "c"]]
182
184
  ]
183
185
  }
184
186
 
@@ -186,14 +188,14 @@ describe "Diff::LCS.sdiff" do
186
188
  end
187
189
 
188
190
  describe "using %w(abcd efgh ijkl mnop) & []" do
189
- let(:s1) { %w(abcd efgh ijkl mnop) }
191
+ let(:s1) { %w[abcd efgh ijkl mnop] }
190
192
  let(:s2) { [] }
191
193
  let(:result) {
192
194
  [
193
- [ '-', [ 0, 'abcd' ], [ 0, nil ] ],
194
- [ '-', [ 1, 'efgh' ], [ 0, nil ] ],
195
- [ '-', [ 2, 'ijkl' ], [ 0, nil ] ],
196
- [ '-', [ 3, 'mnop' ], [ 0, nil ] ]
195
+ ["-", [0, "abcd"], [0, nil]],
196
+ ["-", [1, "efgh"], [0, nil]],
197
+ ["-", [2, "ijkl"], [0, nil]],
198
+ ["-", [3, "mnop"], [0, nil]]
197
199
  ]
198
200
  }
199
201
 
@@ -201,11 +203,11 @@ describe "Diff::LCS.sdiff" do
201
203
  end
202
204
 
203
205
  describe "using [[1,2]] & []" do
204
- let(:s1) { [ [ 1, 2 ] ] }
206
+ let(:s1) { [[1, 2]] }
205
207
  let(:s2) { [] }
206
208
  let(:result) {
207
209
  [
208
- [ '-', [ 0, [ 1, 2 ] ], [ 0, nil ] ]
210
+ ["-", [0, [1, 2]], [0, nil]]
209
211
  ]
210
212
  }
211
213