diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
commit | be47d6eceffd2c5dbbc1566d5eea490527fb2bd4 (patch) | |
tree | 0e8fda573576bb4181dba29d0e88380a8c38fafd /libgo/go/strconv | |
parent | efb30cdeb003fd7c585ee0d7657340086abcbd9e (diff) | |
download | gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.zip gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.gz gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.bz2 |
libgo: Update to Go 1.1.1.
From-SVN: r200974
Diffstat (limited to 'libgo/go/strconv')
-rw-r--r-- | libgo/go/strconv/atof_test.go | 1 | ||||
-rw-r--r-- | libgo/go/strconv/atoi.go | 2 | ||||
-rw-r--r-- | libgo/go/strconv/atoi_test.go | 24 | ||||
-rw-r--r-- | libgo/go/strconv/extfloat.go | 1 | ||||
-rw-r--r-- | libgo/go/strconv/fp_test.go | 19 | ||||
-rw-r--r-- | libgo/go/strconv/quote.go | 5 | ||||
-rw-r--r-- | libgo/go/strconv/strconv_test.go | 24 |
7 files changed, 43 insertions, 33 deletions
diff --git a/libgo/go/strconv/atof_test.go b/libgo/go/strconv/atof_test.go index b4f3a6f..ba493321 100644 --- a/libgo/go/strconv/atof_test.go +++ b/libgo/go/strconv/atof_test.go @@ -110,6 +110,7 @@ var atoftests = []atofTest{ {"1e", "0", ErrSyntax}, {"1e-", "0", ErrSyntax}, {".e-1", "0", ErrSyntax}, + {"1\x00.2", "0", ErrSyntax}, // http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/ {"2.2250738585072012e-308", "2.2250738585072014e-308", nil}, diff --git a/libgo/go/strconv/atoi.go b/libgo/go/strconv/atoi.go index bdd5d71..21c6900 100644 --- a/libgo/go/strconv/atoi.go +++ b/libgo/go/strconv/atoi.go @@ -20,7 +20,7 @@ type NumError struct { } func (e *NumError) Error() string { - return "strconv." + e.Func + ": " + `parsing "` + e.Num + `": ` + e.Err.Error() + return "strconv." + e.Func + ": " + "parsing " + Quote(e.Num) + ": " + e.Err.Error() } func syntaxError(fn, str string) *NumError { diff --git a/libgo/go/strconv/atoi_test.go b/libgo/go/strconv/atoi_test.go index d0e7b61..9407573 100644 --- a/libgo/go/strconv/atoi_test.go +++ b/libgo/go/strconv/atoi_test.go @@ -5,6 +5,7 @@ package strconv_test import ( + "errors" "reflect" . "strconv" "testing" @@ -146,6 +147,16 @@ var atoi32tests = []atoi32Test{ {"-2147483649", -1 << 31, ErrRange}, } +type numErrorTest struct { + num, want string +} + +var numErrorTests = []numErrorTest{ + {"0", `strconv.ParseFloat: parsing "0": failed`}, + {"`", "strconv.ParseFloat: parsing \"`\": failed"}, + {"1\x00.2", `strconv.ParseFloat: parsing "1\x00.2": failed`}, +} + func init() { // The atoi routines return NumErrors wrapping // the error and the string. Convert the tables above. @@ -277,6 +288,19 @@ func TestParseInt(t *testing.T) { } } +func TestNumError(t *testing.T) { + for _, test := range numErrorTests { + err := &NumError{ + Func: "ParseFloat", + Num: test.num, + Err: errors.New("failed"), + } + if got := err.Error(); got != test.want { + t.Errorf(`(&NumError{"ParseFloat", %q, "failed"}).Error() = %v, want %v`, test.num, got, test.want) + } + } +} + func BenchmarkAtoi(b *testing.B) { for i := 0; i < b.N; i++ { ParseInt("12345678", 10, 0) diff --git a/libgo/go/strconv/extfloat.go b/libgo/go/strconv/extfloat.go index b7eaaa6..bed8b16 100644 --- a/libgo/go/strconv/extfloat.go +++ b/libgo/go/strconv/extfloat.go @@ -636,7 +636,6 @@ func (f *extFloat) ShortestDecimal(d *decimalSlice, lower, upper *extFloat) bool 1<<shift, multiplier*2) } } - return false } // adjustLastDigit modifies d = x-currentDiff*ε, to get closest to diff --git a/libgo/go/strconv/fp_test.go b/libgo/go/strconv/fp_test.go index 294b7a9..6de2f8b 100644 --- a/libgo/go/strconv/fp_test.go +++ b/libgo/go/strconv/fp_test.go @@ -7,7 +7,6 @@ package strconv_test import ( "bufio" "fmt" - "io" "os" "strconv" "strings" @@ -102,19 +101,10 @@ func TestFp(t *testing.T) { } defer f.Close() - b := bufio.NewReader(f) + s := bufio.NewScanner(f) - lineno := 0 - for { - line, err2 := b.ReadString('\n') - if err2 == io.EOF { - break - } - if err2 != nil { - t.Fatal("testfp: read testdata/testfp.txt: " + err2.Error()) - } - line = line[0 : len(line)-1] - lineno++ + for lineno := 1; s.Scan(); lineno++ { + line := s.Text() if len(line) == 0 || line[0] == '#' { continue } @@ -148,4 +138,7 @@ func TestFp(t *testing.T) { "want ", a[3], " got ", s) } } + if s.Err() != nil { + t.Fatal("testfp: read testdata/testfp.txt: ", s.Err()) + } } diff --git a/libgo/go/strconv/quote.go b/libgo/go/strconv/quote.go index 8a73f9d..8cbef88 100644 --- a/libgo/go/strconv/quote.go +++ b/libgo/go/strconv/quote.go @@ -139,8 +139,9 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte { return append(dst, QuoteRuneToASCII(r)...) } -// CanBackquote returns whether the string s would be -// a valid Go string literal if enclosed in backquotes. +// CanBackquote reports whether the string s can be represented +// unchanged as a single-line backquoted string without control +// characters other than space and tab. func CanBackquote(s string) bool { for i := 0; i < len(s); i++ { if (s[i] < ' ' && s[i] != '\t') || s[i] == '`' { diff --git a/libgo/go/strconv/strconv_test.go b/libgo/go/strconv/strconv_test.go index b01aff1..381874b 100644 --- a/libgo/go/strconv/strconv_test.go +++ b/libgo/go/strconv/strconv_test.go @@ -24,14 +24,12 @@ var ( desc string fn func() }{ - // TODO(bradfitz): this might be 0, once escape analysis is better - {1, `AppendInt(localBuf[:0], 123, 10)`, func() { + {0, `AppendInt(localBuf[:0], 123, 10)`, func() { var localBuf [64]byte AppendInt(localBuf[:0], 123, 10) }}, {0, `AppendInt(globalBuf[:0], 123, 10)`, func() { AppendInt(globalBuf[:0], 123, 10) }}, - // TODO(bradfitz): this might be 0, once escape analysis is better - {1, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() { + {0, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() { var localBuf [64]byte AppendFloat(localBuf[:0], 1.23, 'g', 5, 64) }}, @@ -48,19 +46,13 @@ var ( ) func TestCountMallocs(t *testing.T) { - defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1)) + if runtime.GOMAXPROCS(0) > 1 { + t.Skip("skipping; GOMAXPROCS>1") + } for _, mt := range mallocTest { - const N = 100 - memstats := new(runtime.MemStats) - runtime.ReadMemStats(memstats) - mallocs := 0 - memstats.Mallocs - for i := 0; i < N; i++ { - mt.fn() - } - runtime.ReadMemStats(memstats) - mallocs += memstats.Mallocs - if mallocs/N > uint64(mt.count) { - t.Errorf("%s: expected %d mallocs, got %d", mt.desc, mt.count, mallocs/N) + allocs := testing.AllocsPerRun(100, mt.fn) + if max := float64(mt.count); allocs > max { + t.Errorf("%s: %v allocs, want <=%v", mt.desc, allocs, max) } } } |