aboutsummaryrefslogtreecommitdiff
path: root/src/strconv/atoc_test.go
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2020-12-14 10:03:05 -0500
committerKatie Hockman <katie@golang.org>2020-12-14 10:06:13 -0500
commit0345ede87ee12698988973884cfc0fd3d499dffd (patch)
tree7123cff141ee5661208d2f5f437b8f5252ac7f6a /src/strconv/atoc_test.go
parent4651d6b267818b0e0d128a5443289717c4bb8cbc (diff)
parent0a02371b0576964e81c3b40d328db9a3ef3b031b (diff)
downloadgo-0345ede87ee12698988973884cfc0fd3d499dffd.tar.xz
[dev.fuzz] all: merge master into dev.fuzz
Change-Id: I5d8c8329ccc9d747bd81ade6b1cb7cb8ae2e94b2
Diffstat (limited to 'src/strconv/atoc_test.go')
-rw-r--r--src/strconv/atoc_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/strconv/atoc_test.go b/src/strconv/atoc_test.go
index 3aa421dd03..4c1aad0900 100644
--- a/src/strconv/atoc_test.go
+++ b/src/strconv/atoc_test.go
@@ -198,5 +198,32 @@ func TestParseComplex(t *testing.T) {
if !(cmplx.IsNaN(test.out) && cmplx.IsNaN(got)) && got != test.out {
t.Fatalf("ParseComplex(%q, 128) = %v, %v; want %v, %v", test.in, got, err, test.out, test.err)
}
+
+ if complex128(complex64(test.out)) == test.out {
+ got, err := ParseComplex(test.in, 64)
+ if !reflect.DeepEqual(err, test.err) {
+ t.Fatalf("ParseComplex(%q, 64) = %v, %v; want %v, %v", test.in, got, err, test.out, test.err)
+ }
+ got64 := complex64(got)
+ if complex128(got64) != test.out {
+ t.Fatalf("ParseComplex(%q, 64) = %v, %v; want %v, %v", test.in, got, err, test.out, test.err)
+ }
+ }
+ }
+}
+
+// Issue 42297: allow ParseComplex(s, not_32_or_64) for legacy reasons
+func TestParseComplexIncorrectBitSize(t *testing.T) {
+ const s = "1.5e308+1.0e307i"
+ const want = 1.5e308 + 1.0e307i
+
+ for _, bitSize := range []int{0, 10, 100, 256} {
+ c, err := ParseComplex(s, bitSize)
+ if err != nil {
+ t.Fatalf("ParseComplex(%q, %d) gave error %s", s, bitSize, err)
+ }
+ if c != want {
+ t.Fatalf("ParseComplex(%q, %d) = %g (expected %g)", s, bitSize, c, want)
+ }
}
}