Skip to content

Commit

Permalink
container should be idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
miRoox committed Nov 20, 2023
1 parent 3c195f2 commit 818d7bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ end
setcontainerproperty!(obj::AnyContainer, name::Symbol, value::Any) = getfield(obj, 1)[name] = value
setcontainerproperty!(obj::ShadowContainer, name::Symbol, value) = setfield!(obj, name, value)

Base.:(==)(x::AnyContainer{T}, y::AnyContainer{T}) where {T} = all(p -> getproperty(x, p) == getproperty(y, p), fieldnames(T))
Base.:(!=)(x::AnyContainer{T}, y::AnyContainer{T}) where {T} = any(p -> getproperty(x, p) != getproperty(y, p), fieldnames(T))

Base.summary(io::IO, ::Container{T}) where {T} = show(io, Container{T})

function Base.show(io::IO, obj::Container)
Expand Down Expand Up @@ -115,3 +118,4 @@ function Container(obj::T) where {T}
end
res
end
Container(c::Container) = c
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ end
@test repr(UndefProperty()) == "#undef"
@test_throws ArgumentError Container(1)
@test Container(im).im
@test Container(Container(1//2)) == Container(1//2)
@test Container(Container(2//1)) != Container(1//2)
@test Container{Complex{Bool}}().im == UndefProperty{Bool}()
@test Container{Complex{Rational{Int}}}().im.num == UndefProperty{Int}()
@test_throws ErrorException Container{Complex{Bool}}().i
Expand Down

0 comments on commit 818d7bb

Please sign in to comment.