module Minitest::Assertions

def mu_pp_for_diff obj

def mu_pp_for_diff obj
  str = mu_pp obj
  # both '\n' & '\\n' (_after_ mu_pp (aka inspect))
  single = !!str.match(/(?<!\\|^)\\n/)
  double = !!str.match(/(?<=\\|^)\\n/)
  process =
    if single ^ double then
      if single then
        lambda { |s| s == "\\n"   ? "\n"    : s } # unescape
      else
        lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
      end
    else
      :itself                                     # leave it alone
    end
  str.
    gsub(/\\?\\n/, &process).
    gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
end