@@ -34,6 +34,24 @@ const MYCONST = 42
3434
3535end
3636
37+ module DRTypeFormatTestMod
38+ struct Simple end
39+ struct Parametric{T} end
40+ struct WithValue{T,N} end
41+ end
42+
43+ module DRMethodTestMod
44+ f () = 1
45+ f (x:: Int ) = x
46+ g (x:: Int , y:: String ) = x
47+ h (xs:: Int... ) = length (xs)
48+ end
49+
50+ module DRExternalTestMod
51+ extfun (x:: Int ) = x
52+ extfun (x:: String ) = length (x)
53+ end
54+
3755using . DocumenterReferenceTestMod
3856
3957function test_documenter_reference ()
@@ -413,4 +431,138 @@ function test_documenter_reference()
413431 DR. reset_config! ()
414432 @test isempty (DR. CONFIG)
415433 end
434+
435+ @testset " _format_type_for_docs and helpers" begin
436+ simple_str = DR. _format_type_for_docs (DRTypeFormatTestMod. Simple)
437+ @test startswith (simple_str, " ::" )
438+ @test occursin (" DRTypeFormatTestMod.Simple" , simple_str)
439+
440+ param_type = DRTypeFormatTestMod. Parametric{DRTypeFormatTestMod. Simple}
441+ param_str = DR. _format_type_for_docs (param_type)
442+ @test occursin (" Parametric" , param_str)
443+ @test occursin (" Simple" , param_str)
444+
445+ union_str = DR. _format_type_for_docs (Union{DRTypeFormatTestMod. Simple, Nothing})
446+ @test occursin (" Union" , union_str)
447+ @test occursin (" Simple" , union_str)
448+ @test occursin (" Nothing" , union_str)
449+
450+ value_type = DRTypeFormatTestMod. WithValue{Int, 3 }
451+ value_str = DR. _format_type_for_docs (value_type)
452+ @test occursin (" WithValue" , value_str)
453+ @test occursin (" 3" , value_str)
454+
455+ param_fmt = DR. _format_type_param (DRTypeFormatTestMod. Simple)
456+ @test occursin (" DRTypeFormatTestMod.Simple" , param_fmt)
457+
458+ value_param_fmt = DR. _format_type_param (3 )
459+ @test value_param_fmt == " 3"
460+ end
461+
462+ @testset " _method_signature_string and method collection" begin
463+ methods_f = methods (DRMethodTestMod. f)
464+ m0 = first (filter (m -> length (m. sig. parameters) == 1 , methods_f))
465+ sig0 = DR. _method_signature_string (m0, DRMethodTestMod, :f )
466+ @test endswith (sig0, " DRMethodTestMod.f()" )
467+
468+ m1 = first (filter (m -> length (m. sig. parameters) == 2 , methods_f))
469+ sig1 = DR. _method_signature_string (m1, DRMethodTestMod, :f )
470+ @test occursin (" DRMethodTestMod.f" , sig1)
471+ @test occursin (" Int" , sig1)
472+
473+ methods_h = methods (DRMethodTestMod. h)
474+ mvar = first (methods_h)
475+ sigv = DR. _method_signature_string (mvar, DRMethodTestMod, :h )
476+ @test occursin (" Vararg" , sigv)
477+
478+ source_files = [abspath (@__FILE__ )]
479+ methods_by_func = DR. _collect_methods_from_source_files (DRMethodTestMod, source_files)
480+ @test :f in keys (methods_by_func)
481+ @test :h in keys (methods_by_func)
482+ for ms in values (methods_by_func)
483+ for m in ms
484+ file = String (m. file)
485+ @test abspath (file) in source_files
486+ end
487+ end
488+ end
489+
490+ @testset " Page content builders" begin
491+ modules_str = " ModA, ModB"
492+ module_contents_private = [
493+ (DocumenterReferenceTestMod, String[], [" priv_a" ]),
494+ (DRMethodTestMod, String[], [" priv_b1" , " priv_b2" ]),
495+ ]
496+ overview_priv, docs_priv = DR. _build_private_page_content (modules_str, module_contents_private)
497+ @test occursin (" Private API" , overview_priv)
498+ @test occursin (" ModA, ModB" , overview_priv)
499+ @test ! isempty (docs_priv)
500+ @test any (occursin (" priv_a" , s) for s in docs_priv)
501+ @test any (occursin (" priv_b1" , s) for s in docs_priv)
502+
503+ module_contents_public = [
504+ (DocumenterReferenceTestMod, [" pub_a" ], String[]),
505+ (DRMethodTestMod, String[], String[]),
506+ ]
507+ overview_pub, docs_pub = DR. _build_public_page_content (modules_str, module_contents_public)
508+ @test occursin (" Public API" , overview_pub)
509+ @test occursin (" ModA, ModB" , overview_pub)
510+ @test ! isempty (docs_pub)
511+ @test any (occursin (" pub_a" , s) for s in docs_pub)
512+ end
513+
514+ @testset " external_modules_to_document" begin
515+ current_module = DocumenterReferenceTestMod
516+ modules = Dict (current_module => String[])
517+ sort_by (x) = x
518+ source_files = [abspath (@__FILE__ )]
519+
520+ config = DR. _Config (
521+ current_module,
522+ " api_ext" ,
523+ modules,
524+ sort_by,
525+ Set {Symbol} (),
526+ true ,
527+ true ,
528+ " Ext API" ,
529+ " Ext API" ,
530+ source_files,
531+ " api_ext" ,
532+ false ,
533+ [DRExternalTestMod],
534+ )
535+
536+ private_docs = DR. _collect_private_docstrings (config, Pair{Symbol,DR. DocType}[])
537+ @test ! isempty (private_docs)
538+ @test any (occursin (" DRExternalTestMod.extfun" , s) for s in private_docs)
539+ end
540+
541+ @testset " APIBuilder runner integration" begin
542+ DR. reset_config! ()
543+
544+ pages = CTBase. automatic_reference_documentation (
545+ CTBase. DocumenterReferenceTag ();
546+ subdirectory= " api_integration" ,
547+ primary_modules= [DocumenterReferenceTestMod],
548+ public= true ,
549+ private= true ,
550+ title= " Integration API" ,
551+ )
552+
553+ @test ! isempty (DR. CONFIG)
554+
555+ doc = Documenter. Document (
556+ ;
557+ root= pwd (),
558+ source= " src" ,
559+ build= " build" ,
560+ remotes= nothing ,
561+ )
562+
563+ Documenter. Selectors. runner (DR. APIBuilder, doc)
564+
565+ @test ! isempty (doc. blueprint. pages)
566+ @test any (endswith (k, " private.md" ) for k in keys (doc. blueprint. pages))
567+ end
416568end
0 commit comments