generate: Write tests for Any type

This commit is contained in:
Sasha Koshka 2025-09-10 09:45:09 -04:00
parent c4ab60515b
commit 1bb565c6fe

View File

@ -62,6 +62,27 @@ func init() {
}, },
}, },
} }
exampleProtocol.Messages[0x0005] = Message {
Name: "Dynamic",
Type: TypeTableDefined {
Fields: map[uint16] Field {
0x0000: Field { Name: "AU8", Type: TypeAny { } },
0x0001: Field { Name: "AU16", Type: TypeAny { } },
0x0002: Field { Name: "AU32", Type: TypeAny { } },
0x0003: Field { Name: "AU64", Type: TypeAny { } },
0x0004: Field { Name: "AI8", Type: TypeAny { } },
0x0005: Field { Name: "AI16", Type: TypeAny { } },
0x0006: Field { Name: "AI32", Type: TypeAny { } },
0x0007: Field { Name: "AI64", Type: TypeAny { } },
0x0008: Field { Name: "AF32", Type: TypeAny { } },
0x0009: Field { Name: "AF64", Type: TypeAny { } },
0x000A: Field { Name: "AString", Type: TypeAny { } },
0x000B: Field { Name: "AArray", Type: TypeAny { } },
0x000C: Field { Name: "ATable", Type: TypeAny { } },
0x000D: Field { Name: "T0", Type: TypeTable { } },
},
},
}
exampleProtocol.Types["User"] = TypeTableDefined { exampleProtocol.Types["User"] = TypeTableDefined {
Fields: map[uint16] Field { Fields: map[uint16] Field {
0x0000: Field { Name: "Name", Type: TypeString { } }, 0x0000: Field { Name: "Name", Type: TypeString { } },
@ -196,6 +217,53 @@ func TestGenerateRunEncodeDecode(test *testing.T) {
[]byte { 0x00, 0x0D, 0x43, 0xEF, 0x1E, 0xCB, 0x37 }, []byte { 0x00, 0x0D, 0x43, 0xEF, 0x1E, 0xCB, 0x37 },
[]byte { 0x00, 0x0E, 0x47, 0x9C, 0x6E, 0xF6, 0x43, 0xEF, 0x1E, 0xCB, 0x37 }, []byte { 0x00, 0x0E, 0x47, 0x9C, 0x6E, 0xF6, 0x43, 0xEF, 0x1E, 0xCB, 0x37 },
)) ))
log.Println("MessageDynamic")
messageDynamic := MessageDynamic {
AU8: uint8(0x23),
AU16: uint16(0x3247),
AU32: uint32(0x87324523),
AU64: uint64(0x3284029034098234),
AI8: int8(0x23),
AI16: int16(0x3247),
AI32: int32(0x57324523),
AI64: int64(0x3284029034098234),
AF32: float32(2342.2378),
AF64: float64(324.8899992),
AString: "fox bed",
AArray: []int16 { 0x7, 0x6, 0x5, 0x4 },
ATable: map[uint16] any {
0x0001: int8(0x8),
0x0002: float64(4.4),
},
T0: map[uint16] any {
0x0001: float32(489.5),
0x0002: "hi",
0x0003: uint16(0x3992),
},
}
testEncodeDecode(
&messageDynamic,
tu.S(0xE1, 14).AddVar(
[]byte { 0x00, 0x00, 0x20, 0x23 },
[]byte { 0x00, 0x01, 0x21, 0x32, 0x47 },
[]byte { 0x00, 0x02, 0x23, 0x87, 0x32, 0x45, 0x23 },
[]byte { 0x00, 0x03, 0x27, 0x32, 0x84, 0x02, 0x90, 0x34, 0x09, 0x82, 0x34 },
[]byte { 0x00, 0x04, 0x40, 0x23 },
[]byte { 0x00, 0x05, 0x41, 0x32, 0x47 },
[]byte { 0x00, 0x06, 0x43, 0x57, 0x32, 0x45, 0x23 },
[]byte { 0x00, 0x07, 0x47, 0x32, 0x84, 0x02, 0x90, 0x34, 0x09, 0x82, 0x34 },
[]byte { 0x00, 0x08, 0x63, 0x45, 0x12, 0x63, 0xCE },
[]byte { 0x00, 0x09, 0x67, 0x40, 0x74, 0x4E, 0x3D, 0x6F, 0xCD, 0x17, 0x75 },
[]byte { 0x00, 0x0A, 0x87, 'f', 'o', 'x', ' ', 'b', 'e', 'd' },
[]byte { 0x00, 0x0B, 0xC4, 0x00, 0x07, 0x00, 0x06, 0x00, 0x05, 0x00, 0x04 },
[]byte { 0x00, 0x0C, 0xE1, 0x02,
0x00, 0x01, 0x20, 0x08,
0x00, 0x02, 0x67, 0x40, 0x11, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9A },
[]byte { 0x00, 0x0D, 0xE1, 0x03,
0x00, 0x01, 0x63, 0x43, 0xF4, 0xC0, 0x00,
0x00, 0x02, 0x82, 'h', 'i',
0x00, 0x03, 0x21, 0x39, 0x92 },
))
`) `)
} }