diff-lcs 1.5.1 → 1.6.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 +491 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +74 -0
- data/CONTRIBUTORS.md +48 -0
- data/Contributing.md +45 -92
- data/Manifest.txt +7 -4
- data/README.md +92 -0
- data/Rakefile +12 -44
- data/SECURITY.md +41 -0
- data/docs/artistic.txt +1 -1
- data/lib/diff/lcs/change.rb +1 -1
- data/lib/diff/lcs/htmldiff.rb +2 -0
- data/lib/diff/lcs/hunk.rb +38 -22
- data/lib/diff/lcs/ldiff.rb +60 -50
- data/lib/diff/lcs.rb +10 -9
- 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
- metadata +41 -23
- data/Code-of-Conduct.md +0 -74
- data/History.md +0 -431
- data/README.rdoc +0 -84
- /data/{License.md → LICENCE.md} +0 -0
data/lib/diff/lcs/hunk.rb
CHANGED
@@ -22,11 +22,13 @@ class Diff::LCS::Hunk
|
|
22
22
|
end
|
23
23
|
|
24
24
|
if String.method_defined?(:encoding)
|
25
|
-
@preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0
|
25
|
+
@preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0) { "" } }.encoding
|
26
26
|
end
|
27
27
|
|
28
28
|
@data_old = data_old
|
29
29
|
@data_new = data_new
|
30
|
+
@old_empty = data_old.empty? || (data_old.size == 1 && data_old[0].empty?)
|
31
|
+
@new_empty = data_new.empty? || (data_new.size == 1 && data_new[0].empty?)
|
30
32
|
|
31
33
|
before = after = file_length_difference
|
32
34
|
after += @blocks[0].diff_size
|
@@ -79,14 +81,12 @@ class Diff::LCS::Hunk
|
|
79
81
|
old_size = @data_old.size
|
80
82
|
|
81
83
|
add_end =
|
82
|
-
if (@end_old + context)
|
83
|
-
old_size - @end_old
|
84
|
+
if (@end_old + context) >= old_size
|
85
|
+
old_size - @end_old - 1
|
84
86
|
else
|
85
87
|
context
|
86
88
|
end
|
87
89
|
|
88
|
-
add_end = @max_diff_size if add_end >= old_size
|
89
|
-
|
90
90
|
@end_old += add_end
|
91
91
|
@end_new += add_end
|
92
92
|
end
|
@@ -131,11 +131,16 @@ class Diff::LCS::Hunk
|
|
131
131
|
|
132
132
|
# Note that an old diff can't have any context. Therefore, we know that
|
133
133
|
# there's only one block in the hunk.
|
134
|
-
def old_diff(
|
134
|
+
def old_diff(last = false)
|
135
135
|
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
|
136
136
|
|
137
137
|
block = @blocks[0]
|
138
138
|
|
139
|
+
if last
|
140
|
+
old_missing_newline = !@old_empty && missing_last_newline?(@data_old)
|
141
|
+
new_missing_newline = !@new_empty && missing_last_newline?(@data_new)
|
142
|
+
end
|
143
|
+
|
139
144
|
# Calculate item number range. Old diff range is just like a context
|
140
145
|
# diff range, except the ranges are on one line with the action between
|
141
146
|
# them.
|
@@ -146,19 +151,22 @@ class Diff::LCS::Hunk
|
|
146
151
|
@data_old[@start_old..@end_old].each { |e| s << encode("< ") + e.chomp + encode("\n") }
|
147
152
|
end
|
148
153
|
|
154
|
+
s << encode("\\n") if old_missing_newline && !new_missing_newline
|
149
155
|
s << encode("---\n") if block.op == "!"
|
150
156
|
|
151
157
|
unless block.insert.empty?
|
152
158
|
@data_new[@start_new..@end_new].each { |e| s << encode("> ") + e.chomp + encode("\n") }
|
153
159
|
end
|
154
160
|
|
161
|
+
s << encode("\\n") if new_missing_newline && !old_missing_newline
|
162
|
+
|
155
163
|
s
|
156
164
|
end
|
157
165
|
private :old_diff
|
158
166
|
|
159
167
|
def unified_diff(last = false)
|
160
168
|
# Calculate item number range.
|
161
|
-
s = encode("@@ -#{unified_range(:old
|
169
|
+
s = encode("@@ -#{unified_range(:old)} +#{unified_range(:new)} @@\n")
|
162
170
|
|
163
171
|
# Outlist starts containing the hunk of the old file. Removing an item
|
164
172
|
# just means putting a '-' in front of it. Inserting an item requires
|
@@ -178,8 +186,8 @@ class Diff::LCS::Hunk
|
|
178
186
|
last_block = blocks[-1]
|
179
187
|
|
180
188
|
if last
|
181
|
-
old_missing_newline = missing_last_newline?(@data_old)
|
182
|
-
new_missing_newline = missing_last_newline?(@data_new)
|
189
|
+
old_missing_newline = !@old_empty && missing_last_newline?(@data_old)
|
190
|
+
new_missing_newline = !@new_empty && missing_last_newline?(@data_new)
|
183
191
|
end
|
184
192
|
|
185
193
|
@blocks.each do |block|
|
@@ -213,8 +221,8 @@ class Diff::LCS::Hunk
|
|
213
221
|
|
214
222
|
def context_diff(last = false)
|
215
223
|
s = encode("***************\n")
|
216
|
-
s << encode("*** #{context_range(:old, ","
|
217
|
-
r = context_range(:new, ","
|
224
|
+
s << encode("*** #{context_range(:old, ",")} ****\n")
|
225
|
+
r = context_range(:new, ",")
|
218
226
|
|
219
227
|
if last
|
220
228
|
old_missing_newline = missing_last_newline?(@data_old)
|
@@ -273,14 +281,24 @@ class Diff::LCS::Hunk
|
|
273
281
|
end
|
274
282
|
private :context_diff
|
275
283
|
|
276
|
-
def ed_diff(format,
|
284
|
+
def ed_diff(format, last)
|
277
285
|
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
|
286
|
+
if last
|
287
|
+
# ed script doesn't support well incomplete lines
|
288
|
+
warn "<old_file>: No newline at end of file\n" if !@old_empty && missing_last_newline?(@data_old)
|
289
|
+
warn "<new_file>: No newline at end of file\n" if !@new_empty && missing_last_newline?(@data_new)
|
290
|
+
|
291
|
+
if @blocks[0].op == "!"
|
292
|
+
return +"" if @blocks[0].changes[0].element == @blocks[0].changes[1].element + "\n"
|
293
|
+
return +"" if @blocks[0].changes[0].element + "\n" == @blocks[0].changes[1].element
|
294
|
+
end
|
295
|
+
end
|
278
296
|
|
279
297
|
s =
|
280
298
|
if format == :reverse_ed
|
281
|
-
encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, "
|
299
|
+
encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, " ")}\n")
|
282
300
|
else
|
283
|
-
encode("#{context_range(:old, "
|
301
|
+
encode("#{context_range(:old, ",")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n")
|
284
302
|
end
|
285
303
|
|
286
304
|
unless @blocks[0].insert.empty?
|
@@ -295,7 +313,7 @@ class Diff::LCS::Hunk
|
|
295
313
|
|
296
314
|
# Generate a range of item numbers to print. Only print 1 number if the
|
297
315
|
# range has only one item in it. Otherwise, it's 'start,end'
|
298
|
-
def context_range(mode, op
|
316
|
+
def context_range(mode, op)
|
299
317
|
case mode
|
300
318
|
when :old
|
301
319
|
s, e = (@start_old + 1), (@end_old + 1)
|
@@ -303,9 +321,6 @@ class Diff::LCS::Hunk
|
|
303
321
|
s, e = (@start_new + 1), (@end_new + 1)
|
304
322
|
end
|
305
323
|
|
306
|
-
e -= 1 if last
|
307
|
-
e = 1 if e.zero?
|
308
|
-
|
309
324
|
(s < e) ? "#{s}#{op}#{e}" : e.to_s
|
310
325
|
end
|
311
326
|
private :context_range
|
@@ -313,18 +328,19 @@ class Diff::LCS::Hunk
|
|
313
328
|
# Generate a range of item numbers to print for unified diff. Print number
|
314
329
|
# where block starts, followed by number of lines in the block
|
315
330
|
# (don't print number of lines if it's 1)
|
316
|
-
def unified_range(mode
|
331
|
+
def unified_range(mode)
|
317
332
|
case mode
|
318
333
|
when :old
|
334
|
+
return "0,0" if @old_empty
|
319
335
|
s, e = (@start_old + 1), (@end_old + 1)
|
320
336
|
when :new
|
337
|
+
return "0,0" if @new_empty
|
321
338
|
s, e = (@start_new + 1), (@end_new + 1)
|
322
339
|
end
|
323
340
|
|
324
|
-
length = e - s +
|
341
|
+
length = e - s + 1
|
325
342
|
|
326
|
-
|
327
|
-
(length <= 1) ? first.to_s : "#{first},#{length}"
|
343
|
+
(length <= 1) ? e.to_s : "#{s},#{length}"
|
328
344
|
end
|
329
345
|
private :unified_range
|
330
346
|
|
data/lib/diff/lcs/ldiff.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "optparse"
|
4
|
-
require "ostruct"
|
5
4
|
require "diff/lcs/hunk"
|
6
5
|
|
7
6
|
module Diff::LCS::Ldiff # :nodoc:
|
@@ -18,14 +17,20 @@ ldiff #{Diff::LCS::VERSION}
|
|
18
17
|
MIT licence.
|
19
18
|
COPYRIGHT
|
20
19
|
# standard:enable Layout/HeredocIndentation
|
21
|
-
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
InputInfo = Struct.new(:filename, :data, :stat) do
|
22
|
+
def initialize(filename)
|
23
|
+
super(filename, ::File.read(filename), ::File.stat(filename))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_reader :format, :lines # :nodoc:
|
29
|
+
attr_reader :file_old, :file_new # :nodoc:
|
30
|
+
attr_reader :data_old, :data_new # :nodoc:
|
31
|
+
end
|
27
32
|
|
28
|
-
def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
|
33
|
+
def self.run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
|
29
34
|
@binary = nil
|
30
35
|
|
31
36
|
args.options do |o|
|
@@ -86,8 +91,18 @@ class << Diff::LCS::Ldiff
|
|
86
91
|
@lines ||= 0
|
87
92
|
|
88
93
|
file_old, file_new = *ARGV
|
94
|
+
diff?(
|
95
|
+
InputInfo.new(file_old),
|
96
|
+
InputInfo.new(file_new),
|
97
|
+
@format,
|
98
|
+
output,
|
99
|
+
binary: @binary,
|
100
|
+
lines: @lines
|
101
|
+
) ? 1 : 0
|
102
|
+
end
|
89
103
|
|
90
|
-
|
104
|
+
def self.diff?(info_old, info_new, format, output, binary: nil, lines: 0)
|
105
|
+
case format
|
91
106
|
when :context
|
92
107
|
char_old = "*" * 3
|
93
108
|
char_new = "-" * 3
|
@@ -100,74 +115,69 @@ class << Diff::LCS::Ldiff
|
|
100
115
|
# items we've read from each file will differ by FLD (could be 0).
|
101
116
|
file_length_difference = 0
|
102
117
|
|
103
|
-
data_old = File.read(file_old)
|
104
|
-
data_new = File.read(file_new)
|
105
|
-
|
106
118
|
# Test binary status
|
107
|
-
if
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
unless @binary
|
114
|
-
data_old = data_old.lines.to_a
|
115
|
-
data_new = data_new.lines.to_a
|
119
|
+
if binary.nil?
|
120
|
+
old_bin = info_old.data[0, 4096].include?("\0")
|
121
|
+
new_bin = info_new.data[0, 4096].include?("\0")
|
122
|
+
binary = old_bin || new_bin
|
116
123
|
end
|
117
124
|
|
118
125
|
# diff yields lots of pieces, each of which is basically a Block object
|
119
|
-
if
|
120
|
-
|
126
|
+
if binary
|
127
|
+
has_diffs = (info_old.data != info_new.data)
|
128
|
+
if format != :report
|
129
|
+
if has_diffs
|
130
|
+
output << "Binary files #{info_old.filename} and #{info_new.filename} differ\n"
|
131
|
+
return true
|
132
|
+
end
|
133
|
+
return false
|
134
|
+
end
|
121
135
|
else
|
136
|
+
data_old = info_old.data.lines.to_a
|
137
|
+
data_new = info_new.data.lines.to_a
|
122
138
|
diffs = Diff::LCS.diff(data_old, data_new)
|
123
|
-
|
139
|
+
return false if diffs.empty?
|
124
140
|
end
|
125
141
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
output
|
142
|
+
case format
|
143
|
+
when :report
|
144
|
+
output << "Files #{info_old.filename} and #{info_new.filename} differ\n"
|
145
|
+
return true
|
146
|
+
when :unified, :context
|
147
|
+
ft = info_old.stat.mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z")
|
148
|
+
output << "#{char_old} #{info_old.filename}\t#{ft}\n"
|
149
|
+
ft = info_new.stat.mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z")
|
150
|
+
output << "#{char_new} #{info_new.filename}\t#{ft}\n"
|
151
|
+
when :ed
|
152
|
+
real_output = output
|
153
|
+
output = []
|
138
154
|
end
|
139
155
|
|
140
156
|
# Loop over hunks. If a hunk overlaps with the last hunk, join them.
|
141
157
|
# Otherwise, print out the old one.
|
142
158
|
oldhunk = hunk = nil
|
143
|
-
|
144
|
-
if @format == :ed
|
145
|
-
real_output = output
|
146
|
-
output = []
|
147
|
-
end
|
148
|
-
|
149
159
|
diffs.each do |piece|
|
150
|
-
begin
|
151
|
-
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece,
|
160
|
+
begin
|
161
|
+
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, lines, file_length_difference)
|
152
162
|
file_length_difference = hunk.file_length_difference
|
153
163
|
|
154
164
|
next unless oldhunk
|
155
|
-
next if
|
165
|
+
next if lines.positive? && hunk.merge(oldhunk)
|
156
166
|
|
157
|
-
output << oldhunk.diff(
|
158
|
-
output << "\n" if
|
167
|
+
output << oldhunk.diff(format)
|
168
|
+
output << "\n" if format == :unified
|
159
169
|
ensure
|
160
170
|
oldhunk = hunk
|
161
171
|
end
|
162
172
|
end
|
163
173
|
|
164
|
-
last = oldhunk.diff(
|
165
|
-
last << "\n"
|
174
|
+
last = oldhunk.diff(format, true)
|
175
|
+
last << "\n" unless last.is_a?(Diff::LCS::Hunk) || last.empty? || last.end_with?("\n")
|
166
176
|
|
167
177
|
output << last
|
168
178
|
|
169
|
-
output.reverse_each { |e| real_output << e.diff(:ed_finish) } if
|
179
|
+
output.reverse_each { |e| real_output << e.diff(:ed_finish, e == output[0]) } if format == :ed
|
170
180
|
|
171
|
-
|
181
|
+
true
|
172
182
|
end
|
173
183
|
end
|
data/lib/diff/lcs.rb
CHANGED
@@ -49,7 +49,7 @@ module Diff; end unless defined? Diff
|
|
49
49
|
# a x b y c z p d q
|
50
50
|
# a b c a x b y c z
|
51
51
|
module Diff::LCS
|
52
|
-
VERSION = "1.
|
52
|
+
VERSION = "1.6.0"
|
53
53
|
end
|
54
54
|
|
55
55
|
require "diff/lcs/callbacks"
|
@@ -62,11 +62,12 @@ module Diff::LCS
|
|
62
62
|
# lcs = seq1.lcs(seq2)
|
63
63
|
#
|
64
64
|
# A note when using objects: Diff::LCS only works properly when each object
|
65
|
-
# can be used as a key in a Hash
|
66
|
-
#
|
67
|
-
# identically for key purposes. That is:
|
65
|
+
# can be used as a key in a Hash. This means that those objects must implement
|
66
|
+
# the methods +#hash+ and +#eql?+ such that two objects containing identical values
|
67
|
+
# compare identically for key purposes. That is:
|
68
68
|
#
|
69
|
-
# O.new('a').eql?(O.new('a')) == true
|
69
|
+
# O.new('a').eql?(O.new('a')) == true &&
|
70
|
+
# O.new('a').hash == O.new('a').hash
|
70
71
|
def lcs(other, &block) # :yields: self[i] if there are matched subsequences
|
71
72
|
Diff::LCS.lcs(self, other, &block)
|
72
73
|
end
|
@@ -256,7 +257,7 @@ class << Diff::LCS
|
|
256
257
|
#
|
257
258
|
# The methods for <tt>callbacks#match</tt>, <tt>callbacks#discard_a</tt>, and
|
258
259
|
# <tt>callbacks#discard_b</tt> are invoked with an event comprising the
|
259
|
-
# action ("=", "+", or "-", respectively), the
|
260
|
+
# action ("=", "+", or "-", respectively), the indexes +i+ and +j+, and the
|
260
261
|
# elements <tt>A[i]</tt> and <tt>B[j]</tt>. Return values are discarded by
|
261
262
|
# #traverse_sequences.
|
262
263
|
#
|
@@ -421,7 +422,7 @@ class << Diff::LCS
|
|
421
422
|
# occurred.
|
422
423
|
#
|
423
424
|
# #traverse_balanced might be a bit slower than #traverse_sequences,
|
424
|
-
#
|
425
|
+
# noticeable only while processing huge amounts of data.
|
425
426
|
#
|
426
427
|
# == Algorithm
|
427
428
|
#
|
@@ -465,7 +466,7 @@ class << Diff::LCS
|
|
465
466
|
# The methods for <tt>callbacks#match</tt>, <tt>callbacks#discard_a</tt>,
|
466
467
|
# <tt>callbacks#discard_b</tt>, and <tt>callbacks#change</tt> are invoked
|
467
468
|
# with an event comprising the action ("=", "+", "-", or "!", respectively),
|
468
|
-
# the
|
469
|
+
# the indexes +i+ and +j+, and the elements <tt>A[i]</tt> and <tt>B[j]</tt>.
|
469
470
|
# Return values are discarded by #traverse_balanced.
|
470
471
|
#
|
471
472
|
# === Context
|
@@ -482,7 +483,7 @@ class << Diff::LCS
|
|
482
483
|
|
483
484
|
# Process all the lines in the match vector.
|
484
485
|
loop do
|
485
|
-
# Find next match
|
486
|
+
# Find next match indexes +ma+ and +mb+
|
486
487
|
loop do
|
487
488
|
ma += 1
|
488
489
|
break unless ma < matches.size && matches[ma].nil?
|
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
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diff-lcs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Ziegler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe
|
@@ -146,20 +146,34 @@ dependencies:
|
|
146
146
|
- - "<"
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '7'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: simplecov
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0.21'
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - "~>"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0.21'
|
149
163
|
description: |-
|
150
164
|
Diff::LCS computes the difference between two Enumerable sequences using the
|
151
165
|
McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
|
152
166
|
to create a simple HTML diff output format and a standard diff-like tool.
|
153
167
|
|
154
168
|
This is release 1.4.3, providing a simple extension that allows for
|
155
|
-
Diff::LCS::Change objects to be treated implicitly as arrays and fixes a
|
156
|
-
|
169
|
+
Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number
|
170
|
+
of formatting issues.
|
157
171
|
|
158
|
-
Ruby versions below 2.5 are soft-deprecated, which means that older versions
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
172
|
+
Ruby versions below 2.5 are soft-deprecated, which means that older versions are
|
173
|
+
no longer part of the CI test suite. If any changes have been introduced that
|
174
|
+
break those versions, bug reports and patches will be accepted, but it will be
|
175
|
+
up to the reporter to verify any fixes prior to release. The next major release
|
176
|
+
will completely break compatibility.
|
163
177
|
email:
|
164
178
|
- halostatue@gmail.com
|
165
179
|
executables:
|
@@ -167,23 +181,29 @@ executables:
|
|
167
181
|
- ldiff
|
168
182
|
extensions: []
|
169
183
|
extra_rdoc_files:
|
170
|
-
-
|
184
|
+
- CHANGELOG.md
|
185
|
+
- CODE_OF_CONDUCT.md
|
186
|
+
- CONTRIBUTING.md
|
187
|
+
- CONTRIBUTORS.md
|
171
188
|
- Contributing.md
|
172
|
-
-
|
173
|
-
- License.md
|
189
|
+
- LICENCE.md
|
174
190
|
- Manifest.txt
|
175
|
-
- README.
|
191
|
+
- README.md
|
192
|
+
- SECURITY.md
|
176
193
|
- docs/COPYING.txt
|
177
194
|
- docs/artistic.txt
|
178
195
|
files:
|
179
196
|
- ".rspec"
|
180
|
-
-
|
197
|
+
- CHANGELOG.md
|
198
|
+
- CODE_OF_CONDUCT.md
|
199
|
+
- CONTRIBUTING.md
|
200
|
+
- CONTRIBUTORS.md
|
181
201
|
- Contributing.md
|
182
|
-
-
|
183
|
-
- License.md
|
202
|
+
- LICENCE.md
|
184
203
|
- Manifest.txt
|
185
|
-
- README.
|
204
|
+
- README.md
|
186
205
|
- Rakefile
|
206
|
+
- SECURITY.md
|
187
207
|
- bin/htmldiff
|
188
208
|
- bin/ldiff
|
189
209
|
- docs/COPYING.txt
|
@@ -238,17 +258,15 @@ files:
|
|
238
258
|
homepage: https://github.com/halostatue/diff-lcs
|
239
259
|
licenses:
|
240
260
|
- MIT
|
241
|
-
- Artistic-
|
261
|
+
- Artistic-1.0-Perl
|
242
262
|
- GPL-2.0-or-later
|
243
263
|
metadata:
|
244
|
-
homepage_uri: https://github.com/halostatue/diff-lcs
|
245
|
-
source_code_uri: https://github.com/halostatue/diff-lcs
|
246
|
-
bug_tracker_uri: https://github.com/halostatue/diff-lcs/issues
|
247
264
|
rubygems_mfa_required: 'true'
|
265
|
+
changelog_uri: https://github.com/halostatue/diff-lcs/blob/main/CHANGELOG.md
|
248
266
|
post_install_message:
|
249
267
|
rdoc_options:
|
250
268
|
- "--main"
|
251
|
-
- README.
|
269
|
+
- README.md
|
252
270
|
require_paths:
|
253
271
|
- lib
|
254
272
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -262,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
280
|
- !ruby/object:Gem::Version
|
263
281
|
version: '0'
|
264
282
|
requirements: []
|
265
|
-
rubygems_version: 3.5.
|
283
|
+
rubygems_version: 3.5.22
|
266
284
|
signing_key:
|
267
285
|
specification_version: 4
|
268
286
|
summary: Diff::LCS computes the difference between two Enumerable sequences using
|