1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 nextToOne
= "1.00000000000000011102230246251565404236316680908203125" + strings
.Repeat("0", 10000) + "1"
18 mallocTest
= []struct {
23 {0, `AppendInt(localBuf[:0], 123, 10)`, func() {
25 AppendInt(localBuf
[:0], 123, 10)
27 {0, `AppendInt(globalBuf[:0], 123, 10)`, func() { AppendInt(globalBuf
[:0], 123, 10) }},
28 {0, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() {
30 AppendFloat(localBuf
[:0], 1.23, 'g', 5, 64)
32 {0, `AppendFloat(globalBuf[:0], 1.23, 'g', 5, 64)`, func() { AppendFloat(globalBuf
[:0], 1.23, 'g', 5, 64) }},
33 {0, `ParseFloat("123.45", 64)`, func() { ParseFloat("123.45", 64) }},
34 {0, `ParseFloat("123.456789123456789", 64)`, func() { ParseFloat("123.456789123456789", 64) }},
35 {0, `ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)`, func() {
36 ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)
38 {0, `ParseFloat("1.0000000000000001110223024625156540423631668090820312500...001", 64)`, func() {
39 ParseFloat(nextToOne
, 64)
44 func TestCountMallocs(t
*testing
.T
) {
45 if runtime
.Compiler
== "gccgo" {
46 t
.Skip("skipping on gccgo until escape analysis is turned on")
49 t
.Skip("skipping malloc count in short mode")
51 if runtime
.GOMAXPROCS(0) > 1 {
52 t
.Skip("skipping; GOMAXPROCS>1")
54 for _
, mt
:= range mallocTest
{
55 allocs
:= testing
.AllocsPerRun(100, mt
.fn
)
56 if max
:= float64(mt
.count
); allocs
> max
{
57 t
.Errorf("%s: %v allocs, want <=%v", mt
.desc
, allocs
, max
)
62 func TestErrorPrefixes(t
*testing
.T
) {
63 _
, errInt
:= Atoi("INVALID")
64 _
, errBool
:= ParseBool("INVALID")
65 _
, errFloat
:= ParseFloat("INVALID", 64)
66 _
, errInt64
:= ParseInt("INVALID", 10, 64)
67 _
, errUint64
:= ParseUint("INVALID", 10, 64)
70 err error
// Input error
71 want
string // Function name wanted
74 {errBool
, "ParseBool"},
75 {errFloat
, "ParseFloat"},
76 {errInt64
, "ParseInt"},
77 {errUint64
, "ParseUint"},
80 for _
, v
:= range vectors
{
81 nerr
, ok
:= v
.err
.(*NumError
)
83 t
.Errorf("test %s, error was not a *NumError", v
.want
)
86 if got
:= nerr
.Func
; got
!= v
.want
{
87 t
.Errorf("mismatching Func: got %s, want %s", got
, v
.want
)