Skip to content

Commit 4314a3f

Browse files
committed
fix all doctests, update stale documentation
1 parent a4cfeb5 commit 4314a3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+412
-385
lines changed

base/abstractdict.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ return the elements in the same order.
9090
9191
# Examples
9292
```jldoctest
93-
julia> a = Dict('a'=>2, 'b'=>3)
93+
julia> D = Dict('a'=>2, 'b'=>3)
9494
Dict{Char,Int64} with 2 entries:
95-
'b' => 3
9695
'a' => 2
96+
'b' => 3
9797
98-
julia> collect(keys(a))
98+
julia> collect(keys(D))
9999
2-element Array{Char,1}:
100-
'b'
101100
'a'
101+
'b'
102102
```
103103
"""
104104
keys(a::AbstractDict) = KeySet(a)
@@ -115,15 +115,15 @@ return the elements in the same order.
115115
116116
# Examples
117117
```jldoctest
118-
julia> a = Dict('a'=>2, 'b'=>3)
118+
julia> D = Dict('a'=>2, 'b'=>3)
119119
Dict{Char,Int64} with 2 entries:
120-
'b' => 3
121120
'a' => 2
121+
'b' => 3
122122
123-
julia> collect(values(a))
123+
julia> collect(values(D))
124124
2-element Array{Int64,1}:
125-
3
126125
2
126+
3
127127
```
128128
"""
129129
values(a::AbstractDict) = ValueIterator(a)

base/array.jl

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,7 @@ julia> A = [false, false, true, false]
15231523
julia> findnext(A, 1)
15241524
3
15251525
1526-
julia> findnext(A, 4) == nothing
1527-
true
1526+
julia> findnext(A, 4) # returns nothing, but not printed in the REPL
15281527
15291528
julia> A = [false false; true false]
15301529
2×2 Array{Bool,2}:
@@ -1575,8 +1574,7 @@ julia> A = [false, false, true, false]
15751574
julia> findfirst(A)
15761575
3
15771576
1578-
julia> findfirst(falses(3)) == nothing
1579-
true
1577+
julia> findfirst(falses(3)) # returns nothing, but not printed in the REPL
15801578
15811579
julia> A = [false false; true false]
15821580
2×2 Array{Bool,2}:
@@ -1615,23 +1613,14 @@ and [`pairs(A)`](@ref).
16151613
16161614
# Examples
16171615
```jldoctest
1618-
A = [1, 4, 2, 2]
1619-
4-element Array{Int64,1}:
1620-
1
1621-
4
1622-
2
1623-
2
1616+
julia> A = [1, 4, 2, 2];
16241617
16251618
julia> findnext(isodd, A, 1)
16261619
1
16271620
1628-
julia> findnext(isodd, A, 2) == nothing
1629-
true
1621+
julia> findnext(isodd, A, 2) # returns nothing, but not printed in the REPL
16301622
1631-
julia> A = [1 4; 2 2]
1632-
2×2 Array{Int64,2}:
1633-
1 4
1634-
2 2
1623+
julia> A = [1 4; 2 2];
16351624
16361625
julia> findnext(isodd, A, CartesianIndex(1, 1))
16371626
CartesianIndex(1, 1)
@@ -1670,8 +1659,7 @@ julia> A = [1, 4, 2, 2]
16701659
julia> findfirst(iseven, A)
16711660
2
16721661
1673-
julia> findfirst(x -> x>10, A) == nothing
1674-
true
1662+
julia> findfirst(x -> x>10, A) # returns nothing, but not printed in the REPL
16751663
16761664
julia> findfirst(equalto(4), A)
16771665
2
@@ -1717,8 +1705,7 @@ julia> A = [false, false, true, true]
17171705
julia> findprev(A, 3)
17181706
3
17191707
1720-
julia> findprev(A, 1) == nothing
1721-
true
1708+
julia> findprev(A, 1) # returns nothing, but not printed in the REPL
17221709
17231710
julia> A = [false false; true true]
17241711
2×2 Array{Bool,2}:
@@ -1767,8 +1754,7 @@ julia> findlast(A)
17671754
17681755
julia> A = falses(2,2);
17691756
1770-
julia> findlast(A) == nothing
1771-
true
1757+
julia> findlast(A) # returns nothing, but not printed in the REPL
17721758
17731759
julia> A = [true false; true false]
17741760
2×2 Array{Bool,2}:
@@ -1814,8 +1800,7 @@ julia> A = [4, 6, 1, 2]
18141800
1
18151801
2
18161802
1817-
julia> findprev(isodd, A, 1) == nothing
1818-
true
1803+
julia> findprev(isodd, A, 1) # returns nothing, but not printed in the REPL
18191804
18201805
julia> findprev(isodd, A, 3)
18211806
3
@@ -1859,8 +1844,7 @@ julia> A = [1, 2, 3, 4]
18591844
julia> findlast(isodd, A)
18601845
3
18611846
1862-
julia> findlast(x -> x > 5, A) == nothing
1863-
true
1847+
julia> findlast(x -> x > 5, A) # returns nothing, but not printed in the REPL
18641848
18651849
julia> A = [1 2; 3 4]
18661850
2×2 Array{Int64,2}:
@@ -1965,9 +1949,9 @@ julia> A = [true false; false true]
19651949
false true
19661950
19671951
julia> findall(A)
1968-
2-element Array{Int64,1}:
1969-
1
1970-
4
1952+
2-element Array{CartesianIndex{2},1}:
1953+
CartesianIndex(1, 1)
1954+
CartesianIndex(2, 2)
19711955
19721956
julia> findall(falses(3))
19731957
0-element Array{Int64,1}
@@ -2137,9 +2121,9 @@ array contains `nothing` wherever `a` is not a member of `b`.
21372121
21382122
# Examples
21392123
```jldoctest
2140-
julia> a = ['a', 'b', 'c', 'b', 'd', 'a']
2124+
julia> a = ['a', 'b', 'c', 'b', 'd', 'a'];
21412125
2142-
julia> b = ['a', 'b', 'c']
2126+
julia> b = ['a', 'b', 'c'];
21432127
21442128
julia> indexin(a, b)
21452129
6-element Array{Union{Nothing, Int64},1}:

base/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ would be the broadcast `inds`). The shape of the output is equal to the shape of
700700
element of `indsb`.
701701
702702
# Examples
703-
```jldoctest
703+
```jldoctest bc_getindex
704704
julia> A = [11 12; 21 22]
705705
2×2 Array{Int64,2}:
706706
11 12
@@ -729,7 +729,7 @@ julia> broadcast_getindex(A, 1:2, 2:-1:1)
729729
Because the indices are all vectors, these calls are like `[A[i[k], j[k]] for k = 1:2]`
730730
where `i` and `j` are the two index vectors.
731731
732-
```jldoctest
732+
```jldoctest bc_getindex
733733
julia> broadcast_getindex(A, 1:2, (1:2)')
734734
2×2 Array{Int64,2}:
735735
11 12

base/dict.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,15 @@ end
530530
Determine whether a collection has a mapping for a given key.
531531
532532
```jldoctest
533-
julia> a = Dict('a'=>2, 'b'=>3)
533+
julia> D = Dict('a'=>2, 'b'=>3)
534534
Dict{Char,Int64} with 2 entries:
535-
'b' => 3
536535
'a' => 2
536+
'b' => 3
537537
538-
julia> haskey(a,'a')
538+
julia> haskey(D, 'a')
539539
true
540540
541-
julia> haskey(a,'c')
541+
julia> haskey(D, 'c')
542542
false
543543
```
544544
"""
@@ -551,15 +551,15 @@ in(key, v::KeySet{<:Any, <:Dict}) = (ht_keyindex(v.dict, key) >= 0)
551551
Return the key matching argument `key` if one exists in `collection`, otherwise return `default`.
552552
553553
```jldoctest
554-
julia> a = Dict('a'=>2, 'b'=>3)
554+
julia> D = Dict('a'=>2, 'b'=>3)
555555
Dict{Char,Int64} with 2 entries:
556-
'b' => 3
557556
'a' => 2
557+
'b' => 3
558558
559-
julia> getkey(a,'a',1)
559+
julia> getkey(D, 'a', 1)
560560
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
561561
562-
julia> getkey(a,'d','a')
562+
julia> getkey(D, 'd', 'a')
563563
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
564564
```
565565
"""

base/docs/basedocs.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,25 +924,28 @@ OutOfMemoryError
924924
An indexing operation into an array, `a`, tried to access an out-of-bounds element at index `i`.
925925
926926
# Examples
927-
```jldoctest
927+
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
928928
julia> A = fill(1.0, 7);
929929
930930
julia> A[8]
931931
ERROR: BoundsError: attempt to access 7-element Array{Float64,1} at index [8]
932932
Stacktrace:
933-
[1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:758
933+
[1] getindex(::Array{Float64,1}, ::Int64) at ./array.jl:660
934+
[2] top-level scope
934935
935936
julia> B = fill(1.0, (2,3));
936937
937938
julia> B[2, 4]
938939
ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [2, 4]
939940
Stacktrace:
940-
[1] getindex(::Array{Float64,2}, ::Int64, ::Int64) at ./array.jl:759
941+
[1] getindex(::Array{Float64,2}, ::Int64, ::Int64) at ./array.jl:661
942+
[2] top-level scope
941943
942944
julia> B[9]
943945
ERROR: BoundsError: attempt to access 2×3 Array{Float64,2} at index [9]
944946
Stacktrace:
945-
[1] getindex(::Array{Float64,2}, ::Int64) at ./array.jl:758
947+
[1] getindex(::Array{Float64,2}, ::Int64) at ./array.jl:660
948+
[2] top-level scope
946949
```
947950
"""
948951
BoundsError
@@ -955,9 +958,9 @@ Cannot exactly convert `val` to type `T` in a method of function `name`.
955958
# Examples
956959
```jldoctest
957960
julia> convert(Float64, 1+2im)
958-
ERROR: InexactError: convert(Float64, 1 + 2im)
961+
ERROR: InexactError: Float64(Float64, 1 + 2im)
959962
Stacktrace:
960-
[1] convert(::Type{Float64}, ::Complex{Int64}) at ./complex.jl:37
963+
[...]
961964
```
962965
"""
963966
InexactError

base/essentials.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ julia> convert(Int, 3.0)
8484
3
8585
8686
julia> convert(Int, 3.5)
87-
ERROR: InexactError: convert(Int64, 3.5)
87+
ERROR: InexactError: Int64(Int64, 3.5)
8888
Stacktrace:
89-
[1] convert(::Type{Int64}, ::Float64) at ./float.jl:703
89+
[...]
9090
```
9191
9292
If `T` is a [`AbstractFloat`](@ref) or [`Rational`](@ref) type,
@@ -414,22 +414,24 @@ Annotates the expression `blk` as a bounds checking block, allowing it to be eli
414414
its caller in order for `@inbounds` to have effect.
415415
416416
# Examples
417-
```jldoctest
417+
```jldoctest; filter = r"Stacktrace:(\\n \\[[0-9]+\\].*)*"
418418
julia> @inline function g(A, i)
419419
@boundscheck checkbounds(A, i)
420420
return "accessing (\$A)[\$i]"
421-
end
422-
f1() = return g(1:2, -1)
423-
f2() = @inbounds return g(1:2, -1)
424-
f2 (generic function with 1 method)
421+
end;
422+
423+
julia> f1() = return g(1:2, -1);
424+
425+
julia> f2() = @inbounds return g(1:2, -1);
425426
426427
julia> f1()
427428
ERROR: BoundsError: attempt to access 2-element UnitRange{Int64} at index [-1]
428429
Stacktrace:
429-
[1] throw_boundserror(::UnitRange{Int64}, ::Tuple{Int64}) at ./abstractarray.jl:435
430-
[2] checkbounds at ./abstractarray.jl:399 [inlined]
430+
[1] throw_boundserror(::UnitRange{Int64}, ::Tuple{Int64}) at ./abstractarray.jl:455
431+
[2] checkbounds at ./abstractarray.jl:420 [inlined]
431432
[3] g at ./none:2 [inlined]
432433
[4] f1() at ./none:1
434+
[5] top-level scope
433435
434436
julia> f2()
435437
"accessing (1:2)[-1]"

base/floatfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ julia> round(pi, 3, base = 2)
9090
rounded to 1.2.
9191
9292
# Examples
93-
```jldoctest
93+
```jldoctest; setup = :(using Printf)
9494
julia> x = 1.15
9595
1.15
9696

base/io.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ julia> open("my_file.txt", "w") do io
315315
57
316316
317317
julia> readuntil("my_file.txt", 'L')
318-
"JuliaL"
318+
"Julia"
319319
320-
julia> readuntil("my_file.txt", '.')
320+
julia> readuntil("my_file.txt", '.', keep = true)
321321
"JuliaLang is a GitHub organization."
322322
323323
julia> rm("my_file.txt")
@@ -1003,7 +1003,7 @@ end with the EOL, matching the length returned by [`eachline`](@ref) and [`readl
10031003
10041004
# Examples
10051005
```jldoctest
1006-
julia> io = IOBuffer("JuliaLang is a GitHub organization.\n");
1006+
julia> io = IOBuffer("JuliaLang is a GitHub organization.\\n");
10071007
10081008
julia> countlines(io)
10091009
1
@@ -1014,7 +1014,7 @@ julia> countlines(io)
10141014
1
10151015
10161016
julia> countlines(io, eol = '.')
1017-
1
1017+
0
10181018
```
10191019
"""
10201020
function countlines(io::IO; eol::Char='\n')

base/iostream.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ iswritable(s::IOStream) = ccall(:ios_get_writable, Cint, (Ptr{Cvoid},), s.ios)!=
4848
isreadable(s::IOStream) = ccall(:ios_get_readable, Cint, (Ptr{Cvoid},), s.ios)!=0
4949

5050
"""
51-
truncate(file,n)
51+
truncate(file, n)
5252
5353
Resize the file or buffer given by the first argument to exactly `n` bytes, filling
5454
previously unallocated space with '\\0' if the file or buffer is grown.
@@ -73,7 +73,7 @@ julia> write(io, "JuliaLang is a GitHub organization.");
7373
julia> truncate(io, 40);
7474
7575
julia> String(take!(io))
76-
"JuliaLang is a GitHub organization.\0\0\0\0\0"
76+
"JuliaLang is a GitHub organization.\\0\\0\\0\\0\\0"
7777
```
7878
"""
7979
function truncate(s::IOStream, n::Integer)
@@ -354,8 +354,8 @@ descriptor upon completion.
354354
# Examples
355355
```jldoctest
356356
julia> open("myfile.txt", "w") do io
357-
write(io, "Hello world!");
358-
end
357+
write(io, "Hello world!")
358+
end;
359359
360360
julia> open(f->read(f, String), "myfile.txt")
361361
"Hello world!"

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ See [`Base.filter`](@ref) for an eager implementation of filtering for arrays.
376376
# Examples
377377
```jldoctest
378378
julia> f = Iterators.filter(isodd, [1, 2, 3, 4, 5])
379-
Base.Iterators.Filter{Base.#isodd,Array{Int64,1}}(isodd, [1, 2, 3, 4, 5])
379+
Base.Iterators.Filter{typeof(isodd),Array{Int64,1}}(isodd, [1, 2, 3, 4, 5])
380380
381381
julia> foreach(println, f)
382382
1

0 commit comments

Comments
 (0)