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

Function TestLocate

msgp/edit_test.go:41–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestLocate(t *testing.T) {
42 var buf bytes.Buffer
43 en := NewWriter(&buf)
44 en.WriteMapHeader(2)
45 en.WriteString("thing_one")
46 en.WriteString("value_one")
47 en.WriteString("thing_two")
48 en.WriteFloat64(2.0)
49 en.Flush()
50
51 field := Locate("thing_one", buf.Bytes())
52 if len(field) == 0 {
53 t.Fatal("field not found")
54 }
55
56 if !HasKey("thing_one", buf.Bytes()) {
57 t.Fatal("field not found")
58 }
59
60 var zbuf bytes.Buffer
61 w := NewWriter(&zbuf)
62 w.WriteString("value_one")
63 w.Flush()
64
65 if !bytes.Equal(zbuf.Bytes(), field) {
66 t.Errorf("got %q; wanted %q", field, zbuf.Bytes())
67 }
68
69 zbuf.Reset()
70 w.WriteFloat64(2.0)
71 w.Flush()
72 field = Locate("thing_two", buf.Bytes())
73 if len(field) == 0 {
74 t.Fatal("field not found")
75 }
76 if !bytes.Equal(zbuf.Bytes(), field) {
77 t.Errorf("got %q; wanted %q", field, zbuf.Bytes())
78 }
79
80 field = Locate("nope", buf.Bytes())
81 if len(field) != 0 {
82 t.Fatalf("wanted a zero-length returned slice")
83 }
84}
85
86func TestReplace(t *testing.T) {
87 // there are 4 cases that need coverage:

Callers

nothing calls this directly

Calls 9

WriteMapHeaderMethod · 0.95
WriteStringMethod · 0.95
WriteFloat64Method · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
LocateFunction · 0.85
HasKeyFunction · 0.85
EqualMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…