Compare commits

...

3 Commits

3 changed files with 21 additions and 6 deletions

View File

@ -100,12 +100,12 @@ func testGenerateRun(test *testing.T, protocol *Protocol, title, imports, testCa
log.Println("decoding:")
destination := reflect.New(reflect.ValueOf(message).Elem().Type()).Interface().(Message)
flat := data.Flatten()
log.Println("before: ", destination)
log.Println("before: ", tu.Describe(destination))
decoder := tape.NewDecoder(bytes.NewBuffer(flat))
n, err = destination.Decode(decoder)
if err != nil { log.Fatalf("at %d: %v\n", n, err) }
log.Println("got: ", destination)
log.Println("correct:", message)
log.Println("got: ", tu.Describe(destination))
log.Println("correct:", tu.Describe(message))
if n != len(flat) {
log.Fatalf("n incorrect: %d != %d\n", n, len(flat))
}

View File

@ -125,6 +125,10 @@ func (this *describer) describe(value reflect.Value) {
return
}
value = reflect.ValueOf(value.Interface())
if !value.IsValid() {
this.printf("<invalid>")
return
}
switch value.Kind() {
case reflect.Array, reflect.Slice:
this.printf("[\n")
@ -155,7 +159,7 @@ func (this *describer) describe(value reflect.Value) {
this.iprintf("\n")
}
this.indent -= 1
this.iprintf("}\n")
this.iprintf("}")
case reflect.Map:
this.printf("map {\n")
this.indent += 1
@ -168,7 +172,7 @@ func (this *describer) describe(value reflect.Value) {
this.iprintf("\n")
}
this.indent -= 1
this.iprintf("}\n")
this.iprintf("}")
case reflect.Pointer:
this.printf("& ")
this.describe(value.Elem())

View File

@ -27,6 +27,12 @@ var samplePayloads = [][]byte {
0x02, 0x23, byte(LSI.WithCN(1)), 0x45, 0x67,
0x02, 0x24, byte(LI.WithCN(3)), 0x45, 0x67, 0x89, 0xAB,
},
/* map[uint16] any */ []byte {
byte(KTV.WithCN(0)), 3,
0x00, 0x01, 0x63, 0x43, 0xF4, 0xC0, 0x00,
0x00, 0x02, 0x82, 'h', 'i',
0x00, 0x03, 0x21, 0x39, 0x92,
},
}
var sampleValues = []any {
@ -49,6 +55,11 @@ var sampleValues = []any {
0x0223: int16(0x4567),
0x0224: uint32(0x456789AB),
},
/* map[uint16] any */ map[uint16] any {
0x0001: float32(489.5),
0x0002: "hi",
0x0003: uint16(0x3992),
},
}
type userDefinedInteger int16
@ -195,7 +206,7 @@ func TestDecodeWrongType(test *testing.T) {
{ var dest []string; arrayCase(&dest) }
}
// tables should only assign to other tables
if index != 12 {
if index != 12 && index != 13 {
test.Log("- map[uint16] any")
{ var dest = map[uint16] any { }; arrayCase(&dest) }
}