]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: allow %d on []byte
authorRob Pike <r@golang.org>
Mon, 4 Oct 2010 09:57:48 +0000 (11:57 +0200)
committerRob Pike <r@golang.org>
Mon, 4 Oct 2010 09:57:48 +0000 (11:57 +0200)
Fixes #1159.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/2305043

src/pkg/fmt/fmt_test.go
src/pkg/fmt/print.go

index c8775ba3f2cc30f407739c22d61861dd6d1d51e9..f0d6a9c97029edb70b392f54e1a88aa7d86f456e 100644 (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"},
index 0f3dd44bf0642074b724570fce0bdf0b41103b88..24b1eb32e00c046596b4793391f4c2ecabc2da35 100644 (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 {