1
1
defmodule ExDoc.Language.ErlangTest do
2
2
# ExDoc.Refs is global
3
3
use ExUnit.Case , async: false
4
-
5
4
import TestHelper
6
5
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
+
7
25
@ moduletag :otp_has_docs
8
26
@ moduletag :tmp_dir
9
27
@@ -56,14 +74,14 @@ defmodule ExDoc.Language.ErlangTest do
56
74
{ :a , [ href: "array#anchor" , rel: "https://erlang.org/doc/link/seeerl" ] ,
57
75
[ { :code , [ ] , [ "array" ] , % { } } ] , % { } }
58
76
59
- assert do_autolink_doc ( ast ) ==
77
+ assert autolink ( ast ) ==
60
78
~s| <a href="https://www.erlang.org/doc/apps/stdlib/array.html#anchor"><code>array</code></a>|
61
79
62
80
ast =
63
81
{ :a , [ href: "stdlib:array#anchor" , rel: "https://erlang.org/doc/link/seeerl" ] ,
64
82
[ { :code , [ ] , [ "array" ] , % { } } ] , % { } }
65
83
66
- assert do_autolink_doc ( ast ) ==
84
+ assert autolink ( ast ) ==
67
85
~s| <a href="https://www.erlang.org/doc/apps/stdlib/array.html#anchor"><code>array</code></a>|
68
86
end
69
87
@@ -339,12 +357,14 @@ defmodule ExDoc.Language.ErlangTest do
339
357
end
340
358
341
359
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
348
368
end
349
369
350
370
test "linking to local nil function works" , c do
@@ -359,8 +379,7 @@ defmodule ExDoc.Language.ErlangTest do
359
379
test "linking to exported nil function works" , c do
360
380
assert autolink_doc (
361
381
"[`nil`](`erlang_bar:nil/0`)" ,
362
- c ,
363
- extra_bar_code: "-export([nil/0]).\n nil() -> [].\n "
382
+ c
364
383
) ==
365
384
~s| <a href="erlang_bar.html#nil/0"><code class="inline">nil</code></a>|
366
385
end
@@ -537,8 +556,8 @@ defmodule ExDoc.Language.ErlangTest do
537
556
538
557
describe "autolink_doc/2 for extra" do
539
558
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>|
542
561
end
543
562
544
563
test "OTP function" , c do
@@ -557,8 +576,8 @@ defmodule ExDoc.Language.ErlangTest do
557
576
end
558
577
559
578
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>|
562
581
end
563
582
564
583
test "OTP module" , c do
@@ -830,13 +849,11 @@ defmodule ExDoc.Language.ErlangTest do
830
849
end
831
850
end
832
851
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
836
853
opts =
837
854
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 } )
840
857
841
858
{ :ok , tokens , _ } = :erl_scan . string ( String . to_charlist ( binary ) )
842
859
{ :ok , ast } = :erl_parse . parse_form ( tokens )
@@ -845,14 +862,10 @@ defmodule ExDoc.Language.ErlangTest do
845
862
end
846
863
847
864
defp autolink_extra ( text , c ) do
848
- # Markdown is usually not valid EDoc
849
- fixtures ( c , "" )
850
-
851
865
[ { :p , _ , [ ast ] , _ } ] = ExDoc.Markdown . to_ast ( text , [ ] )
852
-
853
866
opts = c |> Map . take ( [ :warnings ] ) |> Enum . to_list ( )
854
867
855
- do_autolink_doc (
868
+ autolink (
856
869
ast ,
857
870
[ current_module: nil , file: nil , module_id: nil , file: "extra.md" ] ++ opts
858
871
)
@@ -869,8 +882,7 @@ defmodule ExDoc.Language.ErlangTest do
869
882
end
870
883
871
884
opts = Keyword . merge ( opts , c |> Map . take ( [ :warnings ] ) |> Enum . to_list ( ) )
872
-
873
- do_autolink_doc ( ast , opts )
885
+ autolink ( ast , opts )
874
886
end
875
887
876
888
defp autolink_edoc ( doc , c , opts \\ [ ] ) do
@@ -884,15 +896,15 @@ defmodule ExDoc.Language.ErlangTest do
884
896
html =
885
897
doc
886
898
|> ExDoc.DocAST . parse! ( "application/erlang+html" )
887
- |> do_autolink_doc ( opts )
899
+ |> autolink ( opts )
888
900
889
901
# OTP 27 wraps edoc in <p></p>
890
902
html
891
903
|> String . trim_leading ( "<p>" )
892
904
|> String . trim_trailing ( "</p>" )
893
905
end
894
906
895
- defp do_autolink_doc ( doc , opts \\ [ ] ) do
907
+ defp autolink ( doc , opts \\ [ ] ) do
896
908
opts =
897
909
opts
898
910
|> Keyword . put ( :language , ExDoc.Language.Erlang )
@@ -901,7 +913,7 @@ defmodule ExDoc.Language.ErlangTest do
901
913
|> Keyword . put_new ( :file , "erlang_foo.erl" )
902
914
|> Keyword . put_new ( :module_id , "erlang_foo" )
903
915
|> Keyword . put_new ( :deps , foolib: "https://foolib.com" )
904
- |> Keyword . drop ( [ :extra_foo_code , :extra_bar_code ] )
916
+ |> Keyword . drop ( [ :extra_foo_code ] )
905
917
906
918
doc
907
919
|> ExDoc.Language.Erlang . autolink_doc ( opts )
@@ -923,9 +935,8 @@ defmodule ExDoc.Language.ErlangTest do
923
935
message
924
936
end
925
937
926
- defp fixtures ( c , doc , opts \\ [ ] ) do
938
+ defp fixtures ( c , doc , opts ) do
927
939
:code . purge ( :erlang_foo )
928
- :code . purge ( :erlang_bar )
929
940
930
941
erlc ( c , :erlang_foo , """
931
942
%% @doc
@@ -938,14 +949,5 @@ defmodule ExDoc.Language.ErlangTest do
938
949
#{ opts [ :extra_foo_code ] }
939
950
foo() -> ok.
940
951
""" )
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
- """ )
950
952
end
951
953
end
0 commit comments