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

Function TestCopyJSONNumericMapKeys

msgp/json_test.go:80–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestCopyJSONNumericMapKeys(t *testing.T) {
81 var buf bytes.Buffer
82 enc := NewWriter(&buf)
83 enc.WriteMapHeader(2)
84 enc.WriteInt64(-5)
85 enc.WriteString("neg")
86 enc.WriteUint64(42)
87 enc.WriteString("pos")
88 enc.Flush()
89
90 var js bytes.Buffer
91 if _, err := CopyToJSON(&js, &buf); err != nil {
92 t.Fatal(err)
93 }
94 mp := make(map[string]any)
95 if err := json.Unmarshal(js.Bytes(), &mp); err != nil {
96 t.Fatalf("unmarshal: %s — json: %s", err, js.String())
97 }
98 if mp["-5"] != "neg" || mp["42"] != "pos" {
99 t.Errorf("unexpected map: %v", mp)
100 }
101}
102
103// Encoder should generate valid utf-8 even if passed bad input
104func TestCopyJSONNegativeUTF8(t *testing.T) {

Callers

nothing calls this directly

Calls 8

WriteMapHeaderMethod · 0.95
WriteInt64Method · 0.95
WriteStringMethod · 0.95
WriteUint64Method · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
CopyToJSONFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…