diff --git a/base/show.jl b/base/show.jl index e627ff5cb2f87..037c66ae95f50 100644 --- a/base/show.jl +++ b/base/show.jl @@ -706,7 +706,7 @@ function show_delim_array(io::IO, itr, op, delim, cl, delim_one, i1=1, n=typemax y = iterate(itr) first = true i0 = i1-1 - while i1 > 2 && y !== nothing + while i1 > 1 && y !== nothing y = iterate(itr, y[2]) i1 -= 1 end diff --git a/test/show.jl b/test/show.jl index 13bf8c4013e6e..5f06d9b31f066 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1520,3 +1520,13 @@ Z = Array{Float64}(undef,0,0) # issue #31065, do not print parentheses for nested dot expressions @test sprint(Base.show_unquoted, :(foo.x.x)) == "foo.x.x" + +@testset "show_delim_array" begin + sdastr(f, n) = # sda: Show Delim Array + sprint((io, x) -> Base.show_delim_array(io, x, "[", ",", "]", false, f, n), Iterators.take(1:f+n, f+n)) + @test sdastr(1, 0) == "[1]" + @test sdastr(1, 1) == "[1]" + @test sdastr(1, 2) == "[1, 2]" + @test sdastr(2, 2) == "[2, 3]" + @test sdastr(3, 3) == "[3, 4, 5]" +end