diff-lcs 1.5.1 → 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} +15 -16
- data/Manifest.txt +61 -5
- data/README.md +92 -0
- data/Rakefile +48 -63
- data/SECURITY.md +41 -0
- data/docs/artistic.txt +1 -1
- data/lib/diff/lcs/backports.rb +4 -0
- data/lib/diff/lcs/change.rb +3 -3
- data/lib/diff/lcs/htmldiff.rb +5 -3
- data/lib/diff/lcs/hunk.rb +38 -22
- data/lib/diff/lcs/ldiff.rb +65 -49
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +12 -11
- data/mise.toml +5 -0
- 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.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/hunk_spec.rb +1 -1
- data/spec/issues_spec.rb +32 -32
- data/spec/ldiff_spec.rb +21 -10
- data/spec/patch_spec.rb +1 -1
- data/spec/spec_helper.rb +93 -93
- metadata +87 -65
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -121
- data/History.md +0 -431
- data/README.rdoc +0 -84
@@ -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
|
data/spec/hunk_spec.rb
CHANGED
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/ldiff_spec.rb
CHANGED
@@ -7,9 +7,16 @@ RSpec.describe "bin/ldiff" do
|
|
7
7
|
|
8
8
|
# standard:disable Style/HashSyntax
|
9
9
|
fixtures = [
|
10
|
-
{:name => "
|
11
|
-
{:name => "
|
12
|
-
{:name => "
|
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}
|
13
20
|
].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)|
|
14
21
|
fixture = fixture.dup
|
15
22
|
fixture[:flag] = flag
|
@@ -24,11 +31,14 @@ RSpec.describe "bin/ldiff" do
|
|
24
31
|
"spec/fixtures/#{fixture[:right]}",
|
25
32
|
"#",
|
26
33
|
"=>",
|
27
|
-
"spec/fixtures/ldiff
|
34
|
+
"spec/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 = "spec/fixtures/ldiff/#{fixture}#{flag}"
|
52
|
+
name = "spec/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
|
@@ -82,8 +95,6 @@ RSpec.describe "bin/ldiff" do
|
|
82
95
|
system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/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
@@ -7,28 +7,21 @@ require "psych" if RUBY_VERSION >= "1.9"
|
|
7
7
|
|
8
8
|
if ENV["COVERAGE"]
|
9
9
|
require "simplecov"
|
10
|
+
require "simplecov-lcov"
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rescue LoadError
|
15
|
-
nil
|
12
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
13
|
+
config.report_with_single_file = true
|
14
|
+
config.lcov_file_name = "lcov.info"
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
require_do("simplecov-sublime-ruby-coverage") {
|
27
|
-
formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter
|
28
|
-
}
|
29
|
-
|
30
|
-
SimpleCov.start do
|
31
|
-
formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
|
17
|
+
SimpleCov.start "test_frameworks" do
|
18
|
+
enable_coverage :branch
|
19
|
+
primary_coverage :branch
|
20
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
21
|
+
SimpleCov::Formatter::HTMLFormatter,
|
22
|
+
SimpleCov::Formatter::LcovFormatter,
|
23
|
+
SimpleCov::Formatter::SimpleFormatter
|
24
|
+
])
|
32
25
|
end
|
33
26
|
end
|
34
27
|
|
@@ -250,100 +243,107 @@ module Diff::LCS::SpecHelper
|
|
250
243
|
new_result
|
251
244
|
end
|
252
245
|
|
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
|
246
|
+
class SimpleCallback
|
247
|
+
def initialize
|
248
|
+
reset
|
249
|
+
end
|
271
250
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
251
|
+
attr_reader :matched_a
|
252
|
+
attr_reader :matched_b
|
253
|
+
attr_reader :discards_a
|
254
|
+
attr_reader :discards_b
|
255
|
+
attr_reader :done_a
|
256
|
+
attr_reader :done_b
|
257
|
+
|
258
|
+
def reset
|
259
|
+
@matched_a = []
|
260
|
+
@matched_b = []
|
261
|
+
@discards_a = []
|
262
|
+
@discards_b = []
|
263
|
+
@done_a = []
|
264
|
+
@done_b = []
|
265
|
+
self
|
266
|
+
end
|
276
267
|
|
277
|
-
|
278
|
-
|
279
|
-
|
268
|
+
def match(event)
|
269
|
+
@matched_a << event.old_element
|
270
|
+
@matched_b << event.new_element
|
271
|
+
end
|
280
272
|
|
281
|
-
|
282
|
-
|
283
|
-
|
273
|
+
def discard_b(event)
|
274
|
+
@discards_b << event.new_element
|
275
|
+
end
|
284
276
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
event.new_element, event.new_position
|
289
|
-
]
|
290
|
-
end
|
277
|
+
def discard_a(event)
|
278
|
+
@discards_a << event.old_element
|
279
|
+
end
|
291
280
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
281
|
+
def finished_a(event)
|
282
|
+
@done_a << [
|
283
|
+
event.old_element, event.old_position,
|
284
|
+
event.new_element, event.new_position
|
285
|
+
]
|
286
|
+
end
|
287
|
+
|
288
|
+
def finished_b(event)
|
289
|
+
@done_b << [
|
290
|
+
event.old_element, event.old_position,
|
291
|
+
event.new_element, event.new_position
|
292
|
+
]
|
298
293
|
end
|
299
|
-
|
300
|
-
|
294
|
+
end
|
295
|
+
|
296
|
+
def simple_callback
|
297
|
+
SimpleCallback.new
|
298
|
+
end
|
299
|
+
|
300
|
+
class SimpleCallbackNoFinishers < SimpleCallback
|
301
|
+
undef :finished_a
|
302
|
+
undef :finished_b
|
301
303
|
end
|
302
304
|
|
303
305
|
def simple_callback_no_finishers
|
304
|
-
|
305
|
-
class << simple
|
306
|
-
undef :finished_a
|
307
|
-
undef :finished_b
|
308
|
-
end
|
309
|
-
simple
|
306
|
+
SimpleCallbackNoFinishers.new
|
310
307
|
end
|
311
308
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
309
|
+
class BalancedCallback
|
310
|
+
def initialize
|
311
|
+
reset
|
312
|
+
end
|
316
313
|
|
317
|
-
|
318
|
-
@result = []
|
319
|
-
end
|
314
|
+
attr_reader :result
|
320
315
|
|
321
|
-
|
322
|
-
|
323
|
-
|
316
|
+
def reset
|
317
|
+
@result = []
|
318
|
+
end
|
324
319
|
|
325
|
-
|
326
|
-
|
327
|
-
|
320
|
+
def match(event)
|
321
|
+
@result << ["=", event.old_position, event.new_position]
|
322
|
+
end
|
328
323
|
|
329
|
-
|
330
|
-
|
331
|
-
|
324
|
+
def discard_a(event)
|
325
|
+
@result << ["<", event.old_position, event.new_position]
|
326
|
+
end
|
332
327
|
|
333
|
-
|
334
|
-
|
335
|
-
end
|
328
|
+
def discard_b(event)
|
329
|
+
@result << [">", event.old_position, event.new_position]
|
336
330
|
end
|
337
|
-
|
338
|
-
|
331
|
+
|
332
|
+
def change(event)
|
333
|
+
@result << ["!", event.old_position, event.new_position]
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def balanced_callback
|
338
|
+
BalancedCallback.new
|
339
|
+
end
|
340
|
+
|
341
|
+
class BalancedCallbackNoChange < BalancedCallback
|
342
|
+
undef :change
|
339
343
|
end
|
340
344
|
|
341
345
|
def balanced_callback_no_change
|
342
|
-
|
343
|
-
class << balanced
|
344
|
-
undef :change
|
345
|
-
end
|
346
|
-
balanced
|
346
|
+
BalancedCallbackNoChange.new
|
347
347
|
end
|
348
348
|
|
349
349
|
module Matchers
|