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

Function TestRaw

msgp/raw_test.go:18–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16}
17
18func TestRaw(t *testing.T) {
19 bts := make([]byte, 0, 512)
20 bts = AppendMapHeader(bts, 3)
21 bts = AppendString(bts, "key_one")
22 bts = AppendFloat64(bts, -1.0)
23 bts = AppendString(bts, "key_two")
24 bts = AppendString(bts, "value_two")
25 bts = AppendString(bts, "key_three")
26 bts = AppendTime(bts, time.Now())
27
28 var r Raw
29
30 // verify that Raw satisfies
31 // the interfaces we want it to
32 var _ allifaces = &r
33
34 // READ TESTS
35
36 extra, err := r.UnmarshalMsg(bts)
37 if err != nil {
38 t.Fatal("error from UnmarshalMsg:", err)
39 }
40 if len(extra) != 0 {
41 t.Errorf("expected 0 bytes left; found %d", len(extra))
42 }
43 if !bytes.Equal([]byte(r), bts) {
44 t.Fatal("value of raw and input slice are not equal after UnmarshalMsg")
45 }
46
47 r = r[:0]
48
49 var buf bytes.Buffer
50 buf.Write(bts)
51
52 rd := NewReader(&buf)
53
54 err = r.DecodeMsg(rd)
55 if err != nil {
56 t.Fatal("error from DecodeMsg:", err)
57 }
58
59 if !bytes.Equal([]byte(r), bts) {
60 t.Fatal("value of raw and input slice are not equal after DecodeMsg")
61 }
62
63 // WRITE TESTS
64
65 buf.Reset()
66 wr := NewWriter(&buf)
67 err = r.EncodeMsg(wr)
68 if err != nil {
69 t.Fatal("error from EncodeMsg:", err)
70 }
71
72 wr.Flush()
73 if !bytes.Equal(buf.Bytes(), bts) {
74 t.Fatal("value of buf.Bytes() and input slice are not equal after EncodeMsg")
75 }

Callers

nothing calls this directly

Calls 14

UnmarshalMsgMethod · 0.95
DecodeMsgMethod · 0.95
EncodeMsgMethod · 0.95
FlushMethod · 0.95
MarshalMsgMethod · 0.95
AppendMapHeaderFunction · 0.85
AppendStringFunction · 0.85
AppendFloat64Function · 0.85
AppendTimeFunction · 0.85
NewReaderFunction · 0.85
NewWriterFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…