Skip to content

Commit 1daeb2b

Browse files
committed
correct quoting of Measurements
1 parent f48af99 commit 1daeb2b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/show.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ function Base.alignment(io::IO, measure::Measurement)
7979
(length(m.captures[1]), length(m.captures[2]))
8080
end
8181

82+
# correct quoting
83+
function Base.show_unquoted(io::IO, z::Measurement, ::Int, prec::Int)
84+
if Base.operator_precedence(:±) <= prec
85+
print(io, "(")
86+
show(io, z)
87+
print(io, ")")
88+
else
89+
show(io, z)
90+
end
91+
end
92+
8293
### Juno pretty printing
8394
@require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
8495
Juno.render(i::Juno.Inline, measure::Measurement) =

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ end
578578
@test Base.alignment(devnull, x) == (5,4)
579579
# Make sure the printed representation of a Measurement object is correctly parsed as
580580
# the same number (note that the tag will be different, but that's not important here).
581-
for a in (w, x, y); @test eval(Meta.parse(repr(a))) == a; end
581+
for a in (w, x, y, range(w, 10w, length=10))
582+
@test eval(Meta.parse(repr(a))) == a
583+
end
584+
# correct quoting in expressions
585+
@test eval(eval(Meta.parse(repr(:(2 * $w))))) == 2 * w
582586
end
583587

584588
@testset "sum" begin

0 commit comments

Comments
 (0)