Skip to content

Commit

Permalink
Add space after comma in range printing (#44937)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Apr 12, 2022
1 parent f10ba9c commit 770b45d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ be an `Integer`.
```jldoctest
julia> LinRange(1.5, 5.5, 9)
9-element LinRange{Float64, Int64}:
1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5
```
Compared to using [`range`](@ref), directly constructing a `LinRange` should
Expand Down Expand Up @@ -592,7 +592,7 @@ as if it were `collect(r)`, dependent on the size of the
terminal, and taking into account whether compact numbers should be shown.
It figures out the width in characters of each element, and if they
end up too wide, it shows the first and last elements separated by a
horizontal ellipsis. Typical output will look like `1.0,2.0,3.0,…,4.0,5.0,6.0`.
horizontal ellipsis. Typical output will look like `1.0, 2.0, …, 5.0, 6.0`.
`print_range(io, r, pre, sep, post, hdots)` uses optional
parameters `pre` and `post` characters for each printed row,
Expand All @@ -601,9 +601,9 @@ parameters `pre` and `post` characters for each printed row,
"""
function print_range(io::IO, r::AbstractRange,
pre::AbstractString = " ",
sep::AbstractString = ",",
sep::AbstractString = ", ",
post::AbstractString = "",
hdots::AbstractString = ",\u2026,") # horiz ellipsis
hdots::AbstractString = ", \u2026, ") # horiz ellipsis
# This function borrows from print_matrix() in show.jl
# and should be called by show and display
sz = displaysize(io)
Expand Down
4 changes: 2 additions & 2 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1197,15 +1197,15 @@ end
@test replrepr(1:4) == "1:4"
@test repr("text/plain", 1:4) == "1:4"
@test repr("text/plain", range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr("text/plain", LinRange{Float64}(1,5,7)) == "7-element LinRange{Float64, Int$nb}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
@test repr("text/plain", LinRange{Float64}(1,5,7)) == "7-element LinRange{Float64, Int$nb}:\n 1.0, 1.66667, 2.33333, 3.0, 3.66667, 4.33333, 5.0"
@test repr(range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr(LinRange{Float64}(1,5,7)) == "LinRange{Float64}(1.0, 5.0, 7)"
@test replrepr(0:100.) == "0.0:1.0:100.0"
# next is to test a very large range, which should be fast because print_range
# only examines spacing of the left and right edges of the range, sufficient
# to cover the designated screen size.
@test replrepr(range(0, stop=100, length=10000)) == "0.0:0.010001000100010001:100.0"
@test replrepr(LinRange{Float64}(0,100, 10000)) == "10000-element LinRange{Float64, Int$nb}:\n 0.0,0.010001,0.020002,0.030003,0.040004,…,99.95,99.96,99.97,99.98,99.99,100.0"
@test replrepr(LinRange{Float64}(0,100, 10000)) == "10000-element LinRange{Float64, Int$nb}:\n 0.0, 0.010001, 0.020002, 0.030003, …, 99.96, 99.97, 99.98, 99.99, 100.0"

@test sprint(show, UnitRange(1, 2)) == "1:2"
@test sprint(show, StepRange(1, 2, 5)) == "1:2:5"
Expand Down

0 comments on commit 770b45d

Please sign in to comment.