forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.jl
1226 lines (949 loc) · 25.6 KB
/
docs.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is a part of Julia. License is MIT: https://julialang.org/license
import Base.Docs: meta, @var, DocStr, parsedoc
using Markdown
using REPL
using REPL: @repl, repl_latex, _repl, accessible
using InteractiveUtils: apropos
# For curmod_*
include("testenv.jl")
# Test helpers.
function docstrings_equal(d1, d2)
io1 = IOBuffer()
io2 = IOBuffer()
show(io1, MIME"text/markdown"(), d1)
show(io2, MIME"text/markdown"(), d2)
String(take!(io1)) == String(take!(io2))
end
docstrings_equal(d1::DocStr, d2) = docstrings_equal(parsedoc(d1), d2)
function docstring_startswith(d1, d2)
io1 = IOBuffer()
io2 = IOBuffer()
show(io1, MIME"text/markdown"(), d1)
show(io2, MIME"text/markdown"(), d2)
startswith(String(take!(io1)), String(take!(io2)))
end
docstring_startswith(d1::DocStr, d2) = docstring_startswith(parsedoc(d1), d2)
@doc "Doc abstract type"
abstract type C74685{T,N} <: AbstractArray{T,N} end
@test repr("text/plain", Docs.doc(C74685))==" Doc abstract type"
@test string(Docs.doc(C74685))=="Doc abstract type\n"
macro macro_doctest() end
@doc "Helps test if macros can be documented with `@doc \"...\" @...`."
:@macro_doctest
@test (@doc @macro_doctest) !== nothing
@test (@eval @doc $(Meta.parse("{a"))) isa Markdown.MD
@test (@eval @doc $(Meta.parse("``"))) isa Markdown.MD
@test (@eval @doc $(Meta.parse("``"))) == (@doc @cmd)
@test (@eval @doc $(Meta.parse("123456789012345678901234567890"))) == (@doc @int128_str)
@test (@eval @doc $(Meta.parse("1234567890123456789012345678901234567890"))) == (@doc @big_str)
# test that random stuff interpolated into docstrings doesn't break search or other methods here
@doc doc"""
break me:
code
$:asymbol # a symbol
$1 # a number
$string # a function
$$latex literal$$
### header!
"""
function break_me_docs end
# issue #11548
module ModuleMacroDoc
macro m() end
end
@doc "I am a module" ModuleMacroDoc
@doc "I am a macro" :@ModuleMacroDoc.m
@test docstrings_equal(@doc(ModuleMacroDoc), doc"I am a module")
@test docstrings_equal(@doc(ModuleMacroDoc.@m), doc"I am a macro")
# General tests for docstrings.
const LINE_NUMBER = @__LINE__() + 1
"DocsTest"
module DocsTest
using Markdown
"f-1"
function f(x)
x
end
"f-2"
f(x, y) = x + y
"s-1"
@generated function s(x)
:(x)
end
"s-2"
@generated s(x, y) = :(x + y)
"g"
function g end
"AT"
abstract type AT end
"BT"
primitive type BT 8 end
"BT2"
primitive type BT2 <: Integer 8 end
"T"
mutable struct T <: AT
"T.x"
x
"T.y"
y :: Int
end
"IT"
struct IT
"IT.x"
x :: Int
"IT.y"
y
end
"TA"
const TA = Union{T, IT}
"@mac()"
macro mac() end
"@mac(x)"
macro mac(x) end
"@mac(x::Int, y::Expr, z = 0)"
macro mac(x::Int, y::Expr, z = 0) end
":@mac"
:@mac
"G"
G = :G
"K"
const K = :K
# Adding docstrings to methods after definition.
t(x::AbstractString) = x
t(x::Int, y) = y
t(x::S) where {S <: Integer} = x
"t-1"
t(::AbstractString)
"t-2"
t(::Int, ::Any)
"t-3"
t{S <: Integer}(::S)
# Docstrings to parametric methods after definition using where syntax (#32960):
tw(x::T) where T = nothing
tw(x::T, y::U) where {T, U <: Integer} = nothing
tw(x::T, y::U, z::V) where T where U <: Integer where V <: AbstractFloat = nothing
"tw-1"
tw(x::T) where T
"tw-2"
tw(x::T, y::U) where {T, U <: Integer}
"tw-3"
tw(x::T, y::U, z::V) where T where U <: Integer where V <: AbstractFloat
"FieldDocs"
mutable struct FieldDocs
"one"
one
doc"two"
two
three
end
"h/0-3"
h(x = 1, y = 2, z = 3) = x + y + z
# Issue #12700.
module Inner
macro m() end
end
import .Inner.@m
"Inner.@m"
:@m
mutable struct Foo
x
end
# value with no docs
const val = Foo(1.0)
"doc multiple expressions"
function multidoc end,
function multidoc! end
"returntype-1"
returntype(x::Float64)::Float64 = x
"returntype-2"
function returntype(x::Int)::Int
x
end
# @nospecialize (issue #34122)
"`fnospecialize` for Numbers"
fnospecialize(@nospecialize(x::Number)) = 1
"`fnospecialize` for arrays"
fnospecialize(@nospecialize(x::AbstractArray)) = 2
end
let md = meta(DocsTest)[@var(DocsTest)]
@test docstrings_equal(md.docs[Union{}], doc"DocsTest")
# Check that plain docstrings store a module reference.
# https://github.com/JuliaLang/julia/pull/13017#issuecomment-138618663
@test md.docs[Union{}].data[:module] == DocsTest
@test md.docs[Union{}].data[:linenumber] == LINE_NUMBER
end
let f = @var(DocsTest.f)
md = meta(DocsTest)[f]
@test docstrings_equal(md.docs[Tuple{Any}], doc"f-1")
@test docstrings_equal(md.docs[Tuple{Any,Any}], doc"f-2")
@test md.docs[Tuple{Any}].data[:binding] === f
@test md.docs[Tuple{Any}].data[:typesig] === Tuple{Any}
@test md.docs[Tuple{Any,Any}].data[:binding] === f
@test md.docs[Tuple{Any,Any}].data[:typesig] === Tuple{Any,Any}
end
let s = @var(DocsTest.s)
md = meta(DocsTest)[s]
@test docstrings_equal(md.docs[Tuple{Any,}], doc"s-1")
@test docstrings_equal(md.docs[Tuple{Any,Any}], doc"s-2")
end
let g = @var(DocsTest.g)
md = meta(DocsTest)[g]
@test docstrings_equal(md.docs[Union{}], doc"g")
end
let h = @var(DocsTest.h)
md = meta(DocsTest)[h]
sig = Union{Tuple{}, Tuple{Any}, Tuple{Any, Any}, Tuple{Any, Any, Any}}
@test docstrings_equal(md.docs[sig], doc"h/0-3")
end
let AT = @var(DocsTest.AT)
md = meta(DocsTest)[AT]
@test docstrings_equal(md.docs[Union{}], doc"AT")
end
let BT = @var(DocsTest.BT)
md = meta(DocsTest)[BT]
@test docstrings_equal(md.docs[Union{}], doc"BT")
end
let BT2 = @var(DocsTest.BT2)
md = meta(DocsTest)[BT2]
@test docstrings_equal(md.docs[Union{}], doc"BT2")
end
let T = @var(DocsTest.T)
md = meta(DocsTest)[T]
d = md.docs[Union{}]
@test docstrings_equal(d, doc"T")
@test d.data[:fields][:x] == "T.x"
@test d.data[:fields][:y] == "T.y"
end
let IT = @var(DocsTest.IT)
md = meta(DocsTest)[IT]
d = md.docs[Union{}]
@test docstrings_equal(d, doc"IT")
@test d.data[:fields][:x] == "IT.x"
@test d.data[:fields][:y] == "IT.y"
end
let rt = @var(DocsTest.returntype)
md = meta(DocsTest)[rt]
@test md.order == [Tuple{Float64}, Tuple{Int}]
end
let fns = @var(DocsTest.fnospecialize)
md = meta(DocsTest)[fns]
d = md.docs[Tuple{Number}]
@test docstrings_equal(d, doc"`fnospecialize` for Numbers")
d = md.docs[Tuple{AbstractArray}]
@test docstrings_equal(d, doc"`fnospecialize` for arrays")
end
@test docstrings_equal(@doc(DocsTest.TA), doc"TA")
@test docstrings_equal(@doc(DocsTest.@mac), doc"@mac()")
@test docstrings_equal(@doc(DocsTest.@mac()), doc"@mac()")
@test docstrings_equal(@doc(DocsTest.@mac(x)), doc"@mac(x)")
@test docstrings_equal(@doc(DocsTest.@mac(x::Int, y::Expr)), doc"@mac(x::Int, y::Expr, z = 0)")
@test docstrings_equal(@doc(DocsTest.@mac(x::Int, y::Expr, z)), doc"@mac(x::Int, y::Expr, z = 0)")
let m = doc"""
@mac()
@mac(x)
@mac(x::Int, y::Expr, z = 0)
:@mac
"""
@test docstrings_equal(@doc(:@DocsTest.mac), m)
@test docstrings_equal(@doc(:(DocsTest.@mac)), m)
end
@test docstrings_equal(@doc(DocsTest.G), doc"G")
@test docstrings_equal(@doc(DocsTest.K), doc"K")
let d1 = @doc(DocsTest.t(::AbstractString)),
d2 = doc"t-1"
@test docstrings_equal(d1,d2)
end
let d1 = @doc(DocsTest.t(::AbstractString)),
d2 = doc"t-1"
@test docstrings_equal(d1,d2)
end
let d1 = @doc(DocsTest.t(::Int, ::Any)),
d2 = doc"t-2"
@test docstrings_equal(d1,d2)
end
let d1 = @doc(DocsTest.t{S <: Integer}(::S)),
d2 = doc"t-3"
@test docstrings_equal(d1,d2)
end
let fields = meta(DocsTest)[@var(DocsTest.FieldDocs)].docs[Union{}].data[:fields]
@test haskey(fields, :one) && fields[:one] == "one"
@test haskey(fields, :two) && fields[:two] == doc"two"
end
let a = @doc(DocsTest.multidoc),
b = @doc(DocsTest.multidoc!)
@test docstrings_equal(a, b)
end
"BareModule"
baremodule BareModule
"f/1"
f(x) = x
"g/1"
function g(x) end
"h"
function h end
"@m"
macro m() end
"C"
const C = 1
"A"
abstract type A end
"T"
mutable struct T
"x"
x
"y"
y
end
end
@test docstrings_equal(@doc(BareModule), doc"BareModule")
@test docstrings_equal(@doc(BareModule.f), doc"f/1")
@test docstrings_equal(@doc(BareModule.g), doc"g/1")
@test docstrings_equal(@doc(BareModule.@m), doc"@m")
@test docstrings_equal(@doc(BareModule.C), doc"C")
@test docstrings_equal(@doc(BareModule.A), doc"A")
@test docstrings_equal(@doc(BareModule.T), doc"T")
@test_throws ErrorException @doc("...", "error")
@test_throws ErrorException @doc("...", @time 0)
# test that when no docs exist, they fallback to
# the docs for the typeof(value)
let d1 = @doc(DocsTest.val)
@test d1 !== nothing
end
# DocRefs
module DocRefTests
"..."
function f end, function f! end, @enum E a b c
@doc Docs.@ref(f) g() = ()
@doc Docs.@ref(f!) g!() = ()
end
let d_1 = @doc(DocRefTests.f).meta[:results][1],
d_2 = @doc(DocRefTests.f!).meta[:results][1],
d_3 = @doc(DocRefTests.g).meta[:results][1],
d_4 = @doc(DocRefTests.g!).meta[:results][1],
d_5 = @doc(DocRefTests.E).meta[:results][1]
@test d_1 === d_2 === d_3 === d_4 === d_5
end
# Document specific expressions generated by macro calls.
module MacroGenerated
import Base.@__doc__
macro example_1(f)
quote
$(f)() = 0
@__doc__ $(f)(x) = x
$(f)(x, y) = x + y
end |> esc
end
const LINE_NUMBER_F = @__LINE__() + 1
"f"
@example_1 f
@example_1 _f
macro example_2(f)
quote
$(f)() = 0
@__doc__ $(f)(x) = x
@__doc__ $(f)(x, y) = x + y
end |> esc
end
const LINE_NUMBER_G = @__LINE__() + 1
"g"
@example_2 g
@example_2 _g
const LINE_NUMBER_T = @__LINE__() + 1
"T"
Base.@kwdef struct T end
end
let md = meta(MacroGenerated)[@var(MacroGenerated.f)]
@test md.order == [Tuple{Any}]
@test docstrings_equal(md.docs[Tuple{Any}], doc"f")
@test md.docs[Tuple{Any}].data[:linenumber] == MacroGenerated.LINE_NUMBER_F
@test md.docs[Tuple{Any}].data[:path] == @__FILE__()
end
@test isdefined(MacroGenerated, :_f)
let md = meta(MacroGenerated)[@var(MacroGenerated.g)]
@test md.order == [Tuple{Any}, Tuple{Any, Any}]
@test docstrings_equal(md.docs[Tuple{Any}], doc"g")
@test docstrings_equal(md.docs[Tuple{Any, Any}], doc"g")
@test md.docs[Tuple{Any}].data[:linenumber] == MacroGenerated.LINE_NUMBER_G
@test md.docs[Tuple{Any}].data[:path] == @__FILE__()
end
@test isdefined(MacroGenerated, :_g)
let md = meta(MacroGenerated)[@var(MacroGenerated.T)]
@test md.order == Type[Union{}]
@test docstrings_equal(md.docs[Union{}], doc"T")
@test md.docs[Union{}].data[:linenumber] == MacroGenerated.LINE_NUMBER_T
@test md.docs[Union{}].data[:path] == @__FILE__()
end
module DocVars
struct __FIELDS__ end
function Docs.formatdoc(buffer, docstr, ::Type{__FIELDS__})
fields = get(docstr.data, :fields, Dict())
if !isempty(fields)
println(buffer, "# Fields")
for (k, v) in sort!(collect(fields))
println(buffer, "`", k, "` -- ", v, "\n")
end
end
end
"""
$T
$__FIELDS__
"""
mutable struct T
"x"
x
"y"
y
z
end
"""
$S
$__FIELDS__
"""
mutable struct S
x
y
z
end
end
let T = meta(DocVars)[@var(DocVars.T)],
S = meta(DocVars)[@var(DocVars.S)],
Tname = Markdown.parse("```\n$(curmod_prefix)DocVars.T\n```"),
Sname = Markdown.parse("```\n$(curmod_prefix)DocVars.S\n```")
# Splicing the expression directly doesn't work
@test docstrings_equal(T.docs[Union{}],
doc"""
$Tname
# Fields
`x` -- x
`y` -- y
"""
)
@test docstrings_equal(S.docs[Union{}],
doc"""
$Sname
"""
)
end
# Issues.
# =======
# Issue #16359. Error message for invalid doc syntax.
let __source__ = LineNumberNode(0),
__module__ = @__MODULE__
for each in [ # valid syntax
:(f()),
:(f(x)),
:(f(x::Int)),
:(f(x...)),
:(f(x = 1)),
:(f(; x = 1))
]
@test Meta.isexpr(Docs.docm(__source__, __module__, "...", each), :block)
end
for each in [ # invalid syntax
:(f("...")),
:(f(1, 2)),
:(f(() -> ()))
]
result = Docs.docm(__source__, __module__, "...", each)
@test Meta.isexpr(result, :call)
@test result.args[1] === error
end
end
# Issue #15424. Non-markdown docstrings.
module I15424
using REPL
struct LazyHelp
text
end
function Base.show(io::IO, ::MIME"text/plain", h::LazyHelp)
print(io, h.text)
end
Base.show(io::IO, h::LazyHelp) = show(io, "text/plain", h)
function Base.Docs.catdoc(hs::LazyHelp...)
Base.Docs.Text() do io
for h in hs
show(io, MIME"text/plain"(), h)
end
end
end
REPL.docsearch(haystack::LazyHelp, needle) = REPL.docsearch(haystack.text, needle)
@doc LazyHelp("LazyHelp\n") LazyHelp
@doc LazyHelp("LazyHelp(text)\n") LazyHelp(text)
end
let d = @doc(I15424.LazyHelp)
@test repr("text/plain", d) == "LazyHelp\nLazyHelp(text)\n"
end
# Issue #13385.
struct I13385
λ
end
"issue #13385"
const i13385 = I13385(true)
@test @doc(i13385) !== nothing
# Issue #12700.
@test docstrings_equal(@doc(DocsTest.@m), doc"Inner.@m")
# issue 11993
# Check if we are documenting the expansion of the macro
macro m1_11993()
end
macro m2_11993()
Symbol("@m1_11993")
end
@doc "This should document @m1... since its the result of expansion" @m2_11993
@test (@doc @m1_11993) !== nothing
let d = (@doc :@m2_11993),
macro_doc = Markdown.parse("`$(curmod_prefix)@m2_11993` is a macro.")
@test docstring_startswith(d, doc"""
No documentation found.
$macro_doc""")
end
@doc "Now @m2... should be documented" :@m2_11993
@test (@doc @m2_11993) !== nothing
"Document inline function"
@inline f1_11993() = nothing
@test (@doc f1_11993) !== nothing
f1_11993()
@doc "Document inline function with old syntax"
@inline f2_11993() = nothing
@test (@doc f2_11993) !== nothing
f2_11993()
# issue #11798
module I11798
"read"
read(x) = x
end
let md = Base.Docs.meta(I11798)[@var(I11798.read)],
d1 = md.docs[md.order[1]],
d2 = doc"read"
@test docstrings_equal(d1,d2)
end
module I12515
struct EmptyType{T} end
"A new method"
Base.collect(::Type{EmptyType{T}}) where {T} = "borked"
end
let fd = meta(I12515)[@var(Base.collect)]
@test fd.order[1] == (Union{Tuple{Type{I12515.EmptyType{T}}}, Tuple{T}} where T)
end
# PR #12593
"$(1 + 1)"
f12593_1() = 1
"$(1 + 1) 2"
f12593_2() = 1
@test (@doc f12593_1) !== nothing
@test (@doc f12593_2) !== nothing
# @test Docs.doc(svdvals, Tuple{Vector{Float64}}) === nothing
# @test Docs.doc(svdvals, Tuple{Float64}) !== nothing
# crude test to make sure we sort docstring output by method specificity
@test !docstrings_equal(Docs.doc(getindex, Tuple{Dict{Int,Int},Int}),
Docs.doc(getindex, Tuple{Type{Int64},Int}))
# test that macro documentation works
@test (@repl :@assert) !== nothing
@test (@repl 0) !== nothing
let t = @doc(DocsTest.t(::Int, ::Int))
@test docstrings_equal(@repl(DocsTest.t(0, 0)), t)
@test docstrings_equal(@repl(DocsTest.t(::Int, ::Int)), t)
end
# Issue #13467.
@test (@repl :@r_str) !== nothing
# Simple tests for apropos:
@test occursin("eachindex", sprint(apropos, r"ind(exes|ices)"))
using Profile
@test occursin("Profile.print", sprint(apropos, "print"))
# Issue #13068.
module I13068
module A
export foo
"""
foo from A
"""
foo(::Int) = 1
end
module B
import ..A: foo
export foo
"""
foo from B
"""
foo(::Float64) = 2
end
end
@test docstrings_equal(
@doc(I13068.A.foo),
doc"""
foo from A
foo from B
"""
)
@test docstrings_equal(Docs.doc(I13068.A.foo, Tuple{Int}), doc"foo from A")
@test docstrings_equal(Docs.doc(I13068.A.foo, Tuple{Float64}), doc"foo from B")
@test docstrings_equal(Docs.doc(I13068.A.foo, Tuple{Char}),
doc"""
foo from A
foo from B
"""
)
# Issue #13905.
let err = try; @macroexpand(@doc "" f() = @x); false; catch ex; ex; end
__source__ = LineNumberNode(@__LINE__() - 1, Symbol(@__FILE__))
err::LoadError
@test err.file === string(__source__.file)
@test err.line === __source__.line
err = err.error::LoadError
@test err.file === string(__source__.file)
@test err.line === __source__.line
err = err.error::UndefVarError
@test err.var == Symbol("@x")
end
# Undocumented DataType Summaries.
module Undocumented
abstract type A end
abstract type B <: A end
mutable struct C <: A end
struct D <: B
one
two::String
three::Float64
end
f = () -> nothing
undocumented() = 1
undocumented(x) = 2
undocumented(x,y) = 3
end
doc_str = Markdown.parse("""
No documentation found.
Binding `$(curmod_prefix)Undocumented.bindingdoesnotexist` does not exist.
""")
@test docstrings_equal(@doc(Undocumented.bindingdoesnotexist), doc"$doc_str")
doc_str = Markdown.parse("""
No documentation found.
# Summary
```
abstract type $(curmod_prefix)Undocumented.A <: Any
```
# Subtypes
```
$(curmod_prefix)Undocumented.B
$(curmod_prefix)Undocumented.C
```
""")
@test docstrings_equal(@doc(Undocumented.A), doc"$doc_str")
doc_str = Markdown.parse("""
No documentation found.
# Summary
```
abstract type $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A
```
# Subtypes
```
$(curmod_prefix)Undocumented.D
```
# Supertype Hierarchy
```
$(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.B), doc"$doc_str")
doc_str = Markdown.parse("""
No documentation found.
# Summary
```
mutable struct $(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A
```
# Supertype Hierarchy
```
$(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.C), doc"$doc_str")
doc_str = Markdown.parse("""
No documentation found.
# Summary
```
struct $(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B
```
# Fields
```
one :: Any
two :: String
three :: Float64
```
# Supertype Hierarchy
```
$(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.D), doc"$doc_str")
let d = @doc(Undocumented.f)
io = IOBuffer()
show(io, MIME"text/markdown"(), d)
@test startswith(String(take!(io)),"""
No documentation found.
`$(curmod_prefix)Undocumented.f` is a `Function`.
""")
end
let d = @doc(Undocumented.undocumented)
io = IOBuffer()
show(io, MIME"text/markdown"(), d)
@test startswith(String(take!(io)), """
No documentation found.
`$(curmod_prefix)Undocumented.undocumented` is a `Function`.
""")
end
# `@doc` "metadata".
let m = @doc(DocsTest).meta
@test length(m[:results]) == 1
@test m[:results][1] === Docs.meta(DocsTest)[@var(DocsTest)].docs[Union{}]
@test m[:binding] == @var(DocsTest)
@test m[:typesig] === Union{}
end
let m = @doc(DocsTest.f).meta
@test length(m[:results]) == 2
@test m[:results][1] === Docs.meta(DocsTest)[@var(DocsTest.f)].docs[Tuple{Any}]
@test m[:results][2] === Docs.meta(DocsTest)[@var(DocsTest.f)].docs[Tuple{Any, Any}]
@test m[:binding] == @var(DocsTest.f)
@test m[:typesig] === Union{}
end
let m = @doc(DocsTest.f(x)).meta
@test length(m[:results]) == 1
@test m[:results][1] === Docs.meta(DocsTest)[@var(DocsTest.f)].docs[Tuple{Any}]
@test m[:binding] == @var(DocsTest.f)
@test m[:typesig] == Tuple{Any}
end
let m = @doc(Undocumented.f).meta
@test isempty(m[:results])
@test m[:binding] == @var(Undocumented.f)
@test m[:typesig] === Union{}
end
# Bindings.
import Base.Docs: @var, Binding, defined
let x = Binding(Base, Symbol("@time"))
@test defined(x) == true
@test @var(@time) == x
@test @var(Base.@time) == x
@test @var(Base.Iterators.@time) == x
end
let x = Binding(Iterators, :enumerate)
@test defined(x) == true
@test @var(enumerate) == x
@test @var(Base.enumerate) == x
@test @var(Iterators.enumerate) == x
@test @var(Base.Iterators.enumerate) == x
end
let x = Binding(Core, :Int)
@test defined(x) == true
@test @var(Int) == x
@test @var(Base.Int) == x
@test @var(Core.Int) == x
end
let x = Binding(Base, :Iterators)
@test defined(x) == true
@test @var(Iterators) == x
@test @var(Base.Iterators) == x
@test @var(Main.Iterators) == x
end
let x = Binding(Base, :VERSION)
@test defined(x) == true
@test @var(VERSION) == x
@test @var(Base.VERSION) == x
end
let x = Binding(Base, :bindingdoesnotexist)
@test defined(x) == false
@test @var(Base.bindingdoesnotexist) == x
end
let x = Binding(curmod, :bindingdoesnotexist)
@test defined(x) == false
@test @var(bindingdoesnotexist) == x
end
let x = Binding(Main, :+)
@test Meta.parse(string(x)) == :(Base.:+)
end
let x = Binding(Meta, :parse)
@test Meta.parse(string(x)) == :(Base.Meta.parse)
end
let x = Binding(Main, :⊕)
@test Meta.parse(string(x)) == :(⊕)
end