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

Function TestDecodeByteString

go/internal/cbor/decoder_test.go:10–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestDecodeByteString(t *testing.T) {
11 var bytesTests = []struct {
12 in []byte
13 out []byte
14 }{
15 {
16 in: []byte{0x40},
17 out: []byte{},
18 },
19 {
20 in: []byte{0x41, 0xab},
21 out: []byte{0xab},
22 },
23 {
24 in: []byte{
25 0x58, 0x19, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
26 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
27 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
28 0x16, 0x17, 0x18,
29 },
30 out: []byte{
31 0, 1, 2, 3, 4, 5, 6, 7,
32 8, 9, 10, 11, 12, 13, 14, 15,
33 16, 17, 18, 19, 20, 21, 22, 23,
34 24,
35 },
36 },
37 }
38
39 for _, test := range bytesTests {
40 e := NewDecoder(bytes.NewReader(test.in))
41 got, err := e.DecodeByteString()
42 if err != nil {
43 t.Errorf("Decode. err: %v", err)
44 }
45
46 if !bytes.Equal(test.out, got) {
47 t.Errorf("%v expected to decode to %v, actual %v", test.in, test.out, got)
48 }
49 }
50}
51
52func TestDecodeByteStringNotCrashing(t *testing.T) {
53 var in = []byte{0x5b, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

Callers

nothing calls this directly

Calls 2

DecodeByteStringMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected