Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container should be idempotent #21

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading