@@ -341,15 +341,7 @@ Base.getproperty(obj::FieldProps, name::Symbol) = getproperty(getfield(obj, :com
341341 @test occursin(" setproperties" , msg)
342342 @test occursin(" FieldProps" , msg)
343343 # == FieldProps((a="aaa", b=:b)
344- if VERSION >= v" 1.7"
345- @test getproperties(x) == (a= 1 , b= :b)
346- else
347- res = @test_throws ErrorException getproperties(x)
348- msg = sprint(showerror, res. value)
349- @test occursin(" overload" , msg)
350- @test occursin(" getproperties" , msg)
351- @test occursin(" FieldProps" , msg)
352- end
344+ @test getproperties(x) == (a= 1 , b= :b)
353345end
354346
355347
@@ -361,24 +353,20 @@ Base.getproperty(s::SProp, prop::Symbol) = "ps$prop"
361353Base. getproperty(s:: SProp , prop:: Int ) = " pi$prop "
362354Base. getproperty(s:: SProp , prop:: String ) = " pstr$prop "
363355
364- if VERSION >= v" 1.7"
365- # automatic getproperties() supported only on 1.7+
356+ @testset " properties can be numbered" begin
357+ @test getproperties(SProp((:a, :b))) === (a= " psa" , b= " psb" )
358+ @test getproperties(SProp((1 , 2 ))) === (" pi1" , " pi2" )
359+ # what should it return?
360+ @test_broken getproperties(SProp((" a" , " b" )))
366361
367- @testset " properties can be numbered" begin
368- @test getproperties(SProp((:a, :b))) === (a= " psa" , b= " psb" )
369- @test getproperties(SProp((1 , 2 ))) === (" pi1" , " pi2" )
370- # what should it return?
371- @test_broken getproperties(SProp((" a" , " b" )))
372-
373- @test_throws ErrorException getproperties(SProp((1 , :a)))
374- end
362+ @test_throws ErrorException getproperties(SProp((1 , :a)))
363+ end
375364
376- @testset " propertynames can be a vector" begin
377- @test getproperties(SProp([:a, :b])) === (a= " psa" , b= " psb" )
378- @test getproperties(SProp(Symbol[])) === (;)
379- @test getproperties(SProp([1 , 2 ])) === (" pi1" , " pi2" )
380- @test getproperties(SProp(Int[])) === ()
381- end
365+ @testset " propertynames can be a vector" begin
366+ @test getproperties(SProp([:a, :b])) === (a= " psa" , b= " psb" )
367+ @test getproperties(SProp(Symbol[])) === (;)
368+ @test getproperties(SProp([1 , 2 ])) === (" pi1" , " pi2" )
369+ @test getproperties(SProp(Int[])) === ()
382370end
383371
384372function funny_numbers(:: Type{Tuple} , n):: Tuple
484472@testset " no allocs S2" begin
485473 obj = S2(3 , UInt32(5 ))
486474 @test 0 == hot_loop_allocs(constructorof, typeof(obj))
487- if VERSION < v" 1.6"
488- @test 32 ≥ hot_loop_allocs(setproperties, obj, (; a = nothing , b = Int32(6 )))
489- else
490- @test 0 == hot_loop_allocs(setproperties, obj, (; a = nothing , b = Int32(6 )))
491- end
475+ @test 0 == hot_loop_allocs(setproperties, obj, (; a = nothing , b = Int32(6 )))
492476end
493477
494478@testset " inference" begin
524508 @inferred getfields(nt)
525509
526510 @inferred constructorof(typeof(nt))
527- if VERSION >= v" 1.3"
528- content = funny_numbers(NamedTuple,n)
529- @inferred reconstruct(nt, content)
530- end
511+ content = funny_numbers(NamedTuple,n)
512+ @inferred reconstruct(nt, content)
531513 # no_allocs_test(nt, content)
532514 for k in 0 : n
533515 nt2 = funny_numbers(NamedTuple, k)
@@ -549,12 +531,10 @@ end
549531 @inferred constructorof(S1)
550532 @inferred constructorof(S20)
551533 @inferred constructorof(S40)
552- if VERSION >= v" 1.3"
553- @inferred reconstruct(funny_numbers(S,0 ) , funny_numbers(Tuple,0 ))
554- @inferred reconstruct(funny_numbers(S,1 ) , funny_numbers(Tuple,1 ))
555- @inferred reconstruct(funny_numbers(S,20 ), funny_numbers(Tuple,20 ))
556- @inferred reconstruct(funny_numbers(S,40 ), funny_numbers(Tuple,40 ))
557- end
534+ @inferred reconstruct(funny_numbers(S,0 ) , funny_numbers(Tuple,0 ))
535+ @inferred reconstruct(funny_numbers(S,1 ) , funny_numbers(Tuple,1 ))
536+ @inferred reconstruct(funny_numbers(S,20 ), funny_numbers(Tuple,20 ))
537+ @inferred reconstruct(funny_numbers(S,40 ), funny_numbers(Tuple,40 ))
558538
559539 @inferred getfields(funny_numbers(S,0 ))
560540 @inferred getfields(funny_numbers(S,1 ))
@@ -569,45 +549,43 @@ end
569549
570550using StaticArrays, IntervalSets
571551
572- if isdefined(Base, :get_extension) # some 1.9 version
573- @testset " staticarrays" begin
574- sa = @SVector [2 , 4 , 6 , 8 ]
575- sa2 = ConstructionBase. constructorof(typeof(sa))((3.0 , 5.0 , 7.0 , 9.0 ))
576- @test sa2 === @SVector [3.0 , 5.0 , 7.0 , 9.0 ]
577-
578- ma = @MMatrix [2.0 4.0 ; 6.0 8.0 ]
579- ma2 = @inferred ConstructionBase. constructorof(typeof(ma))((1 , 2 , 3 , 4 ))
580- @test ma2 isa MArray{Tuple{2 ,2 },Int,2 ,4 }
581- @test all(ma2 .=== @MMatrix [1 3 ; 2 4 ])
582-
583- sz = SizedArray{Tuple{2 ,2 }}([1 2 ;3 4 ])
584- sz2 = @inferred ConstructionBase. constructorof(typeof(sz))([:a :b; :c :d])
585- @test sz2 == SizedArray{Tuple{2 ,2 }}([:a :b; :c :d])
586- @test typeof(sz2) <: SizedArray{Tuple{2,2},Symbol,2,2}
587-
588- for T in (SVector, MVector)
589- @test @inferred(ConstructionBase. constructorof(T)((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
590- @test @inferred(ConstructionBase. constructorof(T{3 })((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
591- @test @inferred(ConstructionBase. constructorof(T{3 })((1 , 2 ))):: T == T((1 , 2 ))
592- @test @inferred(ConstructionBase. constructorof(T{3 , Symbol})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
593- @test @inferred(ConstructionBase. constructorof(T{3 , Symbol})((1 , 2 ))):: T == T((1 , 2 ))
594- @test @inferred(ConstructionBase. constructorof(T{3 , X} where {X})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
595- @test @inferred(ConstructionBase. constructorof(T{3 , X} where {X})((1 , 2 ))):: T == T((1 , 2 ))
596- @test @inferred(ConstructionBase. constructorof(T{X, Symbol} where {X})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
597- end
598-
599- sv = SVector(1 , 2 )
600- @test SVector(3.0 , 2.0 ) === @inferred setproperties(sv, x = 3.0 )
601- @test SVector(3.0 , 5.0 ) === @inferred setproperties(sv, x = 3.0 , y = 5.0 )
602- @test SVector(- 1.0 , - 2.0 ) === @inferred setproperties(sv, data = (- 1.0 , - 2 ))
603- @test_throws " does not have properties z" setproperties(sv, z = 3.0 )
604- @test_throws " does not have properties z" setproperties(SVector(1 , 2 , 3 , 4 , 5 ), z = 3.0 )
552+ @testset " staticarrays" begin
553+ sa = @SVector [2 , 4 , 6 , 8 ]
554+ sa2 = ConstructionBase. constructorof(typeof(sa))((3.0 , 5.0 , 7.0 , 9.0 ))
555+ @test sa2 === @SVector [3.0 , 5.0 , 7.0 , 9.0 ]
556+
557+ ma = @MMatrix [2.0 4.0 ; 6.0 8.0 ]
558+ ma2 = @inferred ConstructionBase. constructorof(typeof(ma))((1 , 2 , 3 , 4 ))
559+ @test ma2 isa MArray{Tuple{2 ,2 },Int,2 ,4 }
560+ @test all(ma2 .=== @MMatrix [1 3 ; 2 4 ])
561+
562+ sz = SizedArray{Tuple{2 ,2 }}([1 2 ;3 4 ])
563+ sz2 = @inferred ConstructionBase. constructorof(typeof(sz))([:a :b; :c :d])
564+ @test sz2 == SizedArray{Tuple{2 ,2 }}([:a :b; :c :d])
565+ @test typeof(sz2) <: SizedArray{Tuple{2,2},Symbol,2,2}
566+
567+ for T in (SVector, MVector)
568+ @test @inferred(ConstructionBase. constructorof(T)((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
569+ @test @inferred(ConstructionBase. constructorof(T{3 })((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
570+ @test @inferred(ConstructionBase. constructorof(T{3 })((1 , 2 ))):: T == T((1 , 2 ))
571+ @test @inferred(ConstructionBase. constructorof(T{3 , Symbol})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
572+ @test @inferred(ConstructionBase. constructorof(T{3 , Symbol})((1 , 2 ))):: T == T((1 , 2 ))
573+ @test @inferred(ConstructionBase. constructorof(T{3 , X} where {X})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
574+ @test @inferred(ConstructionBase. constructorof(T{3 , X} where {X})((1 , 2 ))):: T == T((1 , 2 ))
575+ @test @inferred(ConstructionBase. constructorof(T{X, Symbol} where {X})((1 , 2 , 3 ))):: T == T((1 , 2 , 3 ))
605576 end
606577
607- @testset " intervalsets" begin
608- @test constructorof(typeof(1 .. 2 ))(0.5 , 1.5 ) === 0.5 .. 1.5
609- @test constructorof(typeof(OpenInterval(1 , 2 )))(0.5 , 1.5 ) === OpenInterval(0.5 , 1.5 )
610- @test setproperties(1 .. 2 , left= 0.0 ) === 0.0 .. 2.0
611- @test setproperties(OpenInterval(1.0 , 2.0 ), left= 1 , right= 5 ) === OpenInterval(1 , 5 )
612- end
578+ sv = SVector(1 , 2 )
579+ @test SVector(3.0 , 2.0 ) === @inferred setproperties(sv, x = 3.0 )
580+ @test SVector(3.0 , 5.0 ) === @inferred setproperties(sv, x = 3.0 , y = 5.0 )
581+ @test SVector(- 1.0 , - 2.0 ) === @inferred setproperties(sv, data = (- 1.0 , - 2 ))
582+ @test_throws " does not have properties z" setproperties(sv, z = 3.0 )
583+ @test_throws " does not have properties z" setproperties(SVector(1 , 2 , 3 , 4 , 5 ), z = 3.0 )
584+ end
585+
586+ @testset " intervalsets" begin
587+ @test constructorof(typeof(1 .. 2 ))(0.5 , 1.5 ) === 0.5 .. 1.5
588+ @test constructorof(typeof(OpenInterval(1 , 2 )))(0.5 , 1.5 ) === OpenInterval(0.5 , 1.5 )
589+ @test setproperties(1 .. 2 , left= 0.0 ) === 0.0 .. 2.0
590+ @test setproperties(OpenInterval(1.0 , 2.0 ), left= 1 , right= 5 ) === OpenInterval(1 , 5 )
613591end
0 commit comments