Skip to content

Commit

Permalink
Add StructType trait definition for Base.VersionNumber (#44)
Browse files Browse the repository at this point in the history
It already satisfies the `StringType` interface, so it's an easy
definition. Fixes one issue mentioned in
quinnj/JSON3.jl#139.
  • Loading branch information
quinnj committed Apr 13, 2021
1 parent 3a624e0 commit 070bb78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/StructTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ StructType(::Type{<:Enum}) = StringType()
StructType(::Type{<:AbstractChar}) = StringType()
StructType(::Type{UUID}) = StringType()
StructType(::Type{T}) where {T <: Dates.TimeType} = StringType()
StructType(::Type{VersionNumber}) = StringType()

function construct(::Type{Char}, str::String; kw...)
if length(str) == 1
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ x = "499beb72-22ea-11ea-3366-55749430b981"

@test StructTypes.construct(Date, Date(2020)) == Date(2020)

# https://github.com/quinnj/JSON3.jl/issues/139
v = v"1.2.3"
@test StructTypes.StructType(v) == StructTypes.StringType()

end

struct B
Expand Down

0 comments on commit 070bb78

Please sign in to comment.