Skip to content

Commit

Permalink
Better bounds error messages (#12)
Browse files Browse the repository at this point in the history
* Better bounds error messages

Addresses the actionable portion of #8.
  • Loading branch information
mbauman authored Mar 12, 2019
1 parent 2a94533 commit 7c97b19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/InvertedIndices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ _should_skip(s::CartesianIndex{1}, p::Integer) = s.I[1] == p

@inline Base.ensure_indexable(I::Tuple{InvertedIndexIterator, Vararg{Any}}) = (collect(I[1]), Base.ensure_indexable(tail(I))...)

Base.show(io::IO, I::InvertedIndexIterator) = show(io, collect(I))
# This is a little hacky, but we display InvertedIndexIterators like the `Not`s they come from
function Base.show(io::IO, I::InvertedIndexIterator)
print(io, "Not(")
show(io, I.skips)
print(io, ")")
end

# Inverted indices must be sorted and unique to ensure that iterating over
# them and the axes simultaneously will work appropriately. Doing this fully
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@ end
end

@testset "Utilities" begin
@test sprint(show, InvertedIndices.InvertedIndexIterator([2,4], 1:5)) == "[1, 3, 5]"
@test sprint(show, InvertedIndices.InvertedIndexIterator([2,4], 1:5)) == "Not([2, 4])"
A = [1]
ex = try A[Not(2,3)] catch ex; ex end
@test occursin("Not([2, 3])", sprint(Base.showerror, ex))
end

0 comments on commit 7c97b19

Please sign in to comment.