MCPcopy Index your code
hub / github.com/vmihailenco/msgpack / TestMapWithInternedString

Function TestMapWithInternedString

intern_test.go:113–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func TestMapWithInternedString(t *testing.T) {
114 type M map[string]interface{}
115
116 dict := []string{"hello world", "foo bar"}
117
118 var buf bytes.Buffer
119
120 enc := msgpack.NewEncoder(nil)
121 enc.ResetDict(&buf, dictMap(dict))
122
123 dec := msgpack.NewDecoder(nil)
124 dec.ResetDict(&buf, dict)
125
126 for i := 0; i < 100; i++ {
127 in := M{
128 "foo bar": "hello world",
129 "hello world": "foo bar",
130 "foo": "bar",
131 }
132 err := enc.Encode(in)
133 require.Nil(t, err)
134
135 _, err = dec.DecodeInterface()
136 require.Nil(t, err)
137 }
138}
139
140func dictMap(dict []string) map[string]int {
141 m := make(map[string]int, len(dict))

Callers

nothing calls this directly

Calls 5

ResetDictMethod · 0.95
ResetDictMethod · 0.95
EncodeMethod · 0.95
DecodeInterfaceMethod · 0.95
dictMapFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…