Skip to content

Commit

Permalink
Merge 95af0c9 into 82f8496
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Mar 6, 2019
2 parents 82f8496 + 95af0c9 commit 7178aec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function show(io::IO, x::Quantity)
nothing
end

function show(io::IO, mime::MIME"text/plain", x::Quantity)
show(io, mime, x.val)
if !isunitless(unit(x))
print(io," ")
show(io, mime, unit(x))
end
end

function show(io::IO, x::Quantity{S, NoDims, <:Units{
(Unitful.Unit{:Degree, NoDims}(0, 1//1),), NoDims}}) where S
show(io, x.val)
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,17 @@ end
@test string(NoDims) == "NoDims"
end

struct Foo <: Number end
Base.show(io::IO, x::Foo) = print(io, "1")
Base.show(io::IO, ::MIME"text/plain", ::Foo) = print(io, "42.0")

@testset "Show quantities" begin
@test repr(1.0 * u"m * s * kg^-1") == "1.0 m s kg^-1"
@test repr("text/plain", 1.0 * u"m * s * kg^-1") == "1.0 m s kg^-1"
@test repr(Foo() * u"m * s * kg^-1") == "1 m s kg^-1"
@test repr("text/plain", Foo() * u"m * s * kg^-1") == "42.0 m s kg^-1"
end

@testset "DimensionError message" begin
function errorstr(e)
b = IOBuffer()
Expand Down

0 comments on commit 7178aec

Please sign in to comment.