Skip to content

Commit 6ea14d6

Browse files
committed
Add tests for assymetric zips
Addresses #58922 @adienes had a good idea to test against OffsetArrays but these are not in base so they are currently commented out
1 parent b61c60c commit 6ea14d6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test/iterators.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ end
11401140
end
11411141

11421142
@testset "nth" begin
1143-
11441143
Z = Array{Int,0}(undef)
11451144
Z[] = 17
11461145
it_result_pairs = Dict(
@@ -1170,7 +1169,6 @@ end
11701169
(Iterators.cycle(((),)), 1000) => ()
11711170
)
11721171

1173-
11741172
@testset "iter: $IT" for (IT, n) in keys(it_result_pairs)
11751173
@test it_result_pairs[(IT, n)] == nth(IT, n)
11761174
@test_throws BoundsError nth(IT, -42)
@@ -1206,3 +1204,18 @@ end
12061204
@test Base.infer_return_type((Vector{Any},)) do xs
12071205
[x for x in xs if x isa Int]
12081206
end == Vector{Int}
1207+
1208+
@testset "issue #58922" begin
1209+
# `last` short circuits correctly
1210+
@test last(zip(1:10, 2:11)) == (10, 11) # same length
1211+
@test last(zip(1:3, 2:11)) == (3, 4) # different length
1212+
1213+
# Finite-guarded zip iterator: one iterator bounded and the other is not
1214+
@test last(zip(1:3, Iterators.countfrom(2))) == (3, 4)
1215+
@test last(zip(1:3, Iterators.cycle(('x', 'y')))) == (3, 'x')
1216+
@test last(zip(1:3, Iterators.repeated('x'))) == (3, 'x')
1217+
1218+
# TODO: test for other array types
1219+
# @test last(zip(OffsetArray(1:10, 2), OffsetArray(1:10, 3))) == (10, 10)
1220+
# @test last(collect(zip(OffsetArray(1:10, 2), OffsetArray(1:10, 3)))) == (10, 10)
1221+
end

0 commit comments

Comments
 (0)