From 5a1dc0ceb9c3f963780ee19e52fea03a3babec97 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Fri, 13 Sep 2024 14:58:38 -0500 Subject: [PATCH] Make `show(::Benchmark)` indent samples 1 space instead of 2; add tests and justification (#114) --- src/show.jl | 2 +- test/runtests.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/show.jl b/src/show.jl index 4e511254..605b1dea 100644 --- a/src/show.jl +++ b/src/show.jl @@ -99,7 +99,7 @@ end function Base.show(io::IO, b::Benchmark) println(io, "Benchmark([") for s in b.samples - println(io, " ", s) + println(io, " ", s) end print(io, "])") end diff --git a/test/runtests.jl b/test/runtests.jl index 6bcce097..e3592dcd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -144,6 +144,16 @@ using Chairmarks: Sample, Benchmark Sample(time=0.10162322700000001, allocs=166, bytes=16584) ]) + # 1 space indent, like Vector, even though there's two levels of nesting here. + @test sprint(show, x) == """ + Benchmark([ + Sample(time=0.10223923, allocs=166, bytes=16584) + Sample(time=0.101591227, allocs=166, bytes=16584) + Sample(time=0.10154031000000001, allocs=166, bytes=16584) + Sample(time=0.101644144, allocs=166, bytes=16584) + Sample(time=0.10162322700000001, allocs=166, bytes=16584) + ])""" + @test eval(Meta.parse(repr(x))).samples == x.samples VERSION >= v"1.6" && @test sprint(show, MIME"text/plain"(), x) == """ Benchmark: 5 samples with 1 evaluation