Skip to content

Commit 58796f1

Browse files
committed
More broadcast tests
1 parent 85b8483 commit 58796f1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/broadcast.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ import Base.Meta: isexpr
300300
# PR 16988
301301
@test Base.promote_op(+, Bool) === Int
302302
@test isa(broadcast(+, [true]), Array{Int,1})
303-
@test Base.promote_op(Float64, Bool) === Float64
304303

305304
# issue #17304
306305
let foo = [[1,2,3],[4,5,6],[7,8,9]]
@@ -312,7 +311,7 @@ end
312311
let f17314 = x -> x < 0 ? false : x
313312
@test eltype(broadcast(f17314, 1:3)) === Int
314313
@test eltype(broadcast(f17314, -1:1)) === Integer
315-
@test eltype(broadcast(f17314, Int[])) === Any
314+
@test eltype(broadcast(f17314, Int[])) === Union{Bool,Int}
316315
end
317316
let io = IOBuffer()
318317
broadcast(x->print(io,x), 1:5) # broadcast with side effects
@@ -337,3 +336,18 @@ end
337336
@test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0)
338337
@test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0]
339338
@test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"]
339+
340+
# Ensure that even strange constructors that break `T(x)::T` work with broadcast
341+
immutable StrangeType18623 end
342+
StrangeType18623(x) = x
343+
StrangeType18623(x,y) = (x,y)
344+
@test @inferred broadcast(StrangeType18623, 1:3) == [1,2,3]
345+
@test @inferred broadcast(StrangeType18623, 1:3, 4:6) == [(1,4),(2,5),(3,6)]
346+
347+
@test typeof(Int.(Number[1, 2, 3])) === typeof((x->Int(x)).(Number[1, 2, 3]))
348+
349+
@test @inferred broadcast(CartesianIndex, 1:2) == [CartesianIndex(1), CartesianIndex(2)]
350+
@test @inferred broadcast(CartesianIndex, 1:2, 3:4) == [CartesianIndex(1,3), CartesianIndex(2,4)]
351+
352+
# Issue 18622
353+
@test @inferred tuple.(1:3, 4:6, 7:9)::Vector{Tuple{Int,Int,Int}} == [(1,4,7), (2,5,8), (3,6,9)]

0 commit comments

Comments
 (0)