diff options
author | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2011-11-23 09:04:02 -0800 |
---|---|---|
committer | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2011-11-23 09:04:02 -0800 |
commit | 49ac8931ae0e10780604001b51ec1e6b0b442c83 (patch) | |
tree | bc4351f97a0c512b8577f2dfb641ea918a576c54 /src/pkg | |
parent | 141be9a25088c455d24ed98196058ef929b2a32b (diff) | |
download | go-49ac8931ae0e10780604001b51ec1e6b0b442c83.tar.gz |
fmt: don't check for nil when printing arrays as Go syntax.
Also add array values to printing test suite.
Fixes issue 2468.
R=golang-dev, r
CC=golang-dev, remy
http://codereview.appspot.com/5436053
Committer: Rob Pike <r@golang.org>
Diffstat (limited to 'src/pkg')
-rw-r--r-- | src/pkg/fmt/fmt_test.go | 16 | ||||
-rw-r--r-- | src/pkg/fmt/print.go | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index 6370560d0..00aac798c 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -47,8 +47,10 @@ func TestFmtInterface(t *testing.T) { const b32 uint32 = 1<<32 - 1 const b64 uint64 = 1<<64 - 1 -var array = []int{1, 2, 3, 4, 5} -var iarray = []interface{}{1, "hello", 2.5, nil} +var array = [5]int{1, 2, 3, 4, 5} +var iarray = [4]interface{}{1, "hello", 2.5, nil} +var slice = array[:] +var islice = iarray[:] type A struct { i int @@ -327,6 +329,12 @@ var fmttests = []struct { {"%v", &array, "&[1 2 3 4 5]"}, {"%v", &iarray, "&[1 hello 2.5 <nil>]"}, + // slices + {"%v", slice, "[1 2 3 4 5]"}, + {"%v", islice, "[1 hello 2.5 <nil>]"}, + {"%v", &slice, "&[1 2 3 4 5]"}, + {"%v", &islice, "&[1 hello 2.5 <nil>]"}, + // complexes with %v {"%v", 1 + 2i, "(1+2i)"}, {"%v", complex64(1 + 2i), "(1+2i)"}, @@ -359,6 +367,10 @@ var fmttests = []struct { {"%#v", SI{}, `fmt_test.SI{I:interface {}(nil)}`}, {"%#v", []int(nil), `[]int(nil)`}, {"%#v", []int{}, `[]int{}`}, + {"%#v", array, `[5]int{1, 2, 3, 4, 5}`}, + {"%#v", &array, `&[5]int{1, 2, 3, 4, 5}`}, + {"%#v", iarray, `[4]interface {}{1, "hello", 2.5, interface {}(nil)}`}, + {"%#v", &iarray, `&[4]interface {}{1, "hello", 2.5, interface {}(nil)}`}, {"%#v", map[int]byte(nil), `map[int] uint8(nil)`}, {"%#v", map[int]byte{}, `map[int] uint8{}`}, diff --git a/src/pkg/fmt/print.go b/src/pkg/fmt/print.go index 7143e07a3..e5ca11724 100644 --- a/src/pkg/fmt/print.go +++ b/src/pkg/fmt/print.go @@ -877,7 +877,7 @@ BigSwitch: } if goSyntax { p.buf.WriteString(value.Type().String()) - if f.IsNil() { + if f.Kind() == reflect.Slice && f.IsNil() { p.buf.WriteString("(nil)") break } |