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

Function TestEncodeByteString

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

Source from the content-addressed store, hash-verified

57}
58
59func TestEncodeByteString(t *testing.T) {
60 var bytesTests = []struct {
61 bs []byte
62 encoding string
63 }{
64 {[]byte{}, "40"},
65 {[]byte{0xab}, "41ab"},
66 {
67 []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24},
68 "5819 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18",
69 },
70 }
71 // This doesn't test every size of integer that might encode the length
72 // of the byte string.
73
74 for _, test := range bytesTests {
75 var b bytes.Buffer
76 e := NewEncoder(&b)
77
78 if err := e.EncodeByteString(test.bs); err != nil {
79 t.Errorf("Encode. err: %v", err)
80 }
81 exp := fromHex(test.encoding)
82
83 if !bytes.Equal(exp, b.Bytes()) {
84 t.Errorf("%v expected to encode to %v, actual %v", test.bs, exp, b.Bytes())
85 }
86 }
87}
88
89func TestEncodeTextString(t *testing.T) {
90 var textTests = []struct {

Callers

nothing calls this directly

Calls 3

EncodeByteStringMethod · 0.95
NewEncoderFunction · 0.85
fromHexFunction · 0.85

Tested by

no test coverage detected