@@ -25,7 +25,8 @@ defmodule ExDoc.Formatter.MarkdownTest do
2525
2626 test "generates Markdown files in the default directory" , % { tmp_dir: tmp_dir } = context do
2727 generate ( config ( context ) )
28- assert File . regular? ( tmp_dir <> "/index.md" )
28+ assert File . regular? ( tmp_dir <> "/llms.txt" )
29+ assert File . regular? ( tmp_dir <> "/api-reference.md" )
2930
3031 assert File . regular? ( tmp_dir <> "/CompiledWithDocs.md" )
3132 assert File . regular? ( tmp_dir <> "/CompiledWithDocs.Nested.md" )
@@ -42,31 +43,34 @@ defmodule ExDoc.Formatter.MarkdownTest do
4243 content = File . read! ( tmp_dir <> "/CompiledWithDocs.md" )
4344
4445 # Header
45- assert content =~ ~r { ^ # `CompiledWithDocs`} m
46- assert content =~ ~r { \ * example_module_tag\* }
46+ assert content =~ " # `CompiledWithDocs`"
47+ assert content =~ " *example_module_tag*"
4748
4849 # Moduledoc
49- assert content =~ ~r { moduledoc}
50+ assert content =~ " moduledoc"
5051
5152 # Function header
52- assert content =~ ~r { ^ # `example`$ } m
53+ assert content =~ " # `example`"
5354
5455 # Function documentation
55- assert content =~ ~r { Some example}
56+ assert content =~ " Some example"
5657
5758 # Deprecated notice
58- assert content =~ ~r { > This function is deprecated\ . Use something else instead\. }
59+ assert content =~ " > This function is deprecated. Use something else instead."
5960
6061 # Struct
61- assert content =~ ~r { ^ # `__struct__`$ } m
62- assert content =~ ~r { Some struct}
62+ assert content =~ " # `__struct__`"
63+ assert content =~ " Some struct"
6364
6465 # Since annotation
65- assert content =~ ~r { ^ # `example_1`$ } m
66- assert content =~ ~r { \ * since 1\. 3 \. 0 \* }
66+ assert content =~ " # `example_1`"
67+ assert content =~ " *since 1.3.0*"
6768
6869 # Macro annotation
69- assert content =~ ~r{ \* macro\* }
70+ assert content =~ "*macro*"
71+
72+ # Footer should be present when api_reference defaults to true
73+ assert content =~ "Consult [api-reference.md]"
7074 end
7175
7276 test "renders types and specs properly" , % { tmp_dir: tmp_dir } = context do
@@ -131,34 +135,48 @@ defmodule ExDoc.Formatter.MarkdownTest do
131135 config = config ( context , output: custom_output )
132136 generate ( config )
133137
134- assert File . regular? ( custom_output <> "/index.md " )
138+ assert File . regular? ( custom_output <> "/llms.txt " )
135139 assert File . regular? ( custom_output <> "/CompiledWithDocs.md" )
136- refute File . exists? ( tmp_dir <> "/index.md " )
140+ refute File . exists? ( tmp_dir <> "/llms.txt " )
137141 end
138142
139143 test "handles custom project name and version" , % { tmp_dir: tmp_dir } = context do
140144 config = config ( context , project: "MyProject" , version: "2.0.0" )
141145 generate ( config )
142146
143- content = File . read! ( tmp_dir <> "/index.md " )
147+ content = File . read! ( tmp_dir <> "/llms.txt " )
144148 assert content =~ "# MyProject v2.0.0 - Table of Contents"
145149 end
150+ end
146151
147- test "processes source_url configuration" , % { tmp_dir: tmp_dir } = context do
148- config = config ( context , source_url: "https://github.com/example/project" )
149- generate ( config )
152+ test "stores generated content in .build.markdown" , % { tmp_dir: tmp_dir } = context do
153+ config = config ( context , extras: [ "test/fixtures/README.md" ] )
154+ generate ( config )
155+
156+ # Verify necessary files in .build.markdown
157+ content = File . read! ( tmp_dir <> "/.build.markdown" )
158+ assert content =~ "readme.md"
159+ assert content =~ "llms.txt"
160+ assert content =~ "CompiledWithDocs.md"
161+ assert content =~ "Mix.Tasks.TaskWithDocs.md"
162+
163+ # Verify the files listed in .build.markdown actually exist
164+ files =
165+ content
166+ |> String . split ( "\n " , trim: true )
167+ |> Enum . map ( & Path . join ( tmp_dir , & 1 ) )
150168
151- assert File . regular? ( tmp_dir <> "/CompiledWithDocs.md" )
152- assert File . regular? ( tmp_dir <> "/index.md" )
169+ for file <- files do
170+ assert File . exists? ( file )
153171 end
154172 end
155173
156- describe "index file " do
174+ describe "llms.txt " do
157175 test "generates index" , % { tmp_dir: tmp_dir } = context do
158176 config = config ( context , extras: [ "test/fixtures/README.md" ] , extra_section: "Guides" )
159177 generate ( config )
160178
161- content = File . read! ( tmp_dir <> "/index.md " )
179+ content = File . read! ( tmp_dir <> "/llms.txt " )
162180
163181 assert content =~ "# Elixir v1.0.1 - Table of Contents"
164182
@@ -193,30 +211,62 @@ defmodule ExDoc.Formatter.MarkdownTest do
193211 test "when no extras exist" , % { tmp_dir: tmp_dir } = context do
194212 config = config ( context )
195213 generate ( config )
196- content = File . read! ( tmp_dir <> "/index.md" )
197- refute content =~ ~r/ ## (Pages|Guides)/
214+ content = File . read! ( tmp_dir <> "/llms.txt" )
215+ refute content =~ "## Pages"
216+ refute content =~ "## Guides"
198217 end
199218 end
200219
201- test "stores generated content in .build.markdown" , % { tmp_dir: tmp_dir } = context do
202- config = config ( context , extras: [ "test/fixtures/README.md" ] )
203- generate ( config )
220+ describe "api_reference" do
221+ test "when false, does not generate api-reference.md" , % { tmp_dir: tmp_dir } = context do
222+ config = config ( context , api_reference: false )
223+ generate ( config )
224+ refute File . exists? ( tmp_dir <> "/api-reference.md" )
204225
205- # Verify necessary files in .build.markdown
206- content = File . read! ( tmp_dir <> "/.build.markdown" )
207- assert content =~ ~r( ^readme\. md$) m
208- assert content =~ ~r( ^index\. md$) m
209- assert content =~ ~r( ^CompiledWithDocs\. md$) m
210- assert content =~ ~r( ^Mix\. Tasks\. TaskWithDocs\. md$) m
226+ # Modules should not have the footer
227+ content = File . read! ( tmp_dir <> "/CompiledWithDocs.md" )
228+ refute content =~ "Consult [api-reference.md]"
229+ end
211230
212- # Verify the files listed in .build.markdown actually exist
213- files =
214- content
215- |> String . split ( "\n " , trim: true )
216- |> Enum . map ( & Path . join ( tmp_dir , & 1 ) )
231+ test "when true, generates api-reference.md" , % { tmp_dir: tmp_dir } = context do
232+ config =
233+ config ( context ,
234+ extras: [ "test/fixtures/README.md" ] ,
235+ extra_section: "Guides" ,
236+ api_reference: true
237+ )
217238
218- for file <- files do
219- assert File . exists? ( file )
239+ generate ( config )
240+ api_content = File . read! ( tmp_dir <> "/api-reference.md" )
241+
242+ # Should have API Reference title
243+ assert api_content =~ "# Elixir v1.0.1 - API Reference"
244+
245+ # Should NOT include extras section
246+ refute api_content =~ "## Guides"
247+ refute api_content =~ "README"
248+
249+ # Should include modules section
250+ assert api_content =~ """
251+ ## Modules
252+
253+ - [CallbacksNoDocs](CallbacksNoDocs.md)
254+ - [Common.Nesting.Prefix.B.A](Common.Nesting.Prefix.B.A.md): moduledoc
255+ """
256+
257+ # Should include mix tasks
258+ assert api_content =~ """
259+ ## Mix Tasks
260+
261+ - [mix task_with_docs](Mix.Tasks.TaskWithDocs.md): Very useful task
262+ """
263+
264+ # Modules should have the footer
265+ module_content = File . read! ( tmp_dir <> "/CompiledWithDocs.md" )
266+ assert module_content =~ "---"
267+
268+ assert module_content =~
269+ "*Consult [api-reference.md](api-reference.md) for complete listing*"
220270 end
221271 end
222272end
0 commit comments