Skip to content

Commit 2ed1598

Browse files
authored
add doctest in unittest (#158)
* add doctest in unittest * only do doctest for julia >= 1.2 * also interpolate Int
1 parent 1fb1716 commit 2ed1598

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ julia = "0.7, 1"
99
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1010
CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91"
1111
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
12+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1213
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1314
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1415

1516
[targets]
16-
test = ["Aqua", "CatIndices", "DelimitedFiles", "Test", "LinearAlgebra"]
17+
test = ["Aqua", "CatIndices", "DelimitedFiles", "Documenter", "Test", "LinearAlgebra"]

src/OffsetArrays.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Integers are recognized as offsets, where `0` means no offsets are applied:
3434
3535
```jldoctest; setup=:(using OffsetArrays)
3636
julia> A = OffsetArray(reshape(1:6, 2, 3), -1, -2)
37-
2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1:
37+
2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1:
3838
1 3 5
3939
2 4 6
4040
@@ -47,17 +47,17 @@ Examples of range-like types are: `Colon()`(aka `:`), `UnitRange`(e.g, `-1:2`),
4747
4848
```jldoctest; setup=:(using OffsetArrays)
4949
julia> OffsetArray(reshape(1:6, 2, 3), 0:1, -1:1)
50-
2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1:
50+
2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1:
5151
1 3 5
5252
2 4 6
5353
5454
julia> OffsetArray(reshape(1:6, 2, 3), :, -1:1) # : as a placeholder means no offset is applied at this dimension
55-
2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 1:2, -1:1) with eltype Int64 with indices 1:2×-1:1:
55+
2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 1:2, -1:1) with eltype $Int with indices 1:2×-1:1:
5656
1 3 5
5757
2 4 6
5858
5959
julia> OffsetArray(reshape(1:6, 2, 3), CartesianIndex(0, -1):CartesianIndex(1, 1))
60-
2×3 OffsetArray(reshape(::UnitRange{Int64}, 2, 3), 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1:
60+
2×3 OffsetArray(reshape(::UnitRange{$Int}, 2, 3), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1:
6161
1 3 5
6262
2 4 6
6363
```
@@ -77,12 +77,12 @@ ERROR: [...]
7777
julia> a = [1 2; 3 4];
7878
7979
julia> OffsetArray(a, OffsetArrays.Origin(0, 1))
80-
2×2 OffsetArray(::$(Array{Int64,2}), 0:1, 1:2) with eltype Int64 with indices 0:1×1:2:
80+
2×2 OffsetArray(::$(Array{Int,2}), 0:1, 1:2) with eltype $Int with indices 0:1×1:2:
8181
1 2
8282
3 4
8383
8484
julia> OffsetArray(a, OffsetArrays.Origin(0)) # short notation for `Origin(0, ..., 0)`
85-
2×2 OffsetArray(::$(Array{Int64, 2}), 0:1, 0:1) with eltype Int64 with indices 0:1×0:1:
85+
2×2 OffsetArray(::$(Array{Int, 2}), 0:1, 0:1) with eltype $Int with indices 0:1×0:1:
8686
1 2
8787
3 4
8888
```
@@ -357,15 +357,15 @@ specific to remove a level of indirection when applicable.
357357
julia> A = [1 3 5; 2 4 6];
358358
359359
julia> O = OffsetArray(A, 0:1, -1:1)
360-
2×3 OffsetArray(::Matrix{Int64}, 0:1, -1:1) with eltype Int64 with indices 0:1×-1:1:
360+
2×3 OffsetArray(::$(Matrix{Int}), 0:1, -1:1) with eltype $Int with indices 0:1×-1:1:
361361
1 3 5
362362
2 4 6
363363
364364
julia> OffsetArrays.no_offset_view(O)[1,1] = -9
365365
-9
366366
367367
julia> A
368-
2×3 Matrix{Int64}:
368+
2×3 $(Matrix{Int}):
369369
-9 3 5
370370
2 4 6
371371
```

src/axes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ julia> ro[-1]
2020
-1
2121
2222
julia> ro[3]
23-
ERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [5]
23+
ERROR: BoundsError: attempt to access 3-element UnitRange{$Int} at index [5]
2424
```
2525
2626
If the range doesn't start at 1, the values may be different from the indices:
@@ -35,7 +35,7 @@ julia> ro[-1]
3535
9
3636
3737
julia> ro[3]
38-
ERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [5]
38+
ERROR: BoundsError: attempt to access 3-element UnitRange{$Int} at index [5]
3939
```
4040
4141
# Extended help

src/origin.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ The `origin` of an array is defined as the index of its first element, i.e., `fi
1313
julia> a = [1 2; 3 4];
1414
1515
julia> OffsetArray(a, OffsetArrays.Origin(0, 1))
16-
2×2 OffsetArray(::$(Array{Int64,2}), 0:1, 1:2) with eltype Int64 with indices 0:1×1:2:
16+
2×2 OffsetArray(::$(Array{Int,2}), 0:1, 1:2) with eltype $Int with indices 0:1×1:2:
1717
1 2
1818
3 4
1919
2020
julia> OffsetArray(a, OffsetArrays.Origin(0)) # short notation for `Origin(0, 0)`
21-
2×2 OffsetArray(::$(Array{Int64, 2}), 0:1, 0:1) with eltype Int64 with indices 0:1×0:1:
21+
2×2 OffsetArray(::$(Array{Int, 2}), 0:1, 0:1) with eltype $Int with indices 0:1×0:1:
2222
1 2
2323
3 4
2424
```

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using OffsetArrays
22
using OffsetArrays: IdentityUnitRange, no_offset_view
33
using OffsetArrays: IdOffsetRange
4-
using Test, Aqua
4+
using Test, Aqua, Documenter
55
using LinearAlgebra
66
using DelimitedFiles
77
using CatIndices: BidirectionalVector
@@ -15,6 +15,9 @@ end
1515
@testset "Project meta quality checks" begin
1616
# Not checking compat section for test-only dependencies
1717
Aqua.test_all(OffsetArrays; project_extras=true, deps_compat=true, stale_deps=true, project_toml_formatting=true)
18+
if VERSION >= v"1.2"
19+
doctest(OffsetArrays, manual = false)
20+
end
1821
end
1922

2023
@testset "IdOffsetRange" begin

0 commit comments

Comments
 (0)