halostatue / diff-lcs

Generate difference sets between Ruby sequences.
http://halostatue.github.com/diff-lcs
Other
290 stars 57 forks source link

Diff::LCS::Hunk#diff(:unified) output changed between 1.3 and 1.4.1 #60

Closed phiggins closed 4 years ago

phiggins commented 4 years ago

Hi,

The tests for chef/chef are seeing some failures related to diff output after upgrading from version 1.3 to 1.4.1 (see chef/chef#10057 for a bit more detail). I've distilled one of the failing test cases to a small script that demonstrates the changes between versions:

require 'diff/lcs'
require 'diff/lcs/hunk'

puts "::Diff::LCS::VERSION == #{::Diff::LCS::VERSION}"
puts

old_data = <<~DATA_OLD.strip.split("\n").map(&:chomp)
{
  "name": "x",
  "description": "hi"
}
DATA_OLD

new_data = <<~DATA_NEW.strip.split("\n").map(&:chomp)
{
  "name": "x",
  "description": "lo"
}
DATA_NEW

diff = ::Diff::LCS.diff(old_data, new_data)

abort "Got #{diff.size} chunks." unless diff.size == 1

hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)

puts hunk.diff(:unified)

Running this with 1.3 I get this output:

Petes-MBP:chef pete$ ruby test_lcs_diff.rb
::Diff::LCS::VERSION == 1.3

@@ -1,5 +1,5 @@
 {
   "name": "x",
-  "description": "hi"
+  "description": "lo"
 }

Running the script with 1.4.1 I get this output:

Petes-MBP:chef pete$ ruby test_lcs_diff.rb
::Diff::LCS::VERSION == 1.4.1

@@ -1,3 +1,3 @@
 {
   "name": "x",
-  "description": "hi"
+  "description": "lo"