1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:04:42 -07:00

fmt: allow %d on []byte

Fixes #1159.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/2305043
This commit is contained in:
Rob Pike 2010-10-04 11:57:48 +02:00
parent 17fe2479bf
commit f73f9ad4ad
2 changed files with 4 additions and 1 deletions

View File

@ -317,6 +317,8 @@ var fmttests = []fmtTest{
// slices with other formats
fmtTest{"%#x", []int{1, 2, 15}, `[0x1 0x2 0xf]`},
fmtTest{"%x", []int{1, 2, 15}, `[1 2 f]`},
fmtTest{"%d", []int{1, 2, 15}, `[1 2 15]`},
fmtTest{"%d", []byte{1, 2, 15}, `[1 2 15]`},
fmtTest{"%q", []string{"a", "b"}, `["a" "b"]`},
// renamings
@ -334,6 +336,7 @@ var fmttests = []fmtTest{
fmtTest{"%X", renamedUint64(17), "11"},
fmtTest{"%o", renamedUintptr(18), "22"},
fmtTest{"%x", renamedString("thing"), "7468696e67"},
fmtTest{"%d", renamedBytes([]byte{1, 2, 15}), `[1 2 15]`},
fmtTest{"%q", renamedBytes([]byte("hello")), `"hello"`},
fmtTest{"%v", renamedFloat(11), "11"},
fmtTest{"%v", renamedFloat32(22), "22"},

View File

@ -439,7 +439,7 @@ func (p *pp) fmtString(v string, verb int, goSyntax bool, value interface{}) {
}
func (p *pp) fmtBytes(v []byte, verb int, goSyntax bool, depth int, value interface{}) {
if verb == 'v' {
if verb == 'v' || verb == 'd' {
if goSyntax {
p.buf.Write(bytesBytes)
} else {