Skip to content

Commit

Permalink
WeakRefStringArray: allow only WeakRefString elems
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Dec 20, 2017
1 parent 45d595d commit 092d943
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/WeakRefStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Base.convert(::Type{String}, x::WeakRefString) = convert(String, string(x))
Base.String(x::WeakRefString) = string(x)
Base.Symbol(x::WeakRefString{UInt8}) = ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int), x.ptr, x.len)

struct WeakRefStringArray{T, N, U} <: AbstractArray{Union{String, U}, N}
struct WeakRefStringArray{T<:WeakRefString, N, U} <: AbstractArray{Union{String, U}, N}
data::Vector{Any}
elements::Array{Union{T, U}, N}

Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ end
E = WeakRefStringArray(data, [str missing])
@test size(E) == (1, 2)
@test eltype(E) === Union{String, Missing}

# WeakRefStringArray only supports WeakRefString elements
@test_throws MethodError WeakRefStringArray(UInt8[], String, 0)
@test_throws MethodError WeakRefStringArray(UInt8[], Int, 0)
@test_throws MethodError WeakRefStringArray(UInt8[], Union{String, Missing}, 0)
@test_throws MethodError WeakRefStringArray(UInt8[], Union{Int, Missing}, 0)
@test_throws MethodError WeakRefStringArray(UInt8[], [1, 2])
@test_throws MethodError WeakRefStringArray(UInt8[], [1.0, missing])
end

0 comments on commit 092d943

Please sign in to comment.