Skip to content

Commit

Permalink
fix off-by-one error in show_delim_array (JuliaLang#32246)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet authored and JeffBezanson committed Jun 6, 2019
1 parent 51e459b commit 4824340
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4824340

Please sign in to comment.