From 7c97b19e6c75043f231f9d8e6661886b688259f1 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 11 Mar 2019 20:00:45 -0500 Subject: [PATCH] Better bounds error messages (#12) * Better bounds error messages Addresses the actionable portion of #8. --- src/InvertedIndices.jl | 7 ++++++- test/runtests.jl | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/InvertedIndices.jl b/src/InvertedIndices.jl index 8754470..80ec12a 100644 --- a/src/InvertedIndices.jl +++ b/src/InvertedIndices.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 1ab6fff..98b6b96 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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