Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :otp_eep48 and :otp_has_docs tags #1516

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,12 @@ defmodule ExDoc.Language.Elixir do
defp parse_function("__block__"), do: {:function, :__block__}

defp parse_function(string) do
case Code.string_to_quoted(string <> "/0") do
{:ok, {:/, _, [{function, _, _}, 0]}} when is_atom(function) -> {:function, function}
_ -> :error
case Code.string_to_quoted("& #{string}/0") do
{:ok, {:&, _, [{:/, _, [{function, _, _}, 0]}]}} when is_atom(function) ->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on Elixir 1.11 we had:

iex> Code.string_to_quoted("+/2")
{:error, {[line: 1, column: 2], "syntax error before: ", "'/'"}}

adding capture fixes it:

iex> Code.string_to_quoted("& +/2")
{:ok, {:&, [line: 1], [{:/, [line: 1], [{:+, [line: 1], nil}, 2]}]}}

{:function, function}

_ ->
:error
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/formatter/html/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
use ExUnit.Case
import TestHelper

@moduletag :otp24
@moduletag :otp_eep48
@moduletag :tmp_dir

test "it works", c do
Expand Down
4 changes: 3 additions & 1 deletion test/ex_doc/language/elixir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ defmodule ExDoc.Language.ElixirTest do
assert_unchanged("bar/1", current_module: AutolinkTest.Foo)
end

@tag :otp24
test "auto-imported function" do
assert autolink_doc("+/2") ==
~m"[`+/2`](https://hexdocs.pm/elixir/Kernel.html#+/2)"

assert autolink_doc("&/1") ==
~m"[`&/1`](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#&/1)"

assert autolink_doc("for/1") ==
~m"[`for/1`](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#for/1)"

Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/language/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ExDoc.Language.ErlangTest do
use ExUnit.Case
import TestHelper

@moduletag :otp24
@moduletag :otp_has_docs
@moduletag :tmp_dir

describe "autolink_doc/2" do
Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/retriever/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExDoc.Retriever.ErlangTest do
alias ExDoc.{Retriever, DocAST, Language.Erlang}
import TestHelper

@moduletag :otp24
@moduletag :otp_eep48
@moduletag :tmp_dir

describe "docs_from_modules/2" do
Expand Down
7 changes: 5 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
otp_eep48? = Code.ensure_loaded?(:edoc_doclet_chunks)

exclude = [
earmark: not ExDoc.Markdown.Earmark.available?(),
otp24: System.otp_release() < "24"
otp_eep48: not otp_eep48?,
otp_has_docs: not match?({:docs_v1, _, _, _, _, _, _}, Code.fetch_docs(:array))
]

ExUnit.start(exclude: Enum.filter(exclude, &elem(&1, 1)))
Expand Down Expand Up @@ -71,7 +74,7 @@ defmodule TestHelper do
:ok
end

if Code.ensure_loaded?(:edoc_doclet_chunks) do
if otp_eep48? do
def edoc_to_chunk(module) do
source_path = module.module_info(:compile)[:source]
dir = :filename.dirname(source_path)
Expand Down