Compare commits
3 Commits
f6b12d43fb
...
2e03867c66
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e03867c66 | |||
| 7a03d8d6b5 | |||
| b2504cda2d |
@ -2,8 +2,9 @@ package testutil
|
||||
|
||||
import "fmt"
|
||||
import "slices"
|
||||
import "strings"
|
||||
import "reflect"
|
||||
import "strings"
|
||||
import "unicode"
|
||||
|
||||
// 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
|
||||
@ -141,8 +142,16 @@ func (this *describer) describe(value reflect.Value) {
|
||||
typ := value.Type()
|
||||
for index := range typ.NumField() {
|
||||
indexBuffer := [1]int { index }
|
||||
this.iprintf("%s: ", typ.Field(index).Name)
|
||||
field := typ.Field(index)
|
||||
this.iprintf("%s: ", field.Name)
|
||||
for _, char := range field.Name {
|
||||
if unicode.IsUpper(char) {
|
||||
this.describe(value.FieldByIndex(indexBuffer[:]))
|
||||
} else {
|
||||
this.printf("<private>")
|
||||
}
|
||||
break
|
||||
}
|
||||
this.iprintf("\n")
|
||||
}
|
||||
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) {
|
||||
destination, err := skeletonPointer(decoder, tag)
|
||||
if err != nil { return nil, n, err }
|
||||
nn, err := DecodeAnyInto(decoder, destination, tag)
|
||||
nn, err := decodeAny(decoder, destination, tag)
|
||||
n += nn; if err != nil { return nil, n, err }
|
||||
return destination, n, err
|
||||
return destination.Elem().Interface(), n, err
|
||||
}
|
||||
|
||||
// unknownSlicePlaceholder is inserted by skeletonValue and informs the program
|
||||
|
||||
@ -335,3 +335,24 @@ 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