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

Function TestAppendString

msgp/write_bytes_test.go:347–365  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

345func BenchmarkAppend2048Bytes(b *testing.B) { benchappendBytes(2048, b) }
346
347func TestAppendString(t *testing.T) {
348 sizes := []int{0, 1, 225, int(tuint32)}
349 var buf bytes.Buffer
350 en := NewWriter(&buf)
351 var bts []byte
352
353 for _, sz := range sizes {
354 buf.Reset()
355 s := string(RandBytes(sz))
356 en.WriteString(s)
357 en.Flush()
358 bts = AppendString(bts[0:0], s)
359 if !bytes.Equal(buf.Bytes(), bts) {
360 t.Errorf("for string of length %d, encoder wrote %d bytes and append wrote %d bytes", sz, buf.Len(), len(bts))
361 t.Errorf("WriteString prefix: %x", buf.Bytes()[0:5])
362 t.Errorf("Appendstring prefix: %x", bts[0:5])
363 }
364 }
365}
366
367func benchappendString(size uint32, b *testing.B) {
368 str := string(RandBytes(int(size)))

Callers

nothing calls this directly

Calls 8

WriteStringMethod · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
RandBytesFunction · 0.85
AppendStringFunction · 0.85
LenMethod · 0.65
ResetMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…