MCPcopy Create free account
hub / github.com/WICG/webpackage / TestEncodeInt

Function TestEncodeInt

go/internal/cbor/encoder_test.go:21–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19}
20
21func TestEncodeInt(t *testing.T) {
22 var inttests = []struct {
23 i int64
24 encoding string
25 }{
26 {0, "00"},
27 {1, "01"},
28 {10, "0a"},
29 {23, "17"},
30 {24, "1818"},
31 {25, "1819"},
32 {100, "1864"},
33 {255, "18ff"},
34 {256, "190100"},
35 {1000, "1903e8"},
36 {1000000, "1a000f4240"},
37 {1000000000000, "1b000000e8d4a51000"},
38 {-1, "20"},
39 {-10, "29"},
40 {-100, "3863"},
41 {-1000, "3903e7"},
42 {-9223372036854775808, "3b7fffffffffffffff"},
43 }
44 for _, test := range inttests {
45 var b bytes.Buffer
46 e := NewEncoder(&b)
47
48 if err := e.EncodeInt(test.i); err != nil {
49 t.Errorf("Encode. err: %v", err)
50 }
51 exp := fromHex(test.encoding)
52
53 if !bytes.Equal(exp, b.Bytes()) {
54 t.Errorf("%d expected to encode to %v, actual %v", test.i, exp, b.Bytes())
55 }
56 }
57}
58
59func TestEncodeByteString(t *testing.T) {
60 var bytesTests = []struct {

Callers

nothing calls this directly

Calls 3

EncodeIntMethod · 0.95
NewEncoderFunction · 0.85
fromHexFunction · 0.85

Tested by

no test coverage detected