mirror of
https://github.com/golang/go
synced 2024-11-23 16:00:06 -07:00
fmt: add a few more reflect.Value tests
Change-Id: I86530a4fd240f3e056e3277355d2965f6863b852 Reviewed-on: https://go-review.googlesource.com/8951 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
6b045d9aef
commit
3e6b7f35de
@ -686,6 +686,14 @@ var fmtTests = []struct {
|
|||||||
// Issue 8965.
|
// Issue 8965.
|
||||||
{"%v", reflect.ValueOf(A{}).Field(0).String(), "<int Value>"}, // Equivalent to the old way.
|
{"%v", reflect.ValueOf(A{}).Field(0).String(), "<int Value>"}, // Equivalent to the old way.
|
||||||
{"%v", reflect.ValueOf(A{}).Field(0), "0"}, // Sees inside the field.
|
{"%v", reflect.ValueOf(A{}).Field(0), "0"}, // Sees inside the field.
|
||||||
|
|
||||||
|
// verbs apply to the extracted value too.
|
||||||
|
{"%s", reflect.ValueOf("hello"), "hello"},
|
||||||
|
{"%q", reflect.ValueOf("hello"), `"hello"`},
|
||||||
|
{"%#04x", reflect.ValueOf(256), "0x0100"},
|
||||||
|
|
||||||
|
// invalid reflect.Value doesn't crash.
|
||||||
|
{"%v", reflect.Value{}, "<nil>"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// zeroFill generates zero-filled strings of the specified width. The length
|
// zeroFill generates zero-filled strings of the specified width. The length
|
||||||
|
@ -847,6 +847,8 @@ func (p *pp) printReflectValue(value reflect.Value, verb rune, depth int) (wasSt
|
|||||||
p.value = value
|
p.value = value
|
||||||
BigSwitch:
|
BigSwitch:
|
||||||
switch f := value; f.Kind() {
|
switch f := value; f.Kind() {
|
||||||
|
case reflect.Invalid:
|
||||||
|
p.buf.WriteString("<invalid reflect.Value>")
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
p.fmtBool(f.Bool(), verb)
|
p.fmtBool(f.Bool(), verb)
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
Loading…
Reference in New Issue
Block a user