fix bug with node length of conflicting map entries
This commit is contained in:
parent
197f72bb5b
commit
a0113b016b
24
bugfix_test.go
Normal file
24
bugfix_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ const (
|
||||
skipTypes
|
||||
allTypes
|
||||
randomMaps
|
||||
pointerValues
|
||||
)
|
||||
|
||||
type wrapLen struct {
|
||||
|
@ -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,9 +184,13 @@ func reflectPointer(o opts, p *pending, r reflect.Value) node {
|
||||
return e
|
||||
}
|
||||
|
||||
if o&pointerValues == 0 {
|
||||
return nodeOf("*", e)
|
||||
}
|
||||
|
||||
return nodeOf("*(", r.Pointer(), ")", e)
|
||||
}
|
||||
|
||||
func reflectList(o opts, p *pending, r reflect.Value) node {
|
||||
if r.IsNil() {
|
||||
return reflectNil(o, true, r)
|
||||
|
Loading…
Reference in New Issue
Block a user