Skip to content

Commit

Permalink
fix: Overwrite type deduction test
Browse files Browse the repository at this point in the history
  • Loading branch information
miRoox committed Mar 23, 2024
1 parent 0098ae4 commit 1a73a43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Overwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ julia> deserialize(Overwrite(UInt8, 0x01), b"\\x05")
```
"""
Overwrite(subcon::Construct{T}, value::T) where {T} = Overwrite(subcon, ((obj; contextkw...) -> value))
Overwrite(::Type{T}, getter) where {T} = Overwrite(Construct(T), getter)
Overwrite(::Type{T}, getter::GT) where {T, GT<:Union{T, Function, UndefProperty}} = Overwrite(Construct(T), getter)

encode(cons::Overwrite{T, TSubCon, GT}, obj::T; contextkw...) where {T, TSubCon, GT<:Function} = convert(T, apply_optional_contextkw(cons.getter, obj, contextkw))
# getter could be undefined when deserializing
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ end
@testset "Overwrite" begin
@testset "deduce type" begin
@test Constructs.deducetype((v) -> Overwrite(UInt8, v), UInt8) <: Construct{UInt8}
@test Constructs.deducetype((v) -> Overwrite(UInt8, v), Function) <: Construct{UInt8}
@test Constructs.deducetype((v) -> Overwrite(UInt8, v), UndefProperty) <: Construct{UInt8}
@test Constructs.deducetype((v) -> Overwrite(Int8, v), typeof(abs)) <: Construct{Int8}
@test Constructs.deducetype((v) -> Overwrite(UInt8, v), UndefProperty{UInt8}) <: Construct{UInt8}
end
@test_throws ArgumentError Overwrite(UInt8, () -> 0x01)
@test serialize(Overwrite(UInt8, 0x01), 2) == b"\x01"
Expand Down

0 comments on commit 1a73a43

Please sign in to comment.