From 830f116f95d7f6a6302d13742cdaf40367820287 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 23 Sep 2020 17:33:43 +0800 Subject: [PATCH 1/3] add doctest in unittest --- Project.toml | 3 ++- src/OffsetArrays.jl | 4 ++-- test/runtests.jl | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 2c119090..f087d1f8 100644 --- a/Project.toml +++ b/Project.toml @@ -9,8 +9,9 @@ julia = "0.7, 1" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "CatIndices", "DelimitedFiles", "Test", "LinearAlgebra"] +test = ["Aqua", "CatIndices", "DelimitedFiles", "Documenter", "Test", "LinearAlgebra"] diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index fd7cc562..46f819e9 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -345,7 +345,7 @@ specific to remove a level of indirection when applicable. julia> A = [1 3 5; 2 4 6]; julia> O = OffsetArray(A, 0:1, -1:1) -2×3 OffsetArray(::Matrix{Int64}, 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: +2×3 OffsetArray(::$(Matrix{Int64}), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: 1 3 5 2 4 6 @@ -353,7 +353,7 @@ julia> OffsetArrays.no_offset_view(O)[1,1] = -9 -9 julia> A -2×3 Matrix{Int64}: +2×3 $(Matrix{Int64}): -9 3 5 2 4 6 ``` diff --git a/test/runtests.jl b/test/runtests.jl index 1a29cf7a..7dc1bc51 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ using OffsetArrays using OffsetArrays: IdentityUnitRange, no_offset_view using OffsetArrays: IdOffsetRange -using Test, Aqua +using Test, Aqua, Documenter using LinearAlgebra using DelimitedFiles using CatIndices: BidirectionalVector @@ -15,6 +15,7 @@ end @testset "Project meta quality checks" begin # Not checking compat section for test-only dependencies Aqua.test_all(OffsetArrays; project_extras=true, deps_compat=true, stale_deps=true, project_toml_formatting=true) + doctest(OffsetArrays, manual = false) end @testset "IdOffsetRange" begin From d3c7d0142d5ade621e938d26e83e8801cd8d1b2a Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 23 Sep 2020 18:50:59 +0800 Subject: [PATCH 2/3] only do doctest for julia >= 1.2 --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7dc1bc51..7a1888a5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,7 +15,9 @@ end @testset "Project meta quality checks" begin # Not checking compat section for test-only dependencies Aqua.test_all(OffsetArrays; project_extras=true, deps_compat=true, stale_deps=true, project_toml_formatting=true) - doctest(OffsetArrays, manual = false) + if VERSION >= v"1.2" + doctest(OffsetArrays, manual = false) + end end @testset "IdOffsetRange" begin From 07e8af52a9cf6f512d564f7c321ccddd2127bb7d Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 23 Sep 2020 19:56:50 +0800 Subject: [PATCH 3/3] also interpolate Int --- src/OffsetArrays.jl | 16 ++++++++-------- src/axes.jl | 4 ++-- src/origin.jl | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index 46f819e9..b3ac55d4 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -34,7 +34,7 @@ Integers are recognized as offsets, where `0` means no offsets are applied: ```jldoctest; setup=:(using OffsetArrays) julia> A = OffsetArray(reshape(1:6, 2, 3), -1, -2) -2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: +2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1: 1 3 5 2 4 6 @@ -47,17 +47,17 @@ Examples of range-like types are: `Colon()`(aka `:`), `UnitRange`(e.g, `-1:2`), ```jldoctest; setup=:(using OffsetArrays) julia> OffsetArray(reshape(1:6, 2, 3), 0:1, -1:1) -2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: +2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1: 1 3 5 2 4 6 julia> OffsetArray(reshape(1:6, 2, 3), :, -1:1) # : as a placeholder means no offset is applied at this dimension -2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 1:2, -1:1) with eltype Int64 with indices 1:2×-1:1: +2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 1:2, -1:1) with eltype $Int with indices 1:2×-1:1: 1 3 5 2 4 6 julia> OffsetArray(reshape(1:6, 2, 3), CartesianIndex(0, -1):CartesianIndex(1, 1)) -2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: +2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1: 1 3 5 2 4 6 ``` @@ -77,12 +77,12 @@ ERROR: [...] julia> a = [1 2; 3 4]; julia> OffsetArray(a, OffsetArrays.Origin(0, 1)) -2×2 OffsetArray(::$(Array{Int64,2}), 0:1, 1:2) with eltype Int64 with indices 0:1×1:2: +2×2 OffsetArray(::$(Array{Int,2}), 0:1, 1:2) with eltype $Int with indices 0:1×1:2: 1 2 3 4 julia> OffsetArray(a, OffsetArrays.Origin(0)) # short notation for `Origin(0, ..., 0)` -2×2 OffsetArray(::$(Array{Int64, 2}), 0:1, 0:1) with eltype Int64 with indices 0:1×0:1: +2×2 OffsetArray(::$(Array{Int, 2}), 0:1, 0:1) with eltype $Int with indices 0:1×0:1: 1 2 3 4 ``` @@ -345,7 +345,7 @@ specific to remove a level of indirection when applicable. julia> A = [1 3 5; 2 4 6]; julia> O = OffsetArray(A, 0:1, -1:1) -2×3 OffsetArray(::$(Matrix{Int64}), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1: +2×3 OffsetArray(::$(Matrix{Int}), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1: 1 3 5 2 4 6 @@ -353,7 +353,7 @@ julia> OffsetArrays.no_offset_view(O)[1,1] = -9 -9 julia> A -2×3 $(Matrix{Int64}): +2×3 $(Matrix{Int}): -9 3 5 2 4 6 ``` diff --git a/src/axes.jl b/src/axes.jl index 105fdb85..0de4739b 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -20,7 +20,7 @@ julia> ro[-1] -1 julia> ro[3] -ERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [5] +ERROR: BoundsError: attempt to access 3-element UnitRange{$Int} at index [5] ``` If the range doesn't start at 1, the values may be different from the indices: @@ -35,7 +35,7 @@ julia> ro[-1] 9 julia> ro[3] -ERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [5] +ERROR: BoundsError: attempt to access 3-element UnitRange{$Int} at index [5] ``` # Extended help diff --git a/src/origin.jl b/src/origin.jl index 9aa21d81..b92b6a2a 100644 --- a/src/origin.jl +++ b/src/origin.jl @@ -13,12 +13,12 @@ The `origin` of an array is defined as the index of its first element, i.e., `fi julia> a = [1 2; 3 4]; julia> OffsetArray(a, OffsetArrays.Origin(0, 1)) -2×2 OffsetArray(::$(Array{Int64,2}), 0:1, 1:2) with eltype Int64 with indices 0:1×1:2: +2×2 OffsetArray(::$(Array{Int,2}), 0:1, 1:2) with eltype $Int with indices 0:1×1:2: 1 2 3 4 julia> OffsetArray(a, OffsetArrays.Origin(0)) # short notation for `Origin(0, 0)` -2×2 OffsetArray(::$(Array{Int64, 2}), 0:1, 0:1) with eltype Int64 with indices 0:1×0:1: +2×2 OffsetArray(::$(Array{Int, 2}), 0:1, 0:1) with eltype $Int with indices 0:1×0:1: 1 2 3 4 ```