MCPcopy
hub / github.com/tinylib/msgp / TestWriteArrayHeader

Function TestWriteArrayHeader

msgp/write_test.go:82–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestWriteArrayHeader(t *testing.T) {
83 tests := []struct {
84 Sz uint32
85 Outbytes []byte
86 }{
87 {0, []byte{mfixarray}},
88 {1, []byte{mfixarray | byte(1)}},
89 {tuint16, []byte{marray16, byte(tuint16 >> 8), byte(tuint16)}},
90 {tuint32, []byte{marray32, byte(tuint32 >> 24), byte(tuint32 >> 16), byte(tuint32 >> 8), byte(tuint32)}},
91 }
92
93 var buf bytes.Buffer
94 var err error
95 wr := NewWriter(&buf)
96 for _, test := range tests {
97 buf.Reset()
98 err = wr.WriteArrayHeader(test.Sz)
99 if err != nil {
100 t.Error(err)
101 }
102 err = wr.Flush()
103 if err != nil {
104 t.Fatal(err)
105 }
106 if !bytes.Equal(buf.Bytes(), test.Outbytes) {
107 t.Errorf("Expected bytes %x; got %x", test.Outbytes, buf.Bytes())
108 }
109 }
110}
111
112func TestReadWriteStringHeader(t *testing.T) {
113 sizes := []uint32{0, 5, 8, 19, 150, tuint16, tuint32}

Callers

nothing calls this directly

Calls 6

WriteArrayHeaderMethod · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
ResetMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…