Skip to content

Commit

Permalink
Support Empty{SVector}
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Dec 20, 2019
1 parent ac190bc commit 674c613
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/NoBang/emptycontainers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ julia> @assert push!!(Empty(StructVector), (a=1, b=2)) == StructVector(a=[1], b=
julia> using TypedTables: Table
julia> @assert push!!(Empty(Table), (a=1, b=2)) == Table(a=[1], b=[2])
julia> using StaticArrays: SVector
julia> @assert push!!(Empty(SVector), 1) === SVector(1)
```
`Empty(T)` object is an iterable with length 0 and element type `Union{}`:
Expand Down
6 changes: 6 additions & 0 deletions src/NoBang/singletonof.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ julia> @assert singletonof(StructVector, (a=1, b=2)) == StructVector(a=[1], b=[2
julia> using TypedTables: Table
julia> @assert singletonof(Table, (a=1, b=2)) == Table(a=[1], b=[2])
julia> using StaticArrays: SArray, SVector
julia> @assert singletonof(SArray, 1) === SVector(1)
julia> @assert singletonof(SVector, 1) === SVector(1)
```
"""
singletonof(::Type{T}, x) where T = T(SingletonVector(x))
Expand Down
5 changes: 5 additions & 0 deletions src/NoBang/staticarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ _empty(xs::StaticArrays.StaticVector) =
StaticArrays.pop(xs)
end
_setindex(xs::StaticArrays.StaticArray, v, I...) = Base.setindex(xs, v, I...)

StaticArrays.SArray(x::SingletonVector) = StaticArrays.SVector{1}(x)
StaticArrays.SVector(x::SingletonVector) = StaticArrays.SVector{1}(x)
StaticArrays.MArray(x::SingletonVector) = StaticArrays.MVector{1}(x)
StaticArrays.MVector(x::SingletonVector) = StaticArrays.MVector{1}(x)
8 changes: 8 additions & 0 deletions test/preamble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ using BangBang
using BangBang: ismutable
using StaticArrays: SVector

"""
==ₜ(x, y)
Check that _type_ and value of `x` and `y` are equal.
"""
==(_, _) = false
==(x::T, y::T) where T = x == y

macro test_error(ex)
quote
let err = nothing
Expand Down
11 changes: 9 additions & 2 deletions test/test_staticarrays.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TestStaticArrays

using Test
include("preamble.jl")
using BangBang: ismutable
using StaticArrays
using StaticArrays: MArray, MMatrix, MVector, SArray, SMatrix, SVector

@testset begin
@test !ismutable(SVector(0))
Expand All @@ -11,4 +11,11 @@ using StaticArrays
@test ismutable(MMatrix{1, 1}(0))
end

@testset "Empty" begin
@test push!!(Empty(SVector), 1) === SVector(1)
@test push!!(Empty(SArray), 1) === SVector(1)
@test push!!(Empty(MVector), 1) ==MVector(1)
@test push!!(Empty(MArray), 1) ==MVector(1)
end

end # module

0 comments on commit 674c613

Please sign in to comment.