github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/dwarf/leb128/encode_test.go (about) 1 package leb128 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestEncodeUnsigned(t *testing.T) { 9 tc := []uint64{0x00, 0x7f, 0x80, 0x8f, 0xffff, 0xfffffff7} 10 for i := range tc { 11 var buf bytes.Buffer 12 EncodeUnsigned(&buf, tc[i]) 13 enc := append([]byte{}, buf.Bytes()...) 14 buf.Write([]byte{0x1, 0x2, 0x3}) 15 out, c := DecodeUnsigned(&buf) 16 t.Logf("input %x output %x encoded %x", tc[i], out, enc) 17 if c != uint32(len(enc)) { 18 t.Errorf("wrong encode") 19 } 20 if out != tc[i] { 21 t.Errorf("wrong encode") 22 } 23 } 24 } 25 26 func TestEncodeSigned(t *testing.T) { 27 tc := []int64{2, -2, 127, -127, 128, -128, 129, -129} 28 for i := range tc { 29 var buf bytes.Buffer 30 EncodeSigned(&buf, tc[i]) 31 enc := append([]byte{}, buf.Bytes()...) 32 buf.Write([]byte{0x1, 0x2, 0x3}) 33 out, c := DecodeSigned(&buf) 34 t.Logf("input %x output %x encoded %x", tc[i], out, enc) 35 if c != uint32(len(enc)) { 36 t.Errorf("wrong encode") 37 } 38 if out != tc[i] { 39 t.Errorf("wrong encode") 40 } 41 } 42 }