@@ -341,15 +341,7 @@ Base.getproperty(obj::FieldProps, name::Symbol) = getproperty(getfield(obj, :com
341
341
@test occursin (" setproperties" , msg)
342
342
@test occursin (" FieldProps" , msg)
343
343
# == 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 )
353
345
end
354
346
355
347
@@ -361,24 +353,20 @@ Base.getproperty(s::SProp, prop::Symbol) = "ps$prop"
361
353
Base. getproperty (s:: SProp , prop:: Int ) = " pi$prop "
362
354
Base. getproperty (s:: SProp , prop:: String ) = " pstr$prop "
363
355
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" )))
366
361
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
375
364
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[])) === ()
382
370
end
383
371
384
372
function funny_numbers (:: Type{Tuple} , n):: Tuple
484
472
@testset " no allocs S2" begin
485
473
obj = S2 (3 , UInt32 (5 ))
486
474
@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 )))
492
476
end
493
477
494
478
@testset " inference" begin
524
508
@inferred getfields (nt)
525
509
526
510
@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)
531
513
# no_allocs_test(nt, content)
532
514
for k in 0 : n
533
515
nt2 = funny_numbers (NamedTuple, k)
@@ -549,12 +531,10 @@ end
549
531
@inferred constructorof (S1)
550
532
@inferred constructorof (S20)
551
533
@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 ))
558
538
559
539
@inferred getfields (funny_numbers (S,0 ))
560
540
@inferred getfields (funny_numbers (S,1 ))
@@ -569,45 +549,43 @@ end
569
549
570
550
using StaticArrays, IntervalSets
571
551
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 ))
605
576
end
606
577
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 )
613
591
end
0 commit comments