Skip to content

Commit

Permalink
Fix printing of StepRangeLen with complex elements (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock authored Jan 26, 2022
1 parent 6ca16b6 commit 1f19b8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function show(io::IO, mime::MIME"text/plain", x::Quantity)
end
end

function show(io::IO, r::Union{StepRange{T},StepRangeLen{T}}) where T<:Quantity
function show(io::IO, r::StepRange{T}) where T<:Quantity
a,s,b = first(r), step(r), last(r)
U = unit(a)
print(io, '(')
Expand All @@ -145,6 +145,16 @@ function show(io::IO, r::Union{StepRange{T},StepRangeLen{T}}) where T<:Quantity
show(io, U)
end

function show(io::IO, r::StepRangeLen{T}) where T<:Quantity
a,s,b = first(r), step(r), last(r)
U = unit(a)
print(io, '(')
show(io, StepRangeLen(ustrip(U, a), ustrip(U, s), length(r)))
print(io, ')')
has_unit_spacing(U) && print(io,' ')
show(io, U)
end

function show(io::IO, x::typeof(NoDims))
print(io, "NoDims")
end
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,8 @@ Base.show(io::IO, ::MIME"text/plain", ::Foo) = print(io, "42.0")
@test repr((1:10)*u"kg/m^3") == "(1:10) kg m^-3"
@test repr((1.0:0.1:10.0)*u"kg/m^3") == "(1.0:0.1:10.0) kg m^-3"
@test repr((1:10)*°) == "(1:10)°"
@test repr(range(1.0+2.0im, length=5)*u"m") == "(1.0 + 2.0im:1.0 + 0.0im:5.0 + 2.0im) m"
@test repr(range(1+2im, step=1+1im, length=5)*u"m") == "(1 + 2im:1 + 1im:5 + 6im) m"
end
withenv("UNITFUL_FANCY_EXPONENTS" => true) do
@test repr(1.0 * u"m * s * kg^(-1//2)") == "1.0 m s kg⁻¹ᐟ²"
Expand Down

0 comments on commit 1f19b8f

Please sign in to comment.