github.com/RomiChan/protobuf@v0.1.1-0.20230204044148-2ed269a2e54d/proto/struct_test.go (about) 1 package proto 2 3 import ( 4 "testing" 5 "unsafe" 6 ) 7 8 func TestStructFieldSize(t *testing.T) { 9 t.Log("sizeof(structField) =", unsafe.Sizeof(structField{})) 10 } 11 12 /* 13 func TestParseStructTag(t *testing.T) { 14 tests := []struct { 15 str string 16 tag structTag 17 }{ 18 { 19 str: `bytes,1,rep,name=next,proto3`, 20 tag: structTag{ 21 name: "next", 22 version: 3, 23 wireType: varlen, 24 fieldNumber: 1, 25 extensions: map[string]string{}, 26 repeated: true, 27 }, 28 }, 29 30 { 31 str: `bytes,5,opt,name=key,proto3`, 32 tag: structTag{ 33 name: "key", 34 version: 3, 35 wireType: varlen, 36 fieldNumber: 5, 37 extensions: map[string]string{}, 38 }, 39 }, 40 41 { 42 str: `fixed64,6,opt,name=seed,proto3`, 43 tag: structTag{ 44 name: "seed", 45 version: 3, 46 wireType: fixed64, 47 fieldNumber: 6, 48 extensions: map[string]string{}, 49 }, 50 }, 51 52 { 53 str: `varint,8,opt,name=expire_after,json=expireAfter,proto3`, 54 tag: structTag{ 55 name: "expire_after", 56 json: "expireAfter", 57 version: 3, 58 wireType: varint, 59 fieldNumber: 8, 60 extensions: map[string]string{}, 61 }, 62 }, 63 64 { 65 str: `bytes,17,opt,name=batch_key,json=batchKey,proto3,customtype=U128`, 66 tag: structTag{ 67 name: "batch_key", 68 json: "batchKey", 69 version: 3, 70 wireType: varlen, 71 fieldNumber: 17, 72 extensions: map[string]string{ 73 "customtype": "U128", 74 }, 75 }, 76 }, 77 } 78 79 for _, test := range tests { 80 t.Run(test.str, func(t *testing.T) { 81 tag, err := parseStructTag(test.str) 82 if err != nil { 83 t.Fatal(err) 84 } 85 if !reflect.DeepEqual(tag, test.tag) { 86 t.Errorf("struct tag mismatch\nwant: %+v\ngot: %+v", test.tag, tag) 87 } 88 }) 89 } 90 } 91 */