Skip to content

Commit

Permalink
Add unit tests for automatic group detection
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 30, 2020
1 parent 1fd03cd commit 0ee78fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/ex_doc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ defmodule ExDoc do
find_formatter(config.formatter).run(docs, config)
end

# Builds configuration by merging `options`, and normalizing the options.
@doc false
@spec build_config(String.t(), String.t(), Keyword.t()) :: ExDoc.Config.t()
defp build_config(project, vsn, options) do
def build_config(project, vsn, options) do
{output, options} = Keyword.pop(options, :output, "./doc")
{groups_for_modules, options} = Keyword.pop(options, :groups_for_modules, [])
{nest_modules_by_prefix, options} = Keyword.pop(options, :nest_modules_by_prefix, [])
Expand Down
9 changes: 0 additions & 9 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,6 @@ defmodule ExDoc.Formatter.HTMLTest do
~r{"id":"Common\.Nesting\.Prefix\.Bar","nested_context":"Common\.Nesting\.Prefix","nested_title":"Bar","title":"Common\.Nesting\.Prefix\.Bar"}ms
end

test "groups exceptions" do
generate_docs(doc_config())

content = read_wildcard!("#{output_dir()}/dist/sidebar_items-*.js")

assert content =~
~r{"group":"Exceptions","id":"RandomError","title":"RandomError"}ms
end

describe "generates logo" do
test "overriding previous entries" do
File.mkdir_p!("#{output_dir()}/assets")
Expand Down
26 changes: 21 additions & 5 deletions test/ex_doc/retriever_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ defmodule ExDoc.RetrieverTest do
defp docs_from_files(names, config \\ []) do
files = Enum.map(names, fn n -> "test/tmp/Elixir.#{n}.beam" end)

default = %ExDoc.Config{
source_url_pattern: "http://example.com/%{path}#L%{line}",
source_root: File.cwd!()
}
config =
ExDoc.build_config(
"foobar",
"0.1",
Keyword.merge(
[
source_url_pattern: "http://example.com/%{path}#L%{line}",
source_root: File.cwd!()
],
config
)
)

Retriever.docs_from_files(files, struct(default, config))
Retriever.docs_from_files(files, config)
end

describe "docs_from_dir" do
Expand Down Expand Up @@ -229,6 +237,14 @@ defmodule ExDoc.RetrieverTest do
test "are properly tagged" do
[module_node] = docs_from_files(["RandomError"])
assert module_node.type == :exception
assert module_node.group == :Exceptions
end
end

describe "deprecated" do
test "are properly tagged" do
[module_node] = docs_from_files(["Warnings"])
assert module_node.group == :Deprecated
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/warnings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Warnings do
`Warnings.bar/0`
"""

@moduledoc deprecated: "Use something without warnings"

@typedoc """
`Warnings.bar/0`
"""
Expand Down

0 comments on commit 0ee78fa

Please sign in to comment.