11defmodule ExDoc.Language.ErlangTest do
22 # ExDoc.Refs is global
33 use ExUnit.Case , async: false
4-
54 import TestHelper
65
6+ setup_all c do
7+ # erlang_bar is shared across all tests.
8+ # Each test defines an erlang_foo for their specific purposes.
9+ :code . purge ( :erlang_bar )
10+
11+ c
12+ |> Map . put ( :tmp_dir , "test/tmp/#{ inspect ( __MODULE__ ) } " )
13+ |> erlc ( :erlang_bar , """
14+ -module(erlang_bar).
15+ -export([bar/0, nil/0]).
16+ -export_type([t/0]).
17+ -type t() :: atom().
18+ nil() -> [].
19+ bar() -> ok.
20+ """ )
21+
22+ :ok
23+ end
24+
725 @ moduletag :otp_has_docs
826 @ moduletag :tmp_dir
927
@@ -56,14 +74,14 @@ defmodule ExDoc.Language.ErlangTest do
5674 { :a , [ href: "array#anchor" , rel: "https://erlang.org/doc/link/seeerl" ] ,
5775 [ { :code , [ ] , [ "array" ] , % { } } ] , % { } }
5876
59- assert do_autolink_doc ( ast ) ==
77+ assert autolink ( ast ) ==
6078 ~s| <a href="https://www.erlang.org/doc/apps/stdlib/array.html#anchor"><code>array</code></a>|
6179
6280 ast =
6381 { :a , [ href: "stdlib:array#anchor" , rel: "https://erlang.org/doc/link/seeerl" ] ,
6482 [ { :code , [ ] , [ "array" ] , % { } } ] , % { } }
6583
66- assert do_autolink_doc ( ast ) ==
84+ assert autolink ( ast ) ==
6785 ~s| <a href="https://www.erlang.org/doc/apps/stdlib/array.html#anchor"><code>array</code></a>|
6886 end
6987
@@ -339,12 +357,14 @@ defmodule ExDoc.Language.ErlangTest do
339357 end
340358
341359 test "linking to local nil works" , c do
342- assert autolink_doc (
343- "[`[]`](`t:nil/0`)" ,
344- c ,
345- extra_foo_code: "-export_type([nil/0]).\n -type nil() :: [].\n "
346- ) ==
347- ~s| <a href="#t:nil/0"><code class="inline">[]</code></a>|
360+ if :erlang . system_info ( :otp_release ) >= ~c" 26" do
361+ assert autolink_doc (
362+ "[`[]`](`t:nil/0`)" ,
363+ c ,
364+ extra_foo_code: "-export_type([nil/0]).\n -type nil() :: [].\n "
365+ ) ==
366+ ~s| <a href="#t:nil/0"><code class="inline">[]</code></a>|
367+ end
348368 end
349369
350370 test "linking to local nil function works" , c do
@@ -359,8 +379,7 @@ defmodule ExDoc.Language.ErlangTest do
359379 test "linking to exported nil function works" , c do
360380 assert autolink_doc (
361381 "[`nil`](`erlang_bar:nil/0`)" ,
362- c ,
363- extra_bar_code: "-export([nil/0]).\n nil() -> [].\n "
382+ c
364383 ) ==
365384 ~s| <a href="erlang_bar.html#nil/0"><code class="inline">nil</code></a>|
366385 end
@@ -537,8 +556,8 @@ defmodule ExDoc.Language.ErlangTest do
537556
538557 describe "autolink_doc/2 for extra" do
539558 test "function" , c do
540- assert autolink_extra ( "`erlang_foo:foo /0`" , c ) ==
541- ~s| <a href="erlang_foo .html#foo /0"><code class="inline">erlang_foo:foo /0</code></a>|
559+ assert autolink_extra ( "`erlang_bar:bar /0`" , c ) ==
560+ ~s| <a href="erlang_bar .html#bar /0"><code class="inline">erlang_bar:bar /0</code></a>|
542561 end
543562
544563 test "OTP function" , c do
@@ -557,8 +576,8 @@ defmodule ExDoc.Language.ErlangTest do
557576 end
558577
559578 test "module" , c do
560- assert autolink_extra ( "`m:erlang_foo `" , c ) ==
561- ~s| <a href="erlang_foo .html"><code class="inline">erlang_foo </code></a>|
579+ assert autolink_extra ( "`m:erlang_bar `" , c ) ==
580+ ~s| <a href="erlang_bar .html"><code class="inline">erlang_bar </code></a>|
562581 end
563582
564583 test "OTP module" , c do
@@ -830,13 +849,11 @@ defmodule ExDoc.Language.ErlangTest do
830849 end
831850 end
832851
833- defp autolink_spec ( binary , c , opts \\ [ ] ) when is_binary ( binary ) do
834- fixtures ( c , "" )
835-
852+ defp autolink_spec ( binary , _c , opts \\ [ ] ) when is_binary ( binary ) do
836853 opts =
837854 opts
838- |> Keyword . put_new ( :current_module , :erlang_foo )
839- |> Keyword . put_new ( :current_kfa , { :function , :foo , 1 } )
855+ |> Keyword . put_new ( :current_module , :erlang_bar )
856+ |> Keyword . put_new ( :current_kfa , { :function , :bar , 1 } )
840857
841858 { :ok , tokens , _ } = :erl_scan . string ( String . to_charlist ( binary ) )
842859 { :ok , ast } = :erl_parse . parse_form ( tokens )
@@ -845,14 +862,10 @@ defmodule ExDoc.Language.ErlangTest do
845862 end
846863
847864 defp autolink_extra ( text , c ) do
848- # Markdown is usually not valid EDoc
849- fixtures ( c , "" )
850-
851865 [ { :p , _ , [ ast ] , _ } ] = ExDoc.Markdown . to_ast ( text , [ ] )
852-
853866 opts = c |> Map . take ( [ :warnings ] ) |> Enum . to_list ( )
854867
855- do_autolink_doc (
868+ autolink (
856869 ast ,
857870 [ current_module: nil , file: nil , module_id: nil , file: "extra.md" ] ++ opts
858871 )
@@ -869,8 +882,7 @@ defmodule ExDoc.Language.ErlangTest do
869882 end
870883
871884 opts = Keyword . merge ( opts , c |> Map . take ( [ :warnings ] ) |> Enum . to_list ( ) )
872-
873- do_autolink_doc ( ast , opts )
885+ autolink ( ast , opts )
874886 end
875887
876888 defp autolink_edoc ( doc , c , opts \\ [ ] ) do
@@ -884,15 +896,15 @@ defmodule ExDoc.Language.ErlangTest do
884896 html =
885897 doc
886898 |> ExDoc.DocAST . parse! ( "application/erlang+html" )
887- |> do_autolink_doc ( opts )
899+ |> autolink ( opts )
888900
889901 # OTP 27 wraps edoc in <p></p>
890902 html
891903 |> String . trim_leading ( "<p>" )
892904 |> String . trim_trailing ( "</p>" )
893905 end
894906
895- defp do_autolink_doc ( doc , opts \\ [ ] ) do
907+ defp autolink ( doc , opts \\ [ ] ) do
896908 opts =
897909 opts
898910 |> Keyword . put ( :language , ExDoc.Language.Erlang )
@@ -901,7 +913,7 @@ defmodule ExDoc.Language.ErlangTest do
901913 |> Keyword . put_new ( :file , "erlang_foo.erl" )
902914 |> Keyword . put_new ( :module_id , "erlang_foo" )
903915 |> Keyword . put_new ( :deps , foolib: "https://foolib.com" )
904- |> Keyword . drop ( [ :extra_foo_code , :extra_bar_code ] )
916+ |> Keyword . drop ( [ :extra_foo_code ] )
905917
906918 doc
907919 |> ExDoc.Language.Erlang . autolink_doc ( opts )
@@ -923,9 +935,8 @@ defmodule ExDoc.Language.ErlangTest do
923935 message
924936 end
925937
926- defp fixtures ( c , doc , opts \\ [ ] ) do
938+ defp fixtures ( c , doc , opts ) do
927939 :code . purge ( :erlang_foo )
928- :code . purge ( :erlang_bar )
929940
930941 erlc ( c , :erlang_foo , """
931942 %% @doc
@@ -938,14 +949,5 @@ defmodule ExDoc.Language.ErlangTest do
938949 #{ opts [ :extra_foo_code ] }
939950 foo() -> ok.
940951 """ )
941-
942- erlc ( c , :erlang_bar , """
943- -module(erlang_bar).
944- -export([bar/0]).
945- -export_type([t/0]).
946- -type t() :: atom().
947- #{ opts [ :extra_bar_code ] }
948- bar() -> ok.
949- """ )
950952 end
951953end
0 commit comments