File: encode_test.go

package info (click to toggle)
delve 1.24.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,092 kB
  • sloc: ansic: 111,943; sh: 169; asm: 141; makefile: 43; python: 23
file content (42 lines) | stat: -rw-r--r-- 960 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package leb128

import (
	"bytes"
	"testing"
)

func TestEncodeUnsigned(t *testing.T) {
	tc := []uint64{0x00, 0x7f, 0x80, 0x8f, 0xffff, 0xfffffff7}
	for i := range tc {
		var buf bytes.Buffer
		EncodeUnsigned(&buf, tc[i])
		enc := append([]byte{}, buf.Bytes()...)
		buf.Write([]byte{0x1, 0x2, 0x3})
		out, c := DecodeUnsigned(&buf)
		t.Logf("input %x output %x encoded %x", tc[i], out, enc)
		if c != uint32(len(enc)) {
			t.Errorf("wrong encode")
		}
		if out != tc[i] {
			t.Errorf("wrong encode")
		}
	}
}

func TestEncodeSigned(t *testing.T) {
	tc := []int64{2, -2, 127, -127, 128, -128, 129, -129}
	for i := range tc {
		var buf bytes.Buffer
		EncodeSigned(&buf, tc[i])
		enc := append([]byte{}, buf.Bytes()...)
		buf.Write([]byte{0x1, 0x2, 0x3})
		out, c := DecodeSigned(&buf)
		t.Logf("input %x output %x encoded %x", tc[i], out, enc)
		if c != uint32(len(enc)) {
			t.Errorf("wrong encode")
		}
		if out != tc[i] {
			t.Errorf("wrong encode")
		}
	}
}