@@ -22,13 +22,17 @@ import (
22
22
)
23
23
24
24
var (
25
- overflowInt , _ , _ = big .ParseFloat ("9223372036854775808" , 10 , 53 , big .ToPositiveInf )
26
- overflowUint , _ , _ = big .ParseFloat ("18446744073709551616" , 10 , 53 , big .ToPositiveInf )
27
- overflowFloat , _ , _ = big .ParseFloat ("1e10000" , 10 , 53 , big .ToPositiveInf )
28
- overflowNegativeFloat , _ , _ = big .ParseFloat ("-1e10000" , 10 , 53 , big .ToPositiveInf )
29
- underflowInt , _ , _ = big .ParseFloat ("-9223372036854775809" , 10 , 53 , big .ToNegativeInf )
30
- underflowFloat , _ , _ = big .ParseFloat ("1e-1000" , 10 , 0 , big .ToNegativeInf )
31
- underflowNegativeFloat , _ , _ = big .ParseFloat ("-1e-1000" , 10 , 0 , big .ToNegativeInf )
25
+ overflowInt , _ , _ = big .ParseFloat ("9223372036854775808" , 10 , 53 , big .ToPositiveInf )
26
+ overflowUint , _ , _ = big .ParseFloat ("18446744073709551616" , 10 , 53 , big .ToPositiveInf )
27
+ overflowFloat32 , _ , _ = big .ParseFloat ("3.40282346638528859811704183484516925440e+39" , 10 , 24 , big .ToPositiveInf )
28
+ overflowFloat64 , _ , _ = big .ParseFloat ("1e10000" , 10 , 53 , big .ToPositiveInf )
29
+ overflowNegativeFloat32 , _ , _ = big .ParseFloat ("-3.40282346638528859811704183484516925440e+39" , 10 , 53 , big .ToPositiveInf )
30
+ overflowNegativeFloat64 , _ , _ = big .ParseFloat ("-1e10000" , 10 , 53 , big .ToPositiveInf )
31
+ underflowInt , _ , _ = big .ParseFloat ("-9223372036854775809" , 10 , 53 , big .ToNegativeInf )
32
+ underflowFloat32 , _ , _ = big .ParseFloat ("1.401298464324817070923729583289916131280e-46" , 10 , 0 , big .ToNegativeInf )
33
+ underflowFloat64 , _ , _ = big .ParseFloat ("1e-1000" , 10 , 0 , big .ToNegativeInf )
34
+ underflowNegativeFloat32 , _ , _ = big .ParseFloat ("-1.401298464324817070923729583289916131280e-46" , 10 , 0 , big .ToNegativeInf )
35
+ underflowNegativeFloat64 , _ , _ = big .ParseFloat ("-1e-1000" , 10 , 0 , big .ToNegativeInf )
32
36
)
33
37
34
38
func TestNumber_bigFloat (t * testing.T ) {
@@ -590,13 +594,13 @@ func TestNumber_float32(t *testing.T) {
590
594
591
595
var n float32
592
596
593
- result , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , 123 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
597
+ result , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , 1.23 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
594
598
if diags .HasError () {
595
599
t .Errorf ("Unexpected error: %v" , diags )
596
600
}
597
601
reflect .ValueOf (& n ).Elem ().Set (result )
598
- if n != 123 {
599
- t .Errorf ("Expected %v, got %v" , 123 , n )
602
+ if n != 1.23 {
603
+ t .Errorf ("Expected %v, got %v" , 1.23 , n )
600
604
}
601
605
}
602
606
@@ -608,11 +612,30 @@ func TestNumber_float32OverflowError(t *testing.T) {
608
612
diag .NewAttributeErrorDiagnostic (
609
613
path .Empty (),
610
614
"Value Conversion Error" ,
611
- "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store 1.797693135e+308 in float32" ,
615
+ "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store 3.402823669e+39 in float32" ,
616
+ ),
617
+ }
618
+
619
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowFloat32 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
620
+
621
+ if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
622
+ t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
623
+ }
624
+ }
625
+
626
+ func TestNumber_float32OverflowNegativeError (t * testing.T ) {
627
+ t .Parallel ()
628
+
629
+ var n float32
630
+ expectedDiags := diag.Diagnostics {
631
+ diag .NewAttributeErrorDiagnostic (
632
+ path .Empty (),
633
+ "Value Conversion Error" ,
634
+ "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store -3.402823466e+39 in float32" ,
612
635
),
613
636
}
614
637
615
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , math . MaxFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
638
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowNegativeFloat32 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
616
639
617
640
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
618
641
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
@@ -627,11 +650,30 @@ func TestNumber_float32UnderflowError(t *testing.T) {
627
650
diag .NewAttributeErrorDiagnostic (
628
651
path .Empty (),
629
652
"Value Conversion Error" ,
630
- "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store 4.940656458e-324 in float32" ,
653
+ "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store 1.401298464e-46 in float32" ,
631
654
),
632
655
}
633
656
634
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , math .SmallestNonzeroFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
657
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowFloat32 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
658
+
659
+ if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
660
+ t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
661
+ }
662
+ }
663
+
664
+ func TestNumber_float32UnderflowNegativeError (t * testing.T ) {
665
+ t .Parallel ()
666
+
667
+ var n float32
668
+ expectedDiags := diag.Diagnostics {
669
+ diag .NewAttributeErrorDiagnostic (
670
+ path .Empty (),
671
+ "Value Conversion Error" ,
672
+ "An unexpected error was encountered trying to convert to number. This is always an error in the provider. Please report the following to the provider developer:\n \n cannot store -1.401298464e-46 in float32" ,
673
+ ),
674
+ }
675
+
676
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowNegativeFloat32 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
635
677
636
678
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
637
679
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
@@ -643,13 +685,13 @@ func TestNumber_float64(t *testing.T) {
643
685
644
686
var n float64
645
687
646
- result , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , 123 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
688
+ result , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , 1.23 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
647
689
if diags .HasError () {
648
690
t .Errorf ("Unexpected error: %v" , diags )
649
691
}
650
692
reflect .ValueOf (& n ).Elem ().Set (result )
651
- if n != 123 {
652
- t .Errorf ("Expected %v, got %v" , 123 , n )
693
+ if n != 1.23 {
694
+ t .Errorf ("Expected %v, got %v" , 1.23 , n )
653
695
}
654
696
}
655
697
@@ -665,7 +707,7 @@ func TestNumber_float64OverflowError(t *testing.T) {
665
707
),
666
708
}
667
709
668
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowFloat ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
710
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
669
711
670
712
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
671
713
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
@@ -684,7 +726,7 @@ func TestNumber_float64OverflowNegativeError(t *testing.T) {
684
726
),
685
727
}
686
728
687
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowNegativeFloat ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
729
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , overflowNegativeFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
688
730
689
731
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
690
732
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
@@ -703,7 +745,7 @@ func TestNumber_float64UnderflowError(t *testing.T) {
703
745
),
704
746
}
705
747
706
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowFloat ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
748
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
707
749
708
750
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
709
751
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
@@ -722,7 +764,7 @@ func TestNumber_float64UnderflowNegativeError(t *testing.T) {
722
764
),
723
765
}
724
766
725
- _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowNegativeFloat ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
767
+ _ , diags := refl .Number (context .Background (), types .NumberType , tftypes .NewValue (tftypes .Number , underflowNegativeFloat64 ), reflect .ValueOf (n ), refl.Options {}, path .Empty ())
726
768
727
769
if diff := cmp .Diff (diags , expectedDiags ); diff != "" {
728
770
t .Errorf ("unexpected diagnostics (+wanted, -got): %s" , diff )
0 commit comments