From 876e98c07ec825a379a29ffefea604d0f5ac8e30 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Thu, 4 Apr 2024 13:24:26 -0600 Subject: [PATCH] lol this is what i get for using private apis --- test/support/style_case.ex | 61 +++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/test/support/style_case.ex b/test/support/style_case.ex index 80627c5a..12f7030c 100644 --- a/test/support/style_case.ex +++ b/test/support/style_case.ex @@ -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