Commit fffda665 authored by Kyle Lemons's avatar Kyle Lemons

Reverse the TextMarshaler default

parent 6105c208
......@@ -33,10 +33,10 @@ type Config struct {
Diffable bool // Adds extra newlines for more easily diffable output.
// Field and value options
IncludeUnexported bool // Include unexported fields in output
PrintStringers bool // Call String on a fmt.Stringer
NoTextMarshalers bool // Don't automatically call MarshalText
SkipZeroFields bool // Skip struct fields that have a zero value.
IncludeUnexported bool // Include unexported fields in output
PrintStringers bool // Call String on a fmt.Stringer
PrintTextMarshalers bool // Call MarshalText on an encoding.TextMarshaler
SkipZeroFields bool // Skip struct fields that have a zero value.
// Output transforms
ShortList int // Maximum character length for short lists if nonzero.
......
......@@ -41,7 +41,7 @@ func (c *Config) val2node(val reflect.Value) node {
if s, ok := v.(fmt.Stringer); ok && c.PrintStringers {
return stringVal(s.String())
}
if t, ok := v.(encoding.TextMarshaler); ok && !c.NoTextMarshalers {
if t, ok := v.(encoding.TextMarshaler); ok && c.PrintTextMarshalers {
if raw, err := t.MarshalText(); err == nil { // if NOT an error
return stringVal(string(raw))
}
......
......@@ -15,7 +15,6 @@
package pretty
import (
"net"
"reflect"
"testing"
"time"
......@@ -94,11 +93,6 @@ func TestVal2nodeDefault(t *testing.T) {
raw: 3,
want: rawVal("3"),
},
{
desc: "TextMarshaler",
raw: net.ParseIP("dead:beef::1"),
want: stringVal("dead:beef::1"),
},
}
for _, test := range tests {
......@@ -141,17 +135,17 @@ func TestVal2node(t *testing.T) {
raw: struct{ Date time.Time }{time.Unix(1234567890, 0).UTC()},
cfg: DefaultConfig,
want: keyvals{
{"Date", stringVal("2009-02-13T23:31:30Z")},
{"Date", keyvals{}},
},
},
{
desc: "time w/o TextMarshalers",
desc: "time w/ PrintTextMarshalers",
raw: struct{ Date time.Time }{time.Unix(1234567890, 0).UTC()},
cfg: &Config{
NoTextMarshalers: true,
PrintTextMarshalers: true,
},
want: keyvals{
{"Date", keyvals{}},
{"Date", stringVal("2009-02-13T23:31:30Z")},
},
},
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment