Skip to content

Commit

Permalink
lol this is what i get for using private apis
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Apr 4, 2024
1 parent 3edad64 commit 876e98c
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions test/support/style_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,39 @@ defmodule Styler.StyleCase do
end
end

def format_diff(left, right, prelude \\ "Styling produced unexpected results") do
# reaching into private ExUnit stuff, uh oh!
# this gets us the nice diffing from ExUnit while allowing us to print our code blocks as strings rather than inspected strings
{%{left: left, right: right}, _} = ExUnit.Diff.compute(left, right, :==)
left = for {diff?, content} <- left.contents, do: if(diff?, do: [:red, content, :reset], else: content)
right = for {diff?, content} <- right.contents, do: if(diff?, do: [:green, content, :reset], else: content)
header = IO.ANSI.format([:red, prelude, :reset])

left =
[[:cyan, "left:\n", :reset] | left]
|> IO.ANSI.format()
|> to_string()
|> Macro.unescape_string()
|> String.replace("\n", "\n ")

right =
[[:cyan, "right:\n", :reset] | right]
|> IO.ANSI.format()
|> to_string()
|> Macro.unescape_string()
|> String.replace("\n", "\n ")

"""
#{header}
#{left}
#{right}
"""
if Version.match?(System.version(), ">= 1.15.0-dev") do
def format_diff(left, right, prelude \\ "Styling produced unexpected results") do
# reaching into private ExUnit stuff, uh oh!
# this gets us the nice diffing from ExUnit while allowing us to print our code blocks as strings rather than inspected strings
{%{left: left, right: right}, _} = ExUnit.Diff.compute(left, right, :==)
left = for {diff?, content} <- left.contents, do: if(diff?, do: [:red, content, :reset], else: content)
right = for {diff?, content} <- right.contents, do: if(diff?, do: [:green, content, :reset], else: content)
header = IO.ANSI.format([:red, prelude, :reset])

left =
[[:cyan, "left:\n", :reset] | left]
|> IO.ANSI.format()
|> to_string()
|> Macro.unescape_string()
|> String.replace("\n", "\n ")

right =
[[:cyan, "right:\n", :reset] | right]
|> IO.ANSI.format()
|> to_string()
|> Macro.unescape_string()
|> String.replace("\n", "\n ")

"""
#{header}
#{left}
#{right}
"""
end
else
def format_diff(left, right, prelude \\ "") do
IO.puts(prelude)
assert left == right
end
end
end

0 comments on commit 876e98c

Please sign in to comment.