diff --git a/mix.exs b/mix.exs index 710c5b689..4ef85916f 100644 --- a/mix.exs +++ b/mix.exs @@ -35,7 +35,8 @@ defmodule ExDoc.Mixfile do {:earmark_parser, "~> 1.4.19"}, {:makeup_elixir, "~> 0.14"}, {:makeup_erlang, "~> 0.1"}, - {:jason, "~> 1.2", only: :test} + {:jason, "~> 1.2", only: :test}, + {:floki, "~> 0.0", only: :test} ] end diff --git a/mix.lock b/mix.lock index 45be1256d..af9b7e73a 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,10 @@ %{ "earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"}, + "floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"}, + "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, "jason": {:hex, :jason, "1.2.0", "10043418c42d2493d0ee212d3fddd25d7ffe484380afad769a0a38795938e448", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "116747dbe057794c3a3e4e143b7c8390b29f634e16c78a7f59ba75bfa6852e7f"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "811e32fb77aabb2b5b6196b21f76fe6ba8b6861c3d8c9eaeedbbf1f4cda627d1", [:mix], [], "hexpm", "dd3504559b0ddfeb7f55297557313fc05340120a037f981a4775b1c43e61d1b9"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"}, } diff --git a/test/ex_doc/formatter/html/erlang_test.exs b/test/ex_doc/formatter/html/erlang_test.exs new file mode 100644 index 000000000..d840a86f2 --- /dev/null +++ b/test/ex_doc/formatter/html/erlang_test.exs @@ -0,0 +1,45 @@ +defmodule ExDoc.Formatter.HTML.ErlangTest do + use ExUnit.Case + import TestHelper + setup :create_tmp_dir + + @moduletag :otp24 + + test "it works", c do + erlc(c, :foo, ~S""" + %% @doc + %% foo module. + -module(foo). + -export([foo/1]). + -export_type([t/0]). + + %% @doc + %% f/0 function. + -spec foo(atom()) -> atom(). + foo(X) -> X. + + -type t() :: atom(). + %% t/0 type. + """) + + doc = generate_docs(c) + + assert [_] = Floki.find(doc, "pre:fl-contains('foo(atom()) -> atom().')") + + assert [_] = Floki.find(doc, "pre:fl-contains('t() :: atom().')") + end + + defp generate_docs(c) do + config = [ + version: "1.0.0", + project: "Foo", + formatter: "html", + output: Path.join(c.tmp_dir, "doc"), + source_beam: Path.join(c.tmp_dir, "ebin"), + extras: [] + ] + + ExDoc.generate_docs(config[:project], config[:version], config) + [c.tmp_dir, "doc", "foo.html"] |> Path.join() |> File.read!() |> Floki.parse_document!() + end +end