255255end
256256
257257f_infer () = StructArray {ComplexF64} ((rand (2 ,2 ), rand (2 ,2 )))
258-
259258g_infer () = StructArray ([(a= (b= " 1" ,), c= 2 )], unwrap = t -> t <: NamedTuple )
260259tup_infer () = StructArray ([(1 , 2 ), (3 , 4 )])
261260cols_infer () = StructArray (([1 , 2 ], [1.2 , 2.3 ]))
@@ -271,6 +270,11 @@ cols_infer() = StructArray(([1, 2], [1.2, 2.3]))
271270 @inferred cols_infer ()
272271end
273272
273+ @testset " to_(named)tuple" begin
274+ @test StructArrays. to_tup ((1 , 2 , 3 )) == (1 , 2 , 3 )
275+ @test StructArrays. to_tup (2 + 3im ) == (re = 2 , im = 3 )
276+ end
277+
274278@testset " propertynames" begin
275279 a = StructArray {ComplexF64} ((Float64[], Float64[]))
276280 @test sort (collect (propertynames (a))) == [:im , :re ]
490494 @test all (t -> t. re >= 0 , s)
491495 @test all (t -> t. re >= 0 , rows)
492496 rows[13 ]. re = - 12
497+ rows[13 ]. im = 0
493498 @test ! all (t -> t. re >= 0 , s)
494499 @test ! all (t -> t. re >= 0 , rows)
500+
501+ io = IOBuffer ()
502+ show (io, rows[13 ])
503+ str = String (take! (io))
504+ @test str == " LazyRow(re = -12.0, im = 0.0)"
505+
506+ io = IOBuffer ()
507+ Base. showarg (io, rows, true )
508+ str = String (take! (io))
509+ @test str == " LazyRows(::Array{Float64,2}, ::Array{Float64,2}) with eltype LazyRow{Complex{Float64}}"
510+ io = IOBuffer ()
511+ Base. showarg (io, rows, false )
512+ str = String (take! (io))
513+ @test str == " LazyRows(::Array{Float64,2}, ::Array{Float64,2})"
514+
515+ s = StructArray ((rand (10 , 10 ), rand (10 , 10 )))
516+ rows = LazyRows (s)
517+ @test IndexStyle (rows) isa IndexLinear
518+ @test all (t -> StructArrays. _getproperty (t, 1 ) >= 0 , s)
519+ @test all (t -> getproperty (t, 1 ) >= 0 , rows)
520+ setproperty! (rows[13 ], 1 , - 12 )
521+ setproperty! (rows[13 ], 2 , 0 )
522+ @test ! all (t -> StructArrays. _getproperty (t, 1 ) >= 0 , s)
523+ @test ! all (t -> getproperty (t, 1 ) >= 0 , rows)
524+
525+ io = IOBuffer ()
526+ show (io, rows[13 ])
527+ str = String (take! (io))
528+ @test str == " LazyRow(-12.0, 0.0)"
529+
530+ io = IOBuffer ()
531+ Base. showarg (io, rows, true )
532+ str = String (take! (io))
533+ @test str == " LazyRows(::Array{Float64,2}, ::Array{Float64,2}) with eltype LazyRow{Tuple{Float64,Float64}}"
534+ io = IOBuffer ()
535+ Base. showarg (io, rows, false )
536+ str = String (take! (io))
537+ @test str == " LazyRows(::Array{Float64,2}, ::Array{Float64,2})"
495538end
496539
497540@testset " refs" begin
0 commit comments