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