From cfd7b19edd74dc307df9594e1197babb31f678f9 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 2 Sep 2017 14:24:39 -0500 Subject: [PATCH] Fix writing arrays with unconventional indices --- src/Writer.jl | 2 +- test/REQUIRE | 1 + test/runtests.jl | 1 + test/standard-serializer.jl | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Writer.jl b/src/Writer.jl index e0e93a8..9bcb57a 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -315,7 +315,7 @@ Serialize a multidimensional array to JSON in column-major format. That is, function show_json{T,n}(io::SC, s::CS, A::AbstractArray{T,n}) begin_array(io) newdims = ntuple(_ -> :, Val{n - 1}) - for j in 1:size(A, n) + for j in indices(A, n) show_element(io, s, view(A, newdims..., j)) end end_array(io) diff --git a/test/REQUIRE b/test/REQUIRE index 01ba106..d0dacdd 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1,3 @@ DataStructures FixedPointNumbers +OffsetArrays diff --git a/test/runtests.jl b/test/runtests.jl index bdcb58e..a879df7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using JSON using Base.Test using Compat +using OffsetArrays import DataStructures diff --git a/test/standard-serializer.jl b/test/standard-serializer.jl index 1a34183..a5b846a 100644 --- a/test/standard-serializer.jl +++ b/test/standard-serializer.jl @@ -56,6 +56,7 @@ end #Multidimensional arrays @test json([0 1; 2 0]) == "[[0,2],[1,0]]" + @test json(OffsetArray([0 1; 2 0], 0:1, 10:11)) == "[[0,2],[1,0]]" end @testset "Pairs" begin