Compare commits
No commits in common. "2e03867c668026bb487b3294fb0f52d3b5e342de" and "f6b12d43fbda3527ac2c31e4e811ff1eed989f2b" have entirely different histories.
2e03867c66
...
f6b12d43fb
@ -2,9 +2,8 @@ package testutil
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "slices"
|
import "slices"
|
||||||
import "reflect"
|
|
||||||
import "strings"
|
import "strings"
|
||||||
import "unicode"
|
import "reflect"
|
||||||
|
|
||||||
// Snake lets you compare blocks of data where the ordering of certain parts may
|
// Snake lets you compare blocks of data where the ordering of certain parts may
|
||||||
// be swapped every which way. It is designed for comparing the encoding of
|
// be swapped every which way. It is designed for comparing the encoding of
|
||||||
@ -142,16 +141,8 @@ func (this *describer) describe(value reflect.Value) {
|
|||||||
typ := value.Type()
|
typ := value.Type()
|
||||||
for index := range typ.NumField() {
|
for index := range typ.NumField() {
|
||||||
indexBuffer := [1]int { index }
|
indexBuffer := [1]int { index }
|
||||||
field := typ.Field(index)
|
this.iprintf("%s: ", typ.Field(index).Name)
|
||||||
this.iprintf("%s: ", field.Name)
|
this.describe(value.FieldByIndex(indexBuffer[:]))
|
||||||
for _, char := range field.Name {
|
|
||||||
if unicode.IsUpper(char) {
|
|
||||||
this.describe(value.FieldByIndex(indexBuffer[:]))
|
|
||||||
} else {
|
|
||||||
this.printf("<private>")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
this.iprintf("\n")
|
this.iprintf("\n")
|
||||||
}
|
}
|
||||||
this.indent -= 1
|
this.indent -= 1
|
||||||
|
|||||||
@ -116,9 +116,9 @@ func DecodeAnyInto(decoder *Decoder, destination any, tag Tag) (n int, err error
|
|||||||
func DecodeAny(decoder *Decoder, tag Tag) (value any, n int, err error) {
|
func DecodeAny(decoder *Decoder, tag Tag) (value any, n int, err error) {
|
||||||
destination, err := skeletonPointer(decoder, tag)
|
destination, err := skeletonPointer(decoder, tag)
|
||||||
if err != nil { return nil, n, err }
|
if err != nil { return nil, n, err }
|
||||||
nn, err := decodeAny(decoder, destination, tag)
|
nn, err := DecodeAnyInto(decoder, destination, tag)
|
||||||
n += nn; if err != nil { return nil, n, err }
|
n += nn; if err != nil { return nil, n, err }
|
||||||
return destination.Elem().Interface(), n, err
|
return destination, n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// unknownSlicePlaceholder is inserted by skeletonValue and informs the program
|
// unknownSlicePlaceholder is inserted by skeletonValue and informs the program
|
||||||
|
|||||||
@ -335,24 +335,3 @@ func TestTagAny(test *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeAny(test *testing.T) {
|
|
||||||
for index, payload := range samplePayloads {
|
|
||||||
correctValue := sampleValues[index]
|
|
||||||
data := payload[1:]
|
|
||||||
decoder := NewDecoder(bytes.NewBuffer(data))
|
|
||||||
tag := Tag(payload[0])
|
|
||||||
decoded, n, err := DecodeAny(decoder, tag)
|
|
||||||
test.Log("n: ", n)
|
|
||||||
test.Log("tag: ", tag)
|
|
||||||
test.Log("got: ", tu.Describe(decoded))
|
|
||||||
test.Log("correct:", tu.Describe(correctValue))
|
|
||||||
if err != nil { test.Fatal(err) }
|
|
||||||
if !reflect.DeepEqual(decoded, correctValue) {
|
|
||||||
test.Fatal("values not equal")
|
|
||||||
}
|
|
||||||
if n != len(data) {
|
|
||||||
test.Fatalf("n not equal: %d != %d", n, len(data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user