Skip to content

Commit 8184684

Browse files
authored
Convert Base.alignment examples to jldoctests (#35961)
1 parent 52d85a3 commit 8184684

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

base/show.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,18 +2102,27 @@ end
21022102
"""
21032103
`alignment(io, X)` returns a tuple (left,right) showing how many characters are
21042104
needed on either side of an alignment feature such as a decimal point.
2105+
2106+
# Examples
2107+
```jldoctest
2108+
julia> Base.alignment(stdout, 42)
2109+
(2, 0)
2110+
2111+
julia> Base.alignment(stdout, 4.23)
2112+
(1, 3)
2113+
2114+
julia> Base.alignment(stdout, 1 + 10im)
2115+
(3, 5)
2116+
```
21052117
"""
21062118
alignment(io::IO, x::Any) = (0, length(sprint(show, x, context=io, sizehint=0)))
21072119
alignment(io::IO, x::Number) = (length(sprint(show, x, context=io, sizehint=0)), 0)
2108-
"`alignment(stdout, 42)` yields (2, 0)"
21092120
alignment(io::IO, x::Integer) = (length(sprint(show, x, context=io, sizehint=0)), 0)
2110-
"`alignment(stdout, 4.23)` yields (1, 3) for `4` and `.23`"
21112121
function alignment(io::IO, x::Real)
21122122
m = match(r"^(.*?)((?:[\.eEfF].*)?)$", sprint(show, x, context=io, sizehint=0))
21132123
m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) :
21142124
(length(m.captures[1]), length(m.captures[2]))
21152125
end
2116-
"`alignment(stdout, 1 + 10im)` yields (3, 5) for `1 +` and `_10im` (plus sign on left, space on right)"
21172126
function alignment(io::IO, x::Complex)
21182127
m = match(r"^(.*[^ef][\+\-])(.*)$", sprint(show, x, context=io, sizehint=0))
21192128
m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) :

0 commit comments

Comments
 (0)