Skip to content

Commit

Permalink
Make show(::Benchmark) indent samples 1 space instead of 2; add tes…
Browse files Browse the repository at this point in the history
…ts and justification (#114)
  • Loading branch information
LilithHafner authored Sep 13, 2024
1 parent f99ee98 commit 5a1dc0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a1dc0c

Please sign in to comment.