Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / go / strconv / strconv_test.go
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.
4
5 package strconv_test
6
7 /*
8
9 gccgo does not pass this.
10
11 import (
12         "runtime"
13         . "strconv"
14         "strings"
15         "testing"
16 )
17
18 var (
19         globalBuf [64]byte
20         nextToOne = "1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1"
21
22         mallocTest = []struct {
23                 count int
24                 desc  string
25                 fn    func()
26         }{
27                 // TODO(bradfitz): this might be 0, once escape analysis is better
28                 {1, `AppendInt(localBuf[:0], 123, 10)`, func() {
29                         var localBuf [64]byte
30                         AppendInt(localBuf[:0], 123, 10)
31                 }},
32                 {0, `AppendInt(globalBuf[:0], 123, 10)`, func() { AppendInt(globalBuf[:0], 123, 10) }},
33                 // TODO(bradfitz): this might be 0, once escape analysis is better
34                 {1, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() {
35                         var localBuf [64]byte
36                         AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)
37                 }},
38                 {0, `AppendFloat(globalBuf[:0], 1.23, 'g', 5, 64)`, func() { AppendFloat(globalBuf[:0], 1.23, 'g', 5, 64) }},
39                 {0, `ParseFloat("123.45", 64)`, func() { ParseFloat("123.45", 64) }},
40                 {0, `ParseFloat("123.456789123456789", 64)`, func() { ParseFloat("123.456789123456789", 64) }},
41                 {0, `ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)`, func() {
42                         ParseFloat("1.000000000000000111022302462515654042363166809082031251", 64)
43                 }},
44                 {0, `ParseFloat("1.0000000000000001110223024625156540423631668090820312500...001", 64)`, func() {
45                         ParseFloat(nextToOne, 64)
46                 }},
47         }
48 )
49
50 func TestCountMallocs(t *testing.T) {
51         defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
52         for _, mt := range mallocTest {
53                 const N = 100
54                 memstats := new(runtime.MemStats)
55                 runtime.ReadMemStats(memstats)
56                 mallocs := 0 - memstats.Mallocs
57                 for i := 0; i < N; i++ {
58                         mt.fn()
59                 }
60                 runtime.ReadMemStats(memstats)
61                 mallocs += memstats.Mallocs
62                 if mallocs/N > uint64(mt.count) {
63                         t.Errorf("%s: expected %d mallocs, got %d", mt.desc, mt.count, mallocs/N)
64                 }
65         }
66 }
67
68 */