diff --git a/bugfix_test.go b/bugfix_test.go new file mode 100644 index 0000000..dd92c16 --- /dev/null +++ b/bugfix_test.go @@ -0,0 +1,24 @@ +package notation + +import "testing" + +func TestMapWrapping(t *testing.T) { + const expect = `map[*interface{}]interface{}{ + *interface{}(string("foo")): interface{}(bool(true)), + *interface{}(string("foo")): interface{}(bool(true)), +}` + + ifpointer := func(v interface{}) *interface{} { + return &v + } + + m := map[*interface{}]interface{}{ + ifpointer("foo"): true, + ifpointer("foo"): true, + } + + s := Sprintwv(m) + if s != expect { + t.Fatalf("expected: %s, got: %s", expect, s) + } +} diff --git a/notation.go b/notation.go index e8d7433..611e7e9 100644 --- a/notation.go +++ b/notation.go @@ -24,6 +24,7 @@ const ( skipTypes allTypes randomMaps + pointerValues ) type wrapLen struct { diff --git a/reflect.go b/reflect.go index 478dacb..1b8d3ea 100644 --- a/reflect.go +++ b/reflect.go @@ -144,9 +144,10 @@ func reflectMap(o opts, p *pending, r reflect.Value) node { sn := make(map[string]node) for _, key := range r.MapKeys() { kn := reflectValue(itemOpts, p, key) + knExt := reflectValue(allTypes|pointerValues, p, key) var b bytes.Buffer wr := writer{w: &b} - fprint(&wr, 0, kn) + fprint(&wr, 0, knExt) skey := b.String() skeys = append(skeys, skey) sv[skey] = key @@ -183,7 +184,11 @@ func reflectPointer(o opts, p *pending, r reflect.Value) node { return e } - return nodeOf("*", e) + if o&pointerValues == 0 { + return nodeOf("*", e) + } + + return nodeOf("*(", r.Pointer(), ")", e) } func reflectList(o opts, p *pending, r reflect.Value) node {