Skip to content

Commit 6f78dcf

Browse files
committed
Prettify summary using showarg
1 parent 6cc3ce3 commit 6f78dcf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/OffsetArrays.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,18 @@ end
219219
@inline unsafe_getindex(a::OffsetSubArray, I::Union{Integer,CartesianIndex}...) = unsafe_getindex(a, Base.IteratorsMD.flatten(I)...)
220220
@inline unsafe_setindex!(a::OffsetSubArray, val, I::Union{Integer,CartesianIndex}...) = unsafe_setindex!(a, val, Base.IteratorsMD.flatten(I)...)
221221

222+
if VERSION >= v"0.7.0-DEV.1790"
223+
function Base.showarg(io::IO, a::OffsetArray, toplevel)
224+
print(io, "OffsetArray(")
225+
Base.showarg(io, parent(a), false)
226+
print(io, ", ")
227+
printindices(io, indices(a)...)
228+
print(io, ')')
229+
toplevel && print(io, " with eltype ", eltype(a))
230+
end
231+
printindices(io::IO, ind1, inds...) =
232+
(print(io, ind1, ", "); printindices(io, inds...))
233+
printindices(io::IO, ind1) = print(io, ind1)
234+
end
235+
222236
end # module

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,9 @@ for i = -3:3
353353
@test a[i] == i
354354
end
355355
@test unsafe_sum(a) == 0
356+
357+
if VERSION >= v"0.7.0-DEV.1790"
358+
a = OffsetArray([1 2; 3 4], -1:0, 5:6)
359+
@test summary(a) == "OffsetArray(::Array{$(Int),2}, -1:0, 5:6) with eltype $(Int) with indices -1:0×5:6"
360+
@test summary(view(a, :, 5)) == "view(OffsetArray(::Array{Int64,2}, -1:0, 5:6), :, 5) with eltype Int64 with indices -1:0"
361+
end

0 commit comments

Comments
 (0)