diff --git a/src/show.jl b/src/show.jl index 6034c258..3873622e 100644 --- a/src/show.jl +++ b/src/show.jl @@ -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) = diff --git a/test/runtests.jl b/test/runtests.jl index 69664acf..4c4362d6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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