diff --git a/src/MArray.jl b/src/MArray.jl index 9c928804..d473ab79 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -280,3 +280,9 @@ function Base.view( end Base.elsize(::Type{<:MArray{S,T}}) where {S,T} = sizeof(T) + +function Base.show(io::IO, S::MArray) + print(io, typeof(S), "(") + show(io, Tuple(S)) + print(io, ")") +end diff --git a/src/SArray.jl b/src/SArray.jl index 5e175079..7d82180e 100644 --- a/src/SArray.jl +++ b/src/SArray.jl @@ -283,3 +283,9 @@ end function promote_rule(::Type{<:SArray{S,T,N,L}}, ::Type{<:SArray{S,U,N,L}}) where {S,T,U,N,L} SArray{S,promote_type(T,U),N,L} end + +function Base.show(io::IO, S::SArray) + print(io, typeof(S), "(") + show(io, Tuple(S)) + print(io, ")") +end diff --git a/test/MArray.jl b/test/MArray.jl index 3a5cf42d..fb995fe6 100644 --- a/test/MArray.jl +++ b/test/MArray.jl @@ -188,4 +188,18 @@ v[] = 2 @test v[] == 2 end + + @testset "show" begin + io = IOBuffer() + + S = MVector{2,Float64}(1,2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "MVector{2, Float64}((1.0, 2.0))" + + S = MMatrix{1, 2, Int, 2}(1, 2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "MMatrix{1, 2, $Int, 2}((1, 2))" + end end diff --git a/test/SArray.jl b/test/SArray.jl index f2d19fc9..5c315497 100644 --- a/test/SArray.jl +++ b/test/SArray.jl @@ -146,4 +146,17 @@ @test @inferred(promote_type(SVector{2,Int}, SVector{2,Float64})) === SVector{2,Float64} @test @inferred(promote_type(SMatrix{2,3,Float32,6}, SMatrix{2,3,Complex{Float64},6})) === SMatrix{2,3,Complex{Float64},6} end + + @testset "show" begin + io = IOBuffer() + S = SVector{2, Float64}(1, 2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "SVector{2, Float64}((1.0, 2.0))" + + S = SMatrix{1, 2, Int, 2}(1, 2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "SMatrix{1, 2, $Int, 2}((1, 2))" + end end