diff options
author | Ian Lance Taylor <iant@google.com> | 2016-02-03 21:58:02 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-02-03 21:58:02 +0000 |
commit | f98dd1a338867a408f7c72d73fbad7fe7fc93e3a (patch) | |
tree | 2f8da9862a9c1fe0df138917f997b03439c02773 /libgo/go/fmt | |
parent | b081ed4efc144da0c45a6484aebfd10e0eb9fda3 (diff) | |
download | gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.zip gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.gz gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.bz2 |
libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200
From-SVN: r233110
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/doc.go | 8 | ||||
-rw-r--r-- | libgo/go/fmt/fmt_test.go | 16 | ||||
-rw-r--r-- | libgo/go/fmt/norace_test.go | 9 | ||||
-rw-r--r-- | libgo/go/fmt/print.go | 23 | ||||
-rw-r--r-- | libgo/go/fmt/race_test.go | 9 | ||||
-rw-r--r-- | libgo/go/fmt/scan.go | 12 | ||||
-rw-r--r-- | libgo/go/fmt/scan_test.go | 5 |
7 files changed, 50 insertions, 32 deletions
diff --git a/libgo/go/fmt/doc.go b/libgo/go/fmt/doc.go index ef91368..4eea48e 100644 --- a/libgo/go/fmt/doc.go +++ b/libgo/go/fmt/doc.go @@ -34,8 +34,8 @@ %b decimalless scientific notation with exponent a power of two, in the manner of strconv.FormatFloat with the 'b' format, e.g. -123456p-78 - %e scientific notation, e.g. -1234.456e+78 - %E scientific notation, e.g. -1234.456E+78 + %e scientific notation, e.g. -1.234456e+78 + %E scientific notation, e.g. -1.234456E+78 %f decimal point but no exponent, e.g. 123.456 %F synonym for %f %g %e for large exponents, %f otherwise @@ -138,8 +138,8 @@ formatting considerations apply for operands that implement certain interfaces. In order of application: - 1. If the operand is a reflect.Value, the concrete value it - holds is printed as if it was the operand. + 1. If the operand is a reflect.Value, the operand is replaced by the + concrete value that it holds, and printing continues with the next rule. 2. If an operand implements the Formatter interface, it will be invoked. Formatter provides fine control of formatting. diff --git a/libgo/go/fmt/fmt_test.go b/libgo/go/fmt/fmt_test.go index 8f3587b..ea6392f 100644 --- a/libgo/go/fmt/fmt_test.go +++ b/libgo/go/fmt/fmt_test.go @@ -7,6 +7,7 @@ package fmt_test import ( "bytes" . "fmt" + "internal/race" "io" "math" "reflect" @@ -984,7 +985,7 @@ func TestCountMallocs(t *testing.T) { t.Skip("skipping malloc count in short mode") case runtime.GOMAXPROCS(0) > 1: t.Skip("skipping; GOMAXPROCS>1") - case raceenabled: + case race.Enabled: t.Skip("skipping malloc count under race detector") } for _, mt := range mallocTest { @@ -1190,6 +1191,11 @@ var startests = []struct { {"%.*d", args(4, 42), "0042"}, {"%*.*d", args(8, 4, 42), " 0042"}, {"%0*d", args(4, 42), "0042"}, + // Some non-int types for width. (Issue 10732). + {"%0*d", args(uint(4), 42), "0042"}, + {"%0*d", args(uint64(4), 42), "0042"}, + {"%0*d", args('\x04', 42), "0042"}, + {"%0*d", args(uintptr(4), 42), "0042"}, // erroneous {"%*d", args(nil, 42), "%!(BADWIDTH)42"}, @@ -1198,17 +1204,19 @@ var startests = []struct { {"%.*d", args(nil, 42), "%!(BADPREC)42"}, {"%.*d", args(-1, 42), "%!(BADPREC)42"}, {"%.*d", args(int(1e7), 42), "%!(BADPREC)42"}, + {"%.*d", args(uint(1e7), 42), "%!(BADPREC)42"}, + {"%.*d", args(uint64(1<<63), 42), "%!(BADPREC)42"}, // Huge negative (-inf). + {"%.*d", args(uint64(1<<64-1), 42), "%!(BADPREC)42"}, // Small negative (-1). {"%*d", args(5, "foo"), "%!d(string= foo)"}, {"%*% %d", args(20, 5), "% 5"}, {"%*", args(4), "%!(NOVERB)"}, - {"%*d", args(int32(4), 42), "%!(BADWIDTH)42"}, } func TestWidthAndPrecision(t *testing.T) { - for _, tt := range startests { + for i, tt := range startests { s := Sprintf(tt.fmt, tt.in...) if s != tt.out { - t.Errorf("%q: got %q expected %q", tt.fmt, s, tt.out) + t.Errorf("#%d: %q: got %q expected %q", i, tt.fmt, s, tt.out) } } } diff --git a/libgo/go/fmt/norace_test.go b/libgo/go/fmt/norace_test.go deleted file mode 100644 index 1267cc3..0000000 --- a/libgo/go/fmt/norace_test.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !race - -package fmt_test - -const raceenabled = false diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go index 8d3e97c..ebfa13e 100644 --- a/libgo/go/fmt/print.go +++ b/libgo/go/fmt/print.go @@ -1024,11 +1024,30 @@ BigSwitch: return wasString } -// intFromArg gets the argNumth element of a. On return, isInt reports whether the argument has type int. +// intFromArg gets the argNumth element of a. On return, isInt reports whether the argument has integer type. func intFromArg(a []interface{}, argNum int) (num int, isInt bool, newArgNum int) { newArgNum = argNum if argNum < len(a) { - num, isInt = a[argNum].(int) + num, isInt = a[argNum].(int) // Almost always OK. + if !isInt { + // Work harder. + switch v := reflect.ValueOf(a[argNum]); v.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + n := v.Int() + if int64(int(n)) == n { + num = int(n) + isInt = true + } + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + n := v.Uint() + if int64(n) >= 0 && uint64(int(n)) == n { + num = int(n) + isInt = true + } + default: + // Already 0, false. + } + } newArgNum = argNum + 1 if tooLarge(num) { num = 0 diff --git a/libgo/go/fmt/race_test.go b/libgo/go/fmt/race_test.go deleted file mode 100644 index ae3147a..0000000 --- a/libgo/go/fmt/race_test.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build race - -package fmt_test - -const raceenabled = true diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index e3e0fd0..4618ed4 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -538,7 +538,7 @@ func (s *ss) okVerb(verb rune, okVerbs, typ string) bool { return true } } - s.errorString("bad verb %" + string(verb) + " for " + typ) + s.errorString("bad verb '%" + string(verb) + "' for " + typ) return false } @@ -813,7 +813,7 @@ func (s *ss) scanComplex(verb rune, n int) complex128 { // convertString returns the string represented by the next input characters. // The format of the input is determined by the verb. func (s *ss) convertString(verb rune) (str string) { - if !s.okVerb(verb, "svqx", "string") { + if !s.okVerb(verb, "svqxX", "string") { return "" } s.skipSpace(false) @@ -821,7 +821,7 @@ func (s *ss) convertString(verb rune) (str string) { switch verb { case 'q': str = s.quotedString() - case 'x': + case 'x', 'X': str = s.hexString() default: str = string(s.token(true, notSpace)) // %s and %v just return the next word @@ -1078,6 +1078,10 @@ func (s *ss) advance(format string) (i int) { for i < len(format) { fmtc, w := utf8.DecodeRuneInString(format[i:]) if fmtc == '%' { + // % at end of string is an error. + if i+w == len(format) { + s.errorString("missing verb: % at end of format string") + } // %% acts like a real percent nextc, _ := utf8.DecodeRuneInString(format[i+w:]) // will not match % if string is empty if nextc != '%' { @@ -1179,7 +1183,7 @@ func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err erro } if numProcessed >= len(a) { // out of operands - s.errorString("too few operands for format %" + format[i-w:]) + s.errorString("too few operands for format '%" + format[i-w:] + "'") break } arg := a[numProcessed] diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index 334c4a6..7ac74dcb 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -255,12 +255,14 @@ var scanfTests = []ScanfTest{ // Strings {"%s", "using-%s\n", &stringVal, "using-%s"}, {"%x", "7573696e672d2578\n", &stringVal, "using-%x"}, + {"%X", "7573696E672D2558\n", &stringVal, "using-%X"}, {"%q", `"quoted\twith\\do\u0075bl\x65s"` + "\n", &stringVal, "quoted\twith\\doubles"}, {"%q", "`quoted with backs`\n", &stringVal, "quoted with backs"}, // Byte slices {"%s", "bytes-%s\n", &bytesVal, []byte("bytes-%s")}, {"%x", "62797465732d2578\n", &bytesVal, []byte("bytes-%x")}, + {"%X", "62797465732D2558\n", &bytesVal, []byte("bytes-%X")}, {"%q", `"bytes\rwith\vdo\u0075bl\x65s"` + "\n", &bytesVal, []byte("bytes\rwith\vdoubles")}, {"%q", "`bytes with backs`\n", &bytesVal, []byte("bytes with backs")}, @@ -291,6 +293,7 @@ var scanfTests = []ScanfTest{ // Interesting formats {"here is\tthe value:%d", "here is the\tvalue:118\n", &intVal, 118}, {"%% %%:%d", "% %:119\n", &intVal, 119}, + {"%d%%", "42%", &intVal, 42}, // %% at end of string. // Corner cases {"%x", "FFFFFFFF\n", &uint32Val, uint32(0xFFFFFFFF)}, @@ -356,6 +359,8 @@ var multiTests = []ScanfMultiTest{ {"%d %d", "23 18 27", args(&i, &j, &k), args(23, 18), "too many operands"}, {"%c", "\u0100", args(&int8Val), nil, "overflow"}, {"X%d", "10X", args(&intVal), nil, "input does not match format"}, + {"%d%", "42%", args(&intVal), args(42), "missing verb: % at end of format string"}, + {"%d% ", "42%", args(&intVal), args(42), "too few operands for format '% '"}, // Slightly odd error, but correct. // Bad UTF-8: should see every byte. {"%c%c%c", "\xc2X\xc2", args(&r1, &r2, &r3), args(utf8.RuneError, 'X', utf8.RuneError), ""}, |