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

Function TestReadIntfBytes

msgp/read_bytes_test.go:692–725  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

690}
691
692func TestReadIntfBytes(t *testing.T) {
693 var buf bytes.Buffer
694 en := NewWriter(&buf)
695
696 tests := make([]any, 0, 10)
697 tests = append(tests, float64(3.5))
698 tests = append(tests, int64(-49082))
699 tests = append(tests, uint64(34908))
700 tests = append(tests, string("hello!"))
701 tests = append(tests, []byte("blah."))
702 tests = append(tests, map[string]any{
703 "key_one": 3.5,
704 "key_two": "hi.",
705 })
706
707 for i, v := range tests {
708 buf.Reset()
709 if err := en.WriteIntf(v); err != nil {
710 t.Fatal(err)
711 }
712 en.Flush()
713
714 out, left, err := ReadIntfBytes(buf.Bytes())
715 if err != nil {
716 t.Errorf("test case %d: %s", i, err)
717 }
718 if len(left) != 0 {
719 t.Errorf("expected 0 bytes left; found %d", len(left))
720 }
721 if !reflect.DeepEqual(v, out) {
722 t.Errorf("ReadIntf(): %v in; %v out", v, out)
723 }
724 }
725}
726
727func BenchmarkSkipBytes(b *testing.B) {
728 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 5

WriteIntfMethod · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
ReadIntfBytesFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…