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

Function TestCopyNext

msgp/read_test.go:1024–1067  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1022}
1023
1024func TestCopyNext(t *testing.T) {
1025 var buf bytes.Buffer
1026 en := NewWriter(&buf)
1027
1028 en.WriteMapHeader(6)
1029
1030 en.WriteString("thing_one")
1031 en.WriteString("value_one")
1032
1033 en.WriteString("thing_two")
1034 en.WriteFloat64(3.14159)
1035
1036 en.WriteString("some_bytes")
1037 en.WriteBytes([]byte("nkl4321rqw908vxzpojnlk2314rqew098-s09123rdscasd"))
1038
1039 en.WriteString("the_time")
1040 en.WriteTime(time.Now())
1041
1042 en.WriteString("what?")
1043 en.WriteBool(true)
1044
1045 en.WriteString("ext")
1046 en.WriteExtension(&RawExtension{Type: 55, Data: []byte("raw data!!!")})
1047
1048 en.Flush()
1049
1050 // Read from a copy of the original buf.
1051 de := NewReader(bytes.NewReader(buf.Bytes()))
1052
1053 w := new(bytes.Buffer)
1054
1055 n, err := de.CopyNext(w)
1056 if err != nil {
1057 t.Fatal(err)
1058 }
1059 if n != int64(buf.Len()) {
1060 t.Fatalf("CopyNext returned the wrong value (%d != %d)",
1061 n, buf.Len())
1062 }
1063
1064 if !bytes.Equal(buf.Bytes(), w.Bytes()) {
1065 t.Fatalf("not equal! %v, %v", buf.Bytes(), w.Bytes())
1066 }
1067}

Callers

nothing calls this directly

Calls 13

WriteMapHeaderMethod · 0.95
WriteStringMethod · 0.95
WriteFloat64Method · 0.95
WriteBytesMethod · 0.95
WriteTimeMethod · 0.95
WriteBoolMethod · 0.95
WriteExtensionMethod · 0.95
FlushMethod · 0.95
CopyNextMethod · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…