diff --git a/src/StarWarsArrays.jl b/src/StarWarsArrays.jl index 8e3c469..5e7d501 100644 --- a/src/StarWarsArrays.jl +++ b/src/StarWarsArrays.jl @@ -72,11 +72,11 @@ Base.setindex!(A::StarWarsArray, v, i::Int) = Base.setindex!(A::StarWarsArray{T,N}, v, i::Vararg{Int,N}) where {T,N} = setindex!(parent(A), v, index.(i, size(parent(A)), order(A))...) +Base.axes(A::StarWarsArray{T,N,P,MacheteOrder}) where {T,N,P} = + map(i->index.(i .+ 1, length(A), MacheteOrder), machete_view_index.(size(A))) + # Showing. Note: this is awful, but it does what I want Base.show(io::IO, m::MIME"text/plain", A::StarWarsArray{T,N,P,MacheteOrder}) where {T,N,P} = - show(io, m, - view(parent(A), - map(i->StarWarsArrays.index.(i .+ 1, length(A), MacheteOrder), - StarWarsArrays.machete_view_index.(size(A)))...)) + show(io, m, view(parent(A), axes(A)...)) end # module diff --git a/test/runtests.jl b/test/runtests.jl index 46080b7..df332ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,6 +40,7 @@ end @test_throws BoundsError v[0] v[4] = -42 @test v[4] == -42 + @test axes(v) == ([3, 4, 1, 2, 5, 6, 7, 8],) m = StarWarsArray(reshape(collect(1:81), 9, 9), MacheteOrder) @test order(m) == MacheteOrder @@ -60,6 +61,7 @@ end @test m[4] == -42 m[2] = 0 @test m[2,4] == 0 + @test axes(m) == ([3, 4, 1, 2, 5, 6, 7, 8], [3, 4, 1, 2, 5, 6, 7, 8]) @test sprint(showerror, StarWarsArrays.StarWarsError(1, MacheteOrder)) == "StarWarsError: there is no episode 1 in MacheteOrder"