strconv_test.go 1.8 KB

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