Skip to content

Commit be0d904

Browse files
committed
Fix doctests and printing
1 parent ae2df42 commit be0d904

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/blockindices.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ end
302302

303303
# deleted code that isn't used, such as 0-dimensional case
304304
"""
305-
BlockRange(axes::Tuple{AbstractUnitRange{Int}})
306-
BlockRange(sizes::Vararg{Integer})
305+
BlockRange(axes::Tuple{AbstractUnitRange{Vararg{Int}}})
306+
BlockRange(sizes::Tuple{Vararg{Integer}})
307307
308308
Represent a Cartesian range of blocks.
309309
@@ -312,18 +312,18 @@ The relationship between `Block` and `BlockRange` mimics the relationship betwee
312312
313313
# Examples
314314
```jldoctest
315-
julia> BlockRange(2:3, 3:4) |> collect
315+
julia> BlockRange((2:3, 3:4)) |> collect
316316
2×2 Matrix{Block{2, Int64}}:
317317
Block(2, 3) Block(2, 4)
318318
Block(3, 3) Block(3, 4)
319319
320-
julia> BlockRange(2, 2) |> collect # number of elements, starting at 1
320+
julia> BlockRange((2, 2)) |> collect # number of elements, starting at 1
321321
2×2 Matrix{Block{2, Int64}}:
322322
Block(1, 1) Block(1, 2)
323323
Block(2, 1) Block(2, 2)
324324
325325
julia> Block(1):Block(2)
326-
BlockRange(1:2)
326+
BlockRange((1:2,))
327327
```
328328
"""
329329
BlockRange

src/show.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ end
212212

213213
# BlockRange
214214

215-
Base.show(io::IO, br::BlockRange) = print(io, "BlockRange(", join(br.indices, ", "), ")")
215+
function Base.show(io::IO, br::BlockRange)
216+
print(io, "BlockRange(")
217+
show(io, map(_xform_index, br.indices))
218+
print(io, ")")
219+
end
220+
_xform_index(i) = i
221+
_xform_index(i::Base.OneTo) = i.stop
216222
Base.show(io::IO, ::MIME"text/plain", br::BlockRange) = show(io, br)
217223

218224
# AbstractBlockedUnitRange

test/test_blockindices.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,14 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
157157
@test sprint(show, "text/plain", BlockIndex((1,2), (3,4))) == "Block(1, 2)[3, 4]"
158158
@test sprint(show, "text/plain", BlockArrays.BlockIndexRange(Block(1), 3:4)) == "Block(1)[3:4]"
159159

160-
@test sprint(show, "text/plain", BlockRange(())) == "BlockRange()"
161-
@test sprint(show, "text/plain", BlockRange((1:2,))) == "BlockRange(1:2)"
162-
@test sprint(show, "text/plain", BlockRange((1:2, 2:3,))) == "BlockRange(1:2, 2:3)"
163-
@test sprint(show, BlockRange((1:2, 2:3))) == "BlockRange(1:2, 2:3)"
160+
@test sprint(show, "text/plain", BlockRange(())) == "BlockRange(())"
161+
@test sprint(show, "text/plain", BlockRange((1:2,))) == "BlockRange((1:2,))"
162+
@test sprint(show, "text/plain", BlockRange((2,))) == "BlockRange((2,))"
163+
@test sprint(show, "text/plain", BlockRange((Base.OneTo(2),))) == "BlockRange((2,))"
164+
@test sprint(show, "text/plain", BlockRange((1:2, 2:3,))) == "BlockRange((1:2, 2:3))"
165+
@test sprint(show, "text/plain", BlockRange((2, 3,))) == "BlockRange((2, 3))"
166+
@test sprint(show, "text/plain", BlockRange(Base.OneTo.((2, 3)))) == "BlockRange((2, 3))"
167+
@test sprint(show, BlockRange((1:2, 2:3))) == "BlockRange((1:2, 2:3))"
164168
end
165169
end
166170

test/test_blockrange.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ using BlockArrays, Test
66
# test backend code
77
@test BlockRange((1:3,)) == BlockRange{1,Tuple{UnitRange{Int}}}((1:3,))
88
@test BlockRange(1:3) === BlockRange(Base.OneTo(1))
9+
@test BlockRange(blockedrange([2,3])) === BlockRange((Base.OneTo(2),))
10+
@test BlockRange(blockedrange(2,[2,3])) === BlockRange((Base.OneTo(2),))
911
@test_throws ArgumentError Block(1,1):Block(2,2)
12+
@test_throws MethodError BlockRange(1:3, 1:3)
13+
@test_throws MethodError BlockRange(3)
14+
@test_throws MethodError BlockRange(3, 3)
15+
@test_throws MethodError BlockRange()
1016

1117
@test eltype(Block.(1:2)) == Block{1,Int}
1218
@test eltype(typeof(Block.(1:2))) == Block{1,Int}

0 commit comments

Comments
 (0)