Skip to content

Commit

Permalink
Merge 1daeb2b into f48af99
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Nov 24, 2019
2 parents f48af99 + 1daeb2b commit 6c76e22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ function Base.alignment(io::IO, measure::Measurement)
(length(m.captures[1]), length(m.captures[2]))
end

# correct quoting
function Base.show_unquoted(io::IO, z::Measurement, ::Int, prec::Int)
if Base.operator_precedence(:±) <= prec
print(io, "(")
show(io, z)
print(io, ")")
else
show(io, z)
end
end

### Juno pretty printing
@require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
Juno.render(i::Juno.Inline, measure::Measurement) =
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,11 @@ end
@test Base.alignment(devnull, x) == (5,4)
# Make sure the printed representation of a Measurement object is correctly parsed as
# the same number (note that the tag will be different, but that's not important here).
for a in (w, x, y); @test eval(Meta.parse(repr(a))) == a; end
for a in (w, x, y, range(w, 10w, length=10))
@test eval(Meta.parse(repr(a))) == a
end
# correct quoting in expressions
@test eval(eval(Meta.parse(repr(:(2 * $w))))) == 2 * w
end

@testset "sum" begin
Expand Down

0 comments on commit 6c76e22

Please sign in to comment.