Skip to content

Commit eee7407

Browse files
committed
Add config test for groups_for_modules
1 parent af30285 commit eee7407

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: test/ex_doc/config_test.exs

+38
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,43 @@ defmodule ExDoc.ConfigTest do
113113
config = build(source_url_pattern: "a%{line}b%{path}c")
114114
assert config.source_url_pattern.("foo.ex", 123) == "a123bfoo.exc"
115115
end
116+
117+
test "groups_for_modules" do
118+
# Using real applications, since we load them to extract the corresponding list of modules
119+
stdlib = :stdlib
120+
kernel = :kernel
121+
custom_group = :custom_group
122+
123+
groups_for_modules = fn config, key ->
124+
List.keyfind(config.groups_for_modules, to_string(key), 0)
125+
end
126+
127+
# Single app, no custom grouping
128+
config = build(apps: [stdlib])
129+
assert groups_for_modules.(config, stdlib) == nil
130+
assert groups_for_modules.(config, custom_group) == nil
131+
132+
# Single app, custom grouping
133+
config = build(apps: [stdlib], groups_for_modules: [{"custom_group", ["module_1"]}])
134+
assert groups_for_modules.(config, stdlib) == nil
135+
assert groups_for_modules.(config, custom_group) == {"custom_group", ["module_1"]}
136+
137+
# Multiple apps, no custom grouping
138+
config = build(apps: [stdlib, kernel])
139+
stdlib_groups = groups_for_modules.(config, stdlib)
140+
kernel_groups = groups_for_modules.(config, kernel)
141+
assert match?({"stdlib", _}, stdlib_groups)
142+
assert match?({"kernel", _}, kernel_groups)
143+
{"stdlib", stdlib_modules} = stdlib_groups
144+
{"kernel", kernel_modules} = kernel_groups
145+
assert Enum.member?(stdlib_modules, :gen_server)
146+
assert Enum.member?(kernel_modules, :file)
147+
148+
# Multiple apps, custom grouping
149+
config = build(apps: [stdlib, kernel], groups_for_modules: [{"custom_group", ["module_1"]}])
150+
assert groups_for_modules.(config, stdlib) == nil
151+
assert groups_for_modules.(config, kernel) == nil
152+
assert groups_for_modules.(config, custom_group) == {"custom_group", ["module_1"]}
153+
end
116154
end
117155
end

0 commit comments

Comments
 (0)