Fix remaining bencode tests.
I'm not sure if I'm doing the right thing, though.
This commit is contained in:
parent
7f9f262959
commit
9af83c7cd1
2 changed files with 14 additions and 2 deletions
|
@ -255,7 +255,7 @@ func TestUnmarshal(t *testing.T) {
|
|||
SVPair{"l3:abc3:defe", []string{"abc", "def"}},
|
||||
SVPair{"li42e3:abce", []any{42, "abc"}},
|
||||
SVPair{"de", map[string]any{}},
|
||||
//SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
||||
SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
||||
SVPair{"d1:ai10e1:b3:fooe", structA{10, "foo"}},
|
||||
SVPair{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
|
||||
}
|
||||
|
|
14
struct.go
14
struct.go
|
@ -72,6 +72,10 @@ func (b *structBuilder) Int64(i int64) {
|
|||
if b == nil {
|
||||
return
|
||||
}
|
||||
if !b.val.CanSet() {
|
||||
x := 0
|
||||
b.val = reflect.ValueOf(&x).Elem()
|
||||
}
|
||||
v := b.val
|
||||
if isfloat(v) {
|
||||
setfloat(v, float64(i))
|
||||
|
@ -84,6 +88,10 @@ func (b *structBuilder) Uint64(i uint64) {
|
|||
if b == nil {
|
||||
return
|
||||
}
|
||||
if !b.val.CanSet() {
|
||||
x := uint64(0)
|
||||
b.val = reflect.ValueOf(&x).Elem()
|
||||
}
|
||||
v := b.val
|
||||
if isfloat(v) {
|
||||
setfloat(v, float64(i))
|
||||
|
@ -96,6 +104,10 @@ func (b *structBuilder) Float64(f float64) {
|
|||
if b == nil {
|
||||
return
|
||||
}
|
||||
if !b.val.CanSet() {
|
||||
x := float64(0)
|
||||
b.val = reflect.ValueOf(&x).Elem()
|
||||
}
|
||||
v := b.val
|
||||
if isfloat(v) {
|
||||
setfloat(v, f)
|
||||
|
@ -169,7 +181,7 @@ func (b *structBuilder) Map() {
|
|||
if b == nil {
|
||||
return
|
||||
}
|
||||
if v := b.val; v.Kind() == reflect.Ptr && v.IsNil() {
|
||||
if v := b.val; v.Kind() == reflect.Ptr {
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.Zero(v.Type().Elem()).Addr())
|
||||
b.Flush()
|
||||
|
|
Loading…
Reference in a new issue