Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Dec 15, 2017
1 parent c8ba97a commit e44a7df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion base/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ promote_rule(::Type{Missing}, ::Type{Any}) = Any
promote_rule(::Type{Missing}, ::Type{Missing}) = Missing

convert(::Type{Union{T, Missing}}, x) where {T} = convert(T, x)
# To fix ambiguities
convert(::Type{Missing}, ::Missing) = missing
convert(::Type{Void}, ::Void) = nothing
convert(::Type{Union{Void, Missing}}, x::Union{Void, Missing}) = x
convert(::Type{Union{Void, Missing}}, x) =
throw(MethodError(convert, (Union{Void, Missing}, x)))
# To print more appropriate message than "T not defined"
convert(::Type{Missing}, x) = throw(MethodError(convert, (Missing, x)))
convert(::Type{Missing}, ::Missing) = missing

# Comparison operators
==(::Missing, ::Missing) = missing
Expand Down
4 changes: 4 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ end
@testset "convert" begin
@test convert(Union{Int, Missing}, 1) === 1
@test convert(Union{Int, Missing}, 1.0) === 1
@test convert(Union{Void, Missing}, missing) === missing
@test convert(Union{Void, Missing}, nothing) === nothing

@test_throws MethodError convert(Missing, 1)
@test_throws MethodError convert(Union{Void, Missing}, 1)
@test_throws MethodError convert(Union{Int, Missing}, "a")
end

Expand Down
2 changes: 1 addition & 1 deletion test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ end
end

@testset "issue #10307" begin
@test typeof(map(x -> parse(Int16, x), AbstractString[])) == Vector{Int16}
@test typeof(map(x -> parse(Int16, x), AbstractString[])) == Vector{Union{Int16, Void}}

for T in [Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128]
for i in [typemax(T), typemin(T)]
Expand Down

0 comments on commit e44a7df

Please sign in to comment.