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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  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 +76 -6
  8. data/README.md +92 -0
  9. data/Rakefile +83 -42
  10. data/SECURITY.md +41 -0
  11. data/bin/htmldiff +4 -4
  12. data/docs/artistic.txt +1 -1
  13. data/lib/diff/lcs/array.rb +1 -1
  14. data/lib/diff/lcs/backports.rb +6 -2
  15. data/lib/diff/lcs/block.rb +4 -4
  16. data/lib/diff/lcs/callbacks.rb +9 -7
  17. data/lib/diff/lcs/change.rb +22 -22
  18. data/lib/diff/lcs/htmldiff.rb +26 -16
  19. data/lib/diff/lcs/hunk.rb +66 -45
  20. data/lib/diff/lcs/internals.rb +24 -20
  21. data/lib/diff/lcs/ldiff.rb +93 -75
  22. data/lib/diff/lcs/version.rb +7 -0
  23. data/lib/diff/lcs.rb +86 -83
  24. data/lib/diff-lcs.rb +1 -1
  25. data/mise.toml +5 -0
  26. data/spec/change_spec.rb +50 -50
  27. data/spec/diff_spec.rb +14 -14
  28. data/spec/fixtures/123_x +2 -0
  29. data/spec/fixtures/456_x +2 -0
  30. data/spec/fixtures/empty +0 -0
  31. data/spec/fixtures/file1.bin +0 -0
  32. data/spec/fixtures/file2.bin +0 -0
  33. data/spec/fixtures/four_lines +4 -0
  34. data/spec/fixtures/four_lines_with_missing_new_line +4 -0
  35. data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  36. data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  37. data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  38. data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  39. data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
  40. data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
  41. data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  42. data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  43. data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  44. data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  45. data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
  46. data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
  47. data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
  48. data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
  49. data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
  50. data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
  51. data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
  52. data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
  53. data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
  54. data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
  55. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  56. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  57. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  58. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  59. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  60. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  61. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  62. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  63. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  64. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  65. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  66. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  67. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  68. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  69. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  70. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  71. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  72. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  73. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  74. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  75. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  76. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  77. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  78. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
  79. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
  80. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  81. data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  82. data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  83. data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  84. data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  85. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  86. data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  87. data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  88. data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  89. data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  90. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  91. data/spec/fixtures/new-chef +4 -0
  92. data/spec/fixtures/new-chef2 +17 -0
  93. data/spec/fixtures/old-chef +4 -0
  94. data/spec/fixtures/old-chef2 +14 -0
  95. data/spec/hunk_spec.rb +20 -20
  96. data/spec/issues_spec.rb +76 -70
  97. data/spec/lcs_spec.rb +11 -11
  98. data/spec/ldiff_spec.rb +30 -17
  99. data/spec/patch_spec.rb +84 -84
  100. data/spec/sdiff_spec.rb +111 -109
  101. data/spec/spec_helper.rb +162 -161
  102. data/spec/traverse_balanced_spec.rb +191 -189
  103. data/spec/traverse_sequences_spec.rb +31 -33
  104. metadata +112 -63
  105. data/Code-of-Conduct.md +0 -74
  106. data/Contributing.md +0 -118
  107. data/History.md +0 -319
  108. data/README.rdoc +0 -84
  109. data/autotest/discover.rb +0 -3
data/spec/spec_helper.rb CHANGED
@@ -1,42 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'pathname'
3
+ require "rubygems"
4
+ require "pathname"
5
5
 
6
- require 'psych' if RUBY_VERSION >= '1.9'
6
+ require "psych" if RUBY_VERSION >= "1.9"
7
7
 
8
- if ENV['COVERAGE']
9
- require 'simplecov'
8
+ if ENV["COVERAGE"]
9
+ require "simplecov"
10
+ require "simplecov-lcov"
10
11
 
11
- def require_do(resource)
12
- require resource
13
- yield if block_given?
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
- formatters = [SimpleCov::Formatter::HTMLFormatter]
19
-
20
- require_do('simplecov-rcov') {
21
- formatters << SimpleCov::Formatter::RcovFormatter
22
- }
23
- require_do('simplecov-vim/formatter') {
24
- formatters << SimpleCov::Formatter::VimFormatter
25
- }
26
- require_do('simplecov-sublime-ruby-coverage') {
27
- formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter
28
- }
29
-
30
- SimpleCov.start do
31
- formatter SimpleCov::Formatter::MultiFormatter[*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
 
35
- file = Pathname.new(__FILE__).expand_path
36
- path = file.parent
28
+ file = Pathname.new(__FILE__).expand_path
29
+ path = file.parent
37
30
  parent = path.parent
38
31
 
39
- $:.unshift parent.join('lib')
32
+ $:.unshift parent.join("lib")
40
33
 
41
34
  module CaptureSubprocessIO
42
35
  def _synchronize
@@ -48,9 +41,9 @@ module CaptureSubprocessIO
48
41
  end
49
42
 
50
43
  def _capture_subprocess_io
51
- require 'tempfile'
44
+ require "tempfile"
52
45
 
53
- captured_stdout, captured_stderr = Tempfile.new('out'), Tempfile.new('err')
46
+ captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
54
47
 
55
48
  orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
56
49
  $stdout.reopen captured_stdout
@@ -71,62 +64,63 @@ module CaptureSubprocessIO
71
64
  private :_capture_subprocess_io
72
65
  end
73
66
 
74
- require 'diff-lcs'
67
+ require "diff-lcs"
75
68
 
76
69
  module Diff::LCS::SpecHelper
77
70
  def hello
78
- 'hello'
71
+ "hello"
79
72
  end
80
73
 
81
74
  def hello_ary
82
- %w(h e l l o)
75
+ %w[h e l l o]
83
76
  end
84
77
 
85
78
  def seq1
86
- %w(a b c e h j l m n p)
79
+ %w[a b c e h j l m n p]
87
80
  end
88
81
 
89
82
  def skipped_seq1
90
- %w(a h n p)
83
+ %w[a h n p]
91
84
  end
92
85
 
93
86
  def seq2
94
- %w(b c d e f j k l m r s t)
87
+ %w[b c d e f j k l m r s t]
95
88
  end
96
89
 
97
90
  def skipped_seq2
98
- %w(d f k r s t)
91
+ %w[d f k r s t]
99
92
  end
100
93
 
101
94
  def word_sequence
102
- %w(abcd efgh ijkl mnopqrstuvwxyz)
95
+ %w[abcd efgh ijkl mnopqrstuvwxyz]
103
96
  end
104
97
 
105
98
  def correct_lcs
106
- %w(b c e j l m)
99
+ %w[b c e j l m]
107
100
  end
108
101
 
102
+ # standard:disable Layout/ExtraSpacing
109
103
  def correct_forward_diff
110
104
  [
111
105
  [
112
- ['-', 0, 'a']
106
+ ["-", 0, "a"]
113
107
  ],
114
108
  [
115
- ['+', 2, 'd']
109
+ ["+", 2, "d"]
116
110
  ],
117
111
  [
118
- ['-', 4, 'h'],
119
- ['+', 4, 'f']
112
+ ["-", 4, "h"],
113
+ ["+", 4, "f"]
120
114
  ],
121
115
  [
122
- ['+', 6, 'k']
116
+ ["+", 6, "k"]
123
117
  ],
124
118
  [
125
- ['-', 8, 'n'],
126
- ['-', 9, 'p'],
127
- ['+', 9, 'r'],
128
- ['+', 10, 's'],
129
- ['+', 11, 't']
119
+ ["-", 8, "n"],
120
+ ["+", 9, "r"],
121
+ ["-", 9, "p"],
122
+ ["+", 10, "s"],
123
+ ["+", 11, "t"]
130
124
  ]
131
125
  ]
132
126
  end
@@ -134,52 +128,53 @@ module Diff::LCS::SpecHelper
134
128
  def correct_backward_diff
135
129
  [
136
130
  [
137
- ['+', 0, 'a']
131
+ ["+", 0, "a"]
138
132
  ],
139
133
  [
140
- ['-', 2, 'd']
134
+ ["-", 2, "d"]
141
135
  ],
142
136
  [
143
- ['-', 4, 'f'],
144
- ['+', 4, 'h']
137
+ ["-", 4, "f"],
138
+ ["+", 4, "h"]
145
139
  ],
146
140
  [
147
- ['-', 6, 'k']
141
+ ["-", 6, "k"]
148
142
  ],
149
143
  [
150
- ['-', 9, 'r'],
151
- ['-', 10, 's'],
152
- ['+', 8, 'n'],
153
- ['-', 11, 't'],
154
- ['+', 9, 'p']
144
+ ["-", 9, "r"],
145
+ ["+", 8, "n"],
146
+ ["-", 10, "s"],
147
+ ["+", 9, "p"],
148
+ ["-", 11, "t"]
155
149
  ]
156
150
  ]
157
151
  end
158
152
 
159
153
  def correct_forward_sdiff
160
154
  [
161
- ['-', [0, 'a'], [0, nil]],
162
- ['=', [1, 'b'], [0, 'b']],
163
- ['=', [2, 'c'], [1, 'c']],
164
- ['+', [3, nil], [2, 'd']],
165
- ['=', [3, 'e'], [3, 'e']],
166
- ['!', [4, 'h'], [4, 'f']],
167
- ['=', [5, 'j'], [5, 'j']],
168
- ['+', [6, nil], [6, 'k']],
169
- ['=', [6, 'l'], [7, 'l']],
170
- ['=', [7, 'm'], [8, 'm']],
171
- ['!', [8, 'n'], [9, 'r']],
172
- ['!', [9, 'p'], [10, 's']],
173
- ['+', [10, nil], [11, 't']]
155
+ ["-", [0, "a"], [0, nil]],
156
+ ["=", [1, "b"], [0, "b"]],
157
+ ["=", [2, "c"], [1, "c"]],
158
+ ["+", [3, nil], [2, "d"]],
159
+ ["=", [3, "e"], [3, "e"]],
160
+ ["!", [4, "h"], [4, "f"]],
161
+ ["=", [5, "j"], [5, "j"]],
162
+ ["+", [6, nil], [6, "k"]],
163
+ ["=", [6, "l"], [7, "l"]],
164
+ ["=", [7, "m"], [8, "m"]],
165
+ ["!", [8, "n"], [9, "r"]],
166
+ ["!", [9, "p"], [10, "s"]],
167
+ ["+", [10, nil], [11, "t"]]
174
168
  ]
175
169
  end
170
+ # standard:enable Layout/ExtraSpacing
176
171
 
177
172
  def reverse_sdiff(forward_sdiff)
178
173
  forward_sdiff.map { |line|
179
174
  line[1], line[2] = line[2], line[1]
180
175
  case line[0]
181
- when '-' then line[0] = '+'
182
- when '+' then line[0] = '-'
176
+ when "-" then line[0] = "+"
177
+ when "+" then line[0] = "-"
183
178
  end
184
179
  line
185
180
  }
@@ -195,8 +190,8 @@ module Diff::LCS::SpecHelper
195
190
 
196
191
  def format_diffs(diffs)
197
192
  diffs.map { |e|
198
- if e.kind_of?(Array)
199
- e.map { |f| f.to_a.join }.join(', ')
193
+ if e.is_a?(Array)
194
+ e.map { |f| f.to_a.join }.join(", ")
200
195
  else
201
196
  e.to_a.join
202
197
  end
@@ -224,10 +219,10 @@ module Diff::LCS::SpecHelper
224
219
  change_result.each do |line|
225
220
  line = [line[0], line[2], line[1]]
226
221
  case line[0]
227
- when '<'
228
- line[0] = '>'
229
- when '>'
230
- line[0] = '<'
222
+ when "<"
223
+ line[0] = ">"
224
+ when ">"
225
+ line[0] = "<"
231
226
  end
232
227
  new_result << line
233
228
  end
@@ -238,9 +233,9 @@ module Diff::LCS::SpecHelper
238
233
  new_result = []
239
234
  change_result.each do |line|
240
235
  case line[0]
241
- when '!'
242
- new_result << ['<', line[1], line[2]]
243
- new_result << ['>', line[1] + 1, line[2]]
236
+ when "!"
237
+ new_result << ["<", line[1], line[2]]
238
+ new_result << [">", line[1] + 1, line[2]]
244
239
  else
245
240
  new_result << line
246
241
  end
@@ -248,101 +243,107 @@ module Diff::LCS::SpecHelper
248
243
  new_result
249
244
  end
250
245
 
251
- def simple_callback
252
- callbacks = Object.new
253
- class << callbacks
254
- attr_reader :matched_a
255
- attr_reader :matched_b
256
- attr_reader :discards_a
257
- attr_reader :discards_b
258
- attr_reader :done_a
259
- attr_reader :done_b
260
-
261
- def reset
262
- @matched_a = []
263
- @matched_b = []
264
- @discards_a = []
265
- @discards_b = []
266
- @done_a = []
267
- @done_b = []
268
- end
246
+ class SimpleCallback
247
+ def initialize
248
+ reset
249
+ end
269
250
 
270
- def match(event)
271
- @matched_a << event.old_element
272
- @matched_b << event.new_element
273
- end
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
274
267
 
275
- def discard_b(event)
276
- @discards_b << event.new_element
277
- end
268
+ def match(event)
269
+ @matched_a << event.old_element
270
+ @matched_b << event.new_element
271
+ end
278
272
 
279
- def discard_a(event)
280
- @discards_a << event.old_element
281
- end
273
+ def discard_b(event)
274
+ @discards_b << event.new_element
275
+ end
282
276
 
283
- def finished_a(event)
284
- @done_a << [
285
- event.old_element, event.old_position,
286
- event.new_element, event.new_position
287
- ]
288
- end
277
+ def discard_a(event)
278
+ @discards_a << event.old_element
279
+ end
289
280
 
290
- def finished_b(event)
291
- p 'called #finished_b'
292
- @done_b << [
293
- event.old_element, event.old_position,
294
- event.new_element, event.new_position
295
- ]
296
- end
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
+ ]
297
293
  end
298
- callbacks.reset
299
- callbacks
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
300
303
  end
301
304
 
302
305
  def simple_callback_no_finishers
303
- simple = simple_callback
304
- class << simple
305
- undef :finished_a
306
- undef :finished_b
307
- end
308
- simple
306
+ SimpleCallbackNoFinishers.new
309
307
  end
310
308
 
311
- def balanced_callback
312
- cb = Object.new
313
- class << cb
314
- attr_reader :result
309
+ class BalancedCallback
310
+ def initialize
311
+ reset
312
+ end
315
313
 
316
- def reset
317
- @result = []
318
- end
314
+ attr_reader :result
319
315
 
320
- def match(event)
321
- @result << ['=', event.old_position, event.new_position]
322
- end
316
+ def reset
317
+ @result = []
318
+ end
323
319
 
324
- def discard_a(event)
325
- @result << ['<', event.old_position, event.new_position]
326
- end
320
+ def match(event)
321
+ @result << ["=", event.old_position, event.new_position]
322
+ end
327
323
 
328
- def discard_b(event)
329
- @result << ['>', event.old_position, event.new_position]
330
- end
324
+ def discard_a(event)
325
+ @result << ["<", event.old_position, event.new_position]
326
+ end
331
327
 
332
- def change(event)
333
- @result << ['!', event.old_position, event.new_position]
334
- end
328
+ def discard_b(event)
329
+ @result << [">", event.old_position, event.new_position]
335
330
  end
336
- cb.reset
337
- cb
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
338
343
  end
339
344
 
340
345
  def balanced_callback_no_change
341
- balanced = balanced_callback
342
- class << balanced
343
- undef :change
344
- end
345
- balanced
346
+ BalancedCallbackNoChange.new
346
347
  end
347
348
 
348
349
  module Matchers
@@ -356,9 +357,7 @@ module Diff::LCS::SpecHelper
356
357
 
357
358
  matcher :correctly_map_sequence do |s1|
358
359
  match do |actual|
359
- actual.each_with_index { |ee, ii|
360
- expect(ee).to be_nil_or_match_values(ii, s1, @s2)
361
- }
360
+ actual.each_index { |ii| expect(actual[ii]).to be_nil_or_match_values(ii, s1, @s2) }
362
361
  end
363
362
 
364
363
  chain :to_other_sequence do |s2|
@@ -370,6 +369,8 @@ end
370
369
 
371
370
  RSpec.configure do |conf|
372
371
  conf.include Diff::LCS::SpecHelper
373
- conf.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
372
+ conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:"
373
+ # standard:disable Style/HashSyntax
374
374
  conf.filter_run_excluding :broken => true
375
+ # standard:enable Style/HashSyntax
375
376
  end