hashdiff icon indicating copy to clipboard operation
hashdiff copied to clipboard

Unexpected results

Open pboling opened this issue 5 years ago • 1 comments

a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }

diff = HashDiff.diff(a, b) do |path, obj1, obj2|
  case path
  when 'b[*]'
    true
  end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]

vs.

a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }

diff = HashDiff.diff(a, b) do |path, obj1, obj2|
  case path
  when 'b[*]'
    false
  end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]

vs.

a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }

diff = HashDiff.diff(a, b) do |path, obj1, obj2|
  case path
  when 'b[*]'
    raise "#{obj1} == #{obj2}"
  end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]

It doesn't seem to make any difference what goes in the block as a custom comparator.

Also, when I do a puts inside the block to try and figure out what is going on there is no output?!

The raise is silently rescued?!

pboling avatar May 03 '19 03:05 pboling

Hi @pboling Could you please check if it works on master branch? It's been fixed but not released yet.

krzysiek1507 avatar May 03 '19 08:05 krzysiek1507