Skip to content
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
5 changes: 5 additions & 0 deletions base/some.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@ macro something(args...)
end
return expr
end

==(a::Some, b::Some) = a.value == b.value
isequal(a::Some, b::Some)::Bool = isequal(a.value, b.value)
const hash_some_seed = UInt == UInt64 ? 0xde5c997007a4ca3a : 0x78c29c09
hash(s::Some, h::UInt) = hash(s.value, hash_some_seed + h)
26 changes: 26 additions & 0 deletions test/some.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@
@test !isequal(Some(1), nothing)
@test !isequal(Some(nothing), nothing)

# Some with something else is false
@test !=(Some(nothing), nothing)
@test !=(nothing, Some(nothing))

# Two `Some`s forward to their wrapped things
@test ==(Some([0x1]), Some([1]))

# propagate wrapped missings
@test !=(Some(1), Some(missing)) isa Missing
@test !=(Some(missing), Some(1)) isa Missing
@test ==(Some(missing), Some(missing)) isa Missing

# Make sure to still propagate non-wrapped Missing
@test ==(Some(1), missing) isa Missing
@test ==(missing, Some(1)) isa Missing

@test isequal(Some([0x1]), Some([1]))
@test !isequal(missing, Some(missing))
@test !isequal(Some(missing), missing)
@test isequal(Some(missing), Some(missing))

# hashing implications
@test hash(Some(0x1)) != hash(0x1)
@test hash(Some(0x1)) == hash(Some(1))
@test hash((Some(1),)) != hash((1, Some))

@testset "something" begin
@test_throws ArgumentError something()
@test something(1) === 1
Expand Down