2015-07-08 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / libgo / go / strconv / strconv_test.go
blob207e00e75dc6996d4c7a56ca9deb0dedc867d383
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.
5 package strconv_test
7 /*
9 gccgo does not pass this.
11 import (
12 "runtime"
13 . "strconv"
14 "strings"
15 "testing"
18 var (
19 globalBuf [64]byte
20 nextToOne = "1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1"
22 mallocTest = []struct {
23 count int
24 desc string
25 fn func()
27 {0, `AppendInt(localBuf[:0], 123, 10)`, func() {
28 var localBuf [64]byte
29 AppendInt(localBuf[:0], 123, 10)
30 }},
31 {0, `AppendInt(globalBuf[:0], 123, 10)`, func() { AppendInt(globalBuf[:0], 123, 10) }},
32 {0, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() {
33 var localBuf [64]byte
34 AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)
35 }},
36 {0, `AppendFloat(globalBuf[:0], 1.23, 'g', 5, 64)`, func() { AppendFloat(globalBuf[:0], 1.23, 'g', 5, 64) }},
37 {0, `ParseFloat("123.45", 64)`, func() { ParseFloat("123.45", 64) }},
38 {0, `ParseFloat("123.456789123456789", 64)`, func() { ParseFloat("123.456789123456789", 64) }},
39 {0, `ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)`, func() {
40 ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)
41 }},
42 {0, `ParseFloat("1.0000000000000001110223024625156540423631668090820312500...001", 64)`, func() {
43 ParseFloat(nextToOne, 64)
44 }},
48 func TestCountMallocs(t *testing.T) {
49 if testing.Short() {
50 t.Skip("skipping malloc count in short mode")
52 if runtime.GOMAXPROCS(0) > 1 {
53 t.Skip("skipping; GOMAXPROCS>1")
55 for _, mt := range mallocTest {
56 allocs := testing.AllocsPerRun(100, mt.fn)
57 if max := float64(mt.count); allocs > max {
58 t.Errorf("%s: %v allocs, want <=%v", mt.desc, allocs, max)