diff --git a/base/show.jl b/base/show.jl index ccdcdcc2d1c47..784ad04904c07 100644 --- a/base/show.jl +++ b/base/show.jl @@ -2061,13 +2061,13 @@ alignment(io::IO, x::Number) = (length(sprint(show, x, context=io, sizehint=0)), alignment(io::IO, x::Integer) = (length(sprint(show, x, context=io, sizehint=0)), 0) "`alignment(4.23)` yields (1,3) for `4` and `.23`" function alignment(io::IO, x::Real) - m = match(r"^(.*?)((?:[\.eE].*)?)$", sprint(show, x, context=io, sizehint=0)) + m = match(r"^(.*?)((?:[\.eEfF].*)?)$", sprint(show, x, context=io, sizehint=0)) m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) : (length(m.captures[1]), length(m.captures[2])) end "`alignment(1 + 10im)` yields (3,5) for `1 +` and `_10im` (plus sign on left, space on right)" function alignment(io::IO, x::Complex) - m = match(r"^(.*[^e][\+\-])(.*)$", sprint(show, x, context=io, sizehint=0)) + m = match(r"^(.*[^ef][\+\-])(.*)$", sprint(show, x, context=io, sizehint=0)) m === nothing ? (length(sprint(show, x, context=io, sizehint=0)), 0) : (length(m.captures[1]), length(m.captures[2])) end diff --git a/test/show.jl b/test/show.jl index f92fa075e13d8..5a243bd9556a7 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1445,6 +1445,11 @@ end "2-element Array{Any,1}:\n Pair{Integer,Int64}(1, 2)\n Pair{Integer,Int64}(33, 4)" end +@testset "alignment for complex arrays" begin # (#34763) + @test replstr([ 1e-7 + 2.0e-11im, 2.0e-5 + 4e0im]) == "2-element Array{Complex{Float64},1}:\n 1.0e-7 + 2.0e-11im\n 2.0e-5 + 4.0im" + @test replstr([ 1f-7 + 2.0f-11im, 2.0f-5 + 4f0im]) == "2-element Array{Complex{Float32},1}:\n 1.0f-7 + 2.0f-11im\n 2.0f-5 + 4.0f0im" +end + @testset "display arrays non-compactly when size(⋅, 2) == 1" begin # 0-dim @test replstr(zeros(Complex{Int})) == "0-dimensional Array{Complex{$Int},0}:\n0 + 0im"