Skip to content

Commit

Permalink
+ Changed mu_pp_for_diff to make having both \n and \\n easier to debug.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 12116]
  • Loading branch information
zenspider committed Jun 10, 2019
1 parent b1578db commit b2eebc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 15 additions & 3 deletions lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,21 @@ def mu_pp obj
# uses mu_pp to do the first pass and then cleans it up.

def mu_pp_for_diff obj
mu_pp(obj).
gsub(/\\n/, "\n"). # escaped newlines -> newlines
gsub(/\\\n/, "\\n\n"). # escaped slash+newline -> escaped newline+newline
str = mu_pp obj

# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
nerd = (str.index(/(?<=\\|^)\\n/) &&
str.index(/(?<!\\|^)\\n/))

process =
if nerd then # nerd view:
lambda { |s| "#{s}#{ "\n" if s == "\\n" }" } # keep escapes, add nl for "\n"
else # normal view:
lambda { |s| s == "\\n" ? "\n" : "\\n\n" } # de-escape a bit, add nls
end

str.
gsub(/\\?\\n/, &process).
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
end

Expand Down
10 changes: 0 additions & 10 deletions test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ def test_assert_equal_does_not_allow_lhs_nil_triggered
end

def test_assert_equal_string_both_escaped_unescaped_newlines
skip "not yet"

msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
--- expected
+++ actual
Expand Down Expand Up @@ -1174,8 +1172,6 @@ def o1.== _
end

def test_diff_str_mixed
skip "not yet"

msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
--- expected
+++ actual
Expand Down Expand Up @@ -1244,8 +1240,6 @@ def test_mu_pp_for_diff_str_bad_encoding
end

def test_mu_pp_for_diff_str_bad_encoding_both
skip "not yet"

str = "\666A\\n\nB".force_encoding Encoding::UTF_8
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\n\nB\""

Expand All @@ -1260,17 +1254,13 @@ def test_mu_pp_for_diff_str_encoding
end

def test_mu_pp_for_diff_str_encoding_both
skip "not yet"

str = "A\\n\nB".b
exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\\\\n\\n\nB\""

assert_mu_pp_for_diff exp, str
end

def test_mu_pp_for_diff_str_nerd
skip "not yet"

assert_mu_pp_for_diff "\"A\\n\nB\\\\nC\"", "A\nB\\nC"
assert_mu_pp_for_diff "\"\\n\nB\\\\nC\"", "\nB\\nC"
assert_mu_pp_for_diff "\"\\n\nB\\\\n\"", "\nB\\n"
Expand Down

0 comments on commit b2eebc2

Please sign in to comment.