Add more tests for shell coloring
This commit is contained in:
@@ -9,8 +9,7 @@ defmodule IEx.Introspection do
|
||||
{ :module, _ } ->
|
||||
case module.__info__(:moduledoc) do
|
||||
{ _, binary } when is_binary(binary) ->
|
||||
# FIXME: add tests for `binary` containing ANSI escapes
|
||||
IO.write IEx.color(:info, "# #{inspect module}\n" <> binary)
|
||||
IO.write IEx.color(:info, "# #{inspect module}\n\n" <> binary)
|
||||
{ _, _ } ->
|
||||
IO.puts IEx.color(:error, "No docs for #{inspect module} have been found")
|
||||
_ ->
|
||||
@@ -148,7 +147,6 @@ defmodule IEx.Introspection do
|
||||
defp print_doc({ { fun, _ }, _line, kind, args, doc }) do
|
||||
args = Enum.map_join(args, ", ", print_doc_arg(&1))
|
||||
IO.puts IEx.color(:info, "* #{kind} #{fun}(#{args})\n")
|
||||
# FIXME: add tests for `doc` containing ANSI escapes
|
||||
if doc, do: IO.write IEx.color(:info, doc)
|
||||
end
|
||||
|
||||
|
||||
@@ -157,7 +157,6 @@ defmodule IEx.Server do
|
||||
end
|
||||
|
||||
defp io_put(result) do
|
||||
# FIXME: add tests for `result` containing ANSI escapes
|
||||
IO.puts IEx.color(:eval_result, inspect(result, IEx.Options.get(:inspect)))
|
||||
end
|
||||
|
||||
|
||||
@@ -3,9 +3,32 @@ Code.require_file "../test_helper.exs", __DIR__
|
||||
defmodule IEx.OptionsTest do
|
||||
use IEx.Case
|
||||
|
||||
@doc """
|
||||
Hello, I have %{red}ANSI%{reset} escapes.
|
||||
"""
|
||||
def ansi_escapes
|
||||
|
||||
test "color" do
|
||||
opts = [colors: [enabled: true, eval_result: "red"]]
|
||||
assert capture_iex("1 + 2", opts) == "\e[31m3\e[0m"
|
||||
|
||||
# Sanity checks
|
||||
assert capture_iex("IO.ANSI.escape(\"%{blue}hello\", true)", opts)
|
||||
== "\e[31m\"\\e[34mhello\\e[0m\"\e[0m"
|
||||
assert capture_iex("IO.puts IO.ANSI.escape(\"%{blue}hello\", true)", opts)
|
||||
== "\e[34mhello\e[0m\n\e[31m:ok\e[0m"
|
||||
assert capture_iex("IO.puts IO.ANSI.escape(\"%{blue}hello\", true)", [colors: [enabled: false]])
|
||||
== "\e[34mhello\e[0m\n:ok"
|
||||
|
||||
# Test that ANSI escapes in the docs are left alone
|
||||
opts = [colors: [enabled: true, info: "red", eval_result: "red"]]
|
||||
assert capture_iex("h IEx.OptionsTest.ansi_escapes", opts)
|
||||
== "\e[31m* def ansi_escapes()\n\e[0m\n\e[31mHello, I have %{red}ANSI%{reset} escapes.\n\e[0m\n\e[31m:ok\e[0m"
|
||||
|
||||
# Test that ANSI escapes in iex output are left alone
|
||||
assert capture_iex("\"%{red} %{blue}\"", opts) == "\e[31m\"%{red} %{blue}\"\e[0m"
|
||||
assert capture_iex("IO.puts IEx.color(:info, \"%{red} %{blue}\")", opts)
|
||||
== "\e[31m%{red} %{blue}\e[0m\n\e[31m:ok\e[0m"
|
||||
end
|
||||
|
||||
test "inspect opts" do
|
||||
|
||||
Reference in New Issue
Block a user