diff --git a/src/StructTypes.jl b/src/StructTypes.jl index e1b7325..4fe335b 100644 --- a/src/StructTypes.jl +++ b/src/StructTypes.jl @@ -459,6 +459,9 @@ construct(::Type{Symbol}, ptr::Ptr{UInt8}, len::Int; kw...) = _symbol(ptr, len) construct(::Type{T}, str::String; dateformat::Dates.DateFormat=Dates.default_format(T), kw...) where {T <: Dates.TimeType} = T(str, dateformat) construct(::Type{UUID}, arg; kw...) = UUID(arg) +# these constructors take no keywords, so read keywords (like `dateformat`) are dropped +construct(::Type{T}, str::String; kw...) where {T <: Union{Symbol, VersionNumber, Regex}} = T(str) +construct(::Type{T}, x::AbstractVector; kw...) where {T <: AbstractSet} = T(x) """ StructTypes.StructType(::Type{T}) = StructTypes.NumberType() diff --git a/test/runtests.jl b/test/runtests.jl index adf3c57..e4de31a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -212,6 +212,14 @@ x = "499beb72-22ea-11ea-3366-55749430b981" @test StructTypes.construct(UUID, pointer(x), 36) == UUID(x) @test StructTypes.construct(UUID, pointer(x), 36; dateformat=dateformat"mm-dd-yyyy") == UUID(x) @test StructTypes.construct(Date, "11-30-2019"; dateformat=dateformat"mm-dd-yyyy") == Date(2019, 11, 30) +# read keywords don't reach constructors that take none +df = dateformat"yyyy" +@test StructTypes.construct(Symbol, "hey"; dateformat=df) === :hey +@test StructTypes.construct(VersionNumber, "1.2.3"; dateformat=df) == v"1.2.3" +@test StructTypes.construct(Regex, "a.c"; dateformat=df) == r"a.c" +@test StructTypes.construct(Set{Int}, [1, 2, 2]; dateformat=df) == Set([1, 2]) +@test StructTypes.construct(Set, Any[1, "a"]; dateformat=df) == Set(Any[1, "a"]) +@test StructTypes.construct(BitSet, [3, 1]; dateformat=df) == BitSet([1, 3]) @test StructTypes.StructType(UInt8) == StructTypes.NumberType() @test StructTypes.StructType(Int8) == StructTypes.NumberType()