Skip to content

Commit f98afc1

Browse files
author
Thomaz Leite
committed
Fix IO.ANSI.Docs and its corresponding test
1 parent 6b407a3 commit f98afc1

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule IEx.ANSIDocs do
1+
defmodule IO.ANSI.Docs do
22
@moduledoc false
33

44
@bullets [?*, ?-, ?+]

lib/elixir/test/elixir/io/ansi/docs_test.exs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Code.require_file "../test_helper.exs", __DIR__
1+
Code.require_file "../../test_helper.exs", __DIR__
22

3-
defmodule IEx.AnsiDocsTest do
4-
use IEx.Case
3+
defmodule IO.ANSI.DocsTest do
4+
use ExUnit.Case, async: true
5+
import ExUnit.CaptureIO
56

67
@colors [ enabled: true,
78
doc_code: "cyan,bright",
@@ -11,19 +12,23 @@ defmodule IEx.AnsiDocsTest do
1112
doc_headings: "yellow,bright",
1213
doc_title: "reverse,yellow,bright" ]
1314

14-
@opts [colors: @colors]
15+
def format_heading(str, use_ansi // true) do
16+
capture_io(fn -> IO.ANSI.Docs.print_heading(str, use_ansi, @colors) end)
17+
|> String.strip
18+
end
1519

1620
def format(str, use_ansi // true) do
17-
cmd = "IEx.ANSIDocs.print(#{inspect str}, #{inspect use_ansi}, #{inspect @colors})"
18-
capture_iex(cmd, @opts)
21+
capture_io(fn -> IO.ANSI.Docs.print(str, use_ansi, @colors) end)
22+
|> String.strip
1923
end
2024

2125
test "non-ansi heading just uses an asterisk" do
22-
assert capture_iex("IEx.ANSIDocs.print_heading(\"wibble\", false)", []) == "* wibble"
26+
result = format_heading("wibble", false)
27+
assert result == "* wibble"
2328
end
2429

2530
test "ansi heading is formatted" do
26-
result = capture_iex("IEx.ANSIDocs.print_heading(\"wibble\", true, #{inspect @colors})", @opts)
31+
result = format_heading("wibble", true)
2732
assert String.starts_with?(result, "\e[0m\n\e[7m\e[33m\e[1m")
2833
assert String.ends_with?(result, "\e[0m\n\e[0m")
2934
assert String.contains?(result, " wibble ")

0 commit comments

Comments
 (0)