Files
elixir-koans/lib/display/colours.ex
Jay Hayes 43c2bbdd71 Show left and right hand values when equality fails
For assertions that contain function calls, displaying just the
expression is not helpful. For e.g.

  Assertion failed
  String.upcase("foo") == "Foo"

The learner is given no extra information to help them learn. Sure they
might consult the documentation (and should!), but perhaps a better
experience would be for us to inform the learner about the values it
encountered.

  Assertion failed
  String.upcase("foo") == "Foo"
  left:  "FOO"
  right: "Foo"

Learner: 💡 ah hah! it upcases the whole string! 💫
2016-06-10 11:39:39 -05:00

35 lines
759 B
Elixir

defmodule Display.Paint do
def red(str), do: painter().red(str)
def cyan(str), do: painter().cyan(str)
def green(str), do: painter().green(str)
def yellow(str), do: painter.yellow(str)
defp painter do
case Mix.env do
:test -> Display.Uncoloured
_ -> Display.Colours
end
end
end
defmodule Display.Colours do
alias IO.ANSI
def red(str), do: colourize(ANSI.red, str)
def cyan(str), do: colourize(ANSI.cyan, str)
def green(str), do: colourize(ANSI.green, str)
def yellow(str), do: colourize(ANSI.yellow, str)
defp colourize(color, message) do
Enum.join([color, message, ANSI.reset], "")
end
end
defmodule Display.Uncoloured do
def red(str), do: str
def cyan(str), do: str
def green(str), do: str
end