Skip to content

Commit

Permalink
Merge pull request #25 from xiaodaigh/bugfix/vcat_promote_rule
Browse files Browse the repository at this point in the history
fixed
  • Loading branch information
xiaodaigh authored Oct 31, 2020
2 parents 8ff5af2 + 04bfac2 commit 47de9c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ function Base.cmp(a::ShortString{S}, b::ShortString{S}) where S
end

promote_rule(::Type{String}, ::Type{ShortString{S}}) where S = String
promote_rule(::Type{ShortString{T}}, ::Type{ShortString{S}}) where {T,S} = ShortString{promote_rule(T,S)}

function promote_rule(::Type{ShortString{T}}, ::Type{ShortString{S}}) where {T,S}
if sizeof(T) >= sizeof(S)
return ShortString{promote_rule(T,S)}
else
return ShortString{promote_rule(S,T)}
end
end

size_content(s::ShortString) = s.size_content

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ end

@test_throws ErrorException ShortString3(ShortString7("123456"))
end

@testset "promote rule" begin
@test vcat(ShortString3["ab", "cd"], ShortString7["abcd", "efgc"]) == vcat(ShortString3["ab", "cd"], ["abcd", "efgc"])
@test vcat(ShortString3["ab", "cd"], ShortString7["abcd", "efgc"]) == vcat(["ab", "cd"], ShortString7["abcd", "efgc"])
end

0 comments on commit 47de9c9

Please sign in to comment.