diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-01-02 15:05:27 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-01-21 23:53:22 -0800 |
commit | 5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch) | |
tree | 962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/fmt | |
parent | 6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff) | |
download | gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.zip gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.bz2 |
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/errors_test.go | 10 | ||||
-rw-r--r-- | libgo/go/fmt/scan.go | 13 | ||||
-rw-r--r-- | libgo/go/fmt/scan_test.go | 19 |
3 files changed, 32 insertions, 10 deletions
diff --git a/libgo/go/fmt/errors_test.go b/libgo/go/fmt/errors_test.go index 0c774bc..481a7b8 100644 --- a/libgo/go/fmt/errors_test.go +++ b/libgo/go/fmt/errors_test.go @@ -11,6 +11,10 @@ import ( ) func TestErrorf(t *testing.T) { + // noVetErrorf is an alias for fmt.Errorf that does not trigger vet warnings for + // %w format strings. + noVetErrorf := fmt.Errorf + wrapped := errors.New("inner error") for _, test := range []struct { err error @@ -46,13 +50,13 @@ func TestErrorf(t *testing.T) { err: fmt.Errorf("%v with added context", wrapped), wantText: "inner error with added context", }, { - err: fmt.Errorf("%w is not an error", "not-an-error"), + err: noVetErrorf("%w is not an error", "not-an-error"), wantText: "%!w(string=not-an-error) is not an error", }, { - err: fmt.Errorf("wrapped two errors: %w %w", errString("1"), errString("2")), + err: noVetErrorf("wrapped two errors: %w %w", errString("1"), errString("2")), wantText: "wrapped two errors: 1 %!w(fmt_test.errString=2)", }, { - err: fmt.Errorf("wrapped three errors: %w %w %w", errString("1"), errString("2"), errString("3")), + err: noVetErrorf("wrapped three errors: %w %w %w", errString("1"), errString("2"), errString("3")), wantText: "wrapped three errors: 1 %!w(fmt_test.errString=2) %!w(fmt_test.errString=3)", }, { err: fmt.Errorf("%w", nil), diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 0dab2c9..8cab018 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -940,6 +940,15 @@ const ( uintptrBits = 32 << (^uintptr(0) >> 63) ) +// scanPercent scans a literal percent character. +func (s *ss) scanPercent() { + s.SkipSpace() + s.notEOF() + if !s.accept("%") { + s.errorString("missing literal %") + } +} + // scanOne scans a single value, deriving the scanner from the type of the argument. func (s *ss) scanOne(verb rune, arg interface{}) { s.buf = s.buf[:0] @@ -1203,6 +1212,10 @@ func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err erro if c != 'c' { s.SkipSpace() } + if c == '%' { + s.scanPercent() + continue // Do not consume an argument. + } s.argLimit = s.limit if f := s.count + s.maxWid; f < s.argLimit { s.argLimit = f diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index b14a6f5..1cc469c 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -318,13 +318,15 @@ var scanfTests = []ScanfTest{ {"%2s", "sssss", &xVal, Xs("ss")}, // Fixed bugs - {"%d\n", "27\n", &intVal, 27}, // ok - {"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline" - {"%v", "0", &intVal, 0}, // was: "EOF"; 0 was taken as base prefix and not counted. - {"%v", "0", &uintVal, uint(0)}, // was: "EOF"; 0 was taken as base prefix and not counted. - {"%c", " ", &uintVal, uint(' ')}, // %c must accept a blank. - {"%c", "\t", &uintVal, uint('\t')}, // %c must accept any space. - {"%c", "\n", &uintVal, uint('\n')}, // %c must accept any space. + {"%d\n", "27\n", &intVal, 27}, // ok + {"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline" + {"%v", "0", &intVal, 0}, // was: "EOF"; 0 was taken as base prefix and not counted. + {"%v", "0", &uintVal, uint(0)}, // was: "EOF"; 0 was taken as base prefix and not counted. + {"%c", " ", &uintVal, uint(' ')}, // %c must accept a blank. + {"%c", "\t", &uintVal, uint('\t')}, // %c must accept any space. + {"%c", "\n", &uintVal, uint('\n')}, // %c must accept any space. + {"%d%%", "23%\n", &uintVal, uint(23)}, // %% matches literal %. + {"%%%d", "%23\n", &uintVal, uint(23)}, // %% matches literal %. // space handling {"%d", "27", &intVal, 27}, @@ -467,6 +469,9 @@ var multiTests = []ScanfMultiTest{ {"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. + {"%%%d", "xxx 42", args(&intVal), args(42), "missing literal %"}, + {"%%%d", "x42", args(&intVal), args(42), "missing literal %"}, + {"%%%d", "42", args(&intVal), args(42), "missing literal %"}, // Bad UTF-8: should see every byte. {"%c%c%c", "\xc2X\xc2", args(&r1, &r2, &r3), args(utf8.RuneError, 'X', utf8.RuneError), ""}, |