MCPcopy
hub / github.com/uber-go/zap / TestDict

Function TestDict

field_test.go:295–317  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

293}
294
295func TestDict(t *testing.T) {
296 tests := []struct {
297 desc string
298 field Field
299 expected any
300 }{
301 {"empty", Dict(""), map[string]any{}},
302 {"single", Dict("", String("k", "v")), map[string]any{"k": "v"}},
303 {"multiple", Dict("", String("k", "v"), String("k2", "v2")), map[string]any{"k": "v", "k2": "v2"}},
304 }
305
306 for _, tt := range tests {
307 t.Run(tt.desc, func(t *testing.T) {
308 enc := zapcore.NewMapObjectEncoder()
309 tt.field.Key = "k"
310 tt.field.AddTo(enc)
311 assert.Equal(t, tt.expected, enc.Fields["k"], "unexpected map contents")
312 assert.Len(t, enc.Fields, 1, "found extra keys in map: %v", enc.Fields)
313
314 assertCanBeReused(t, tt.field)
315 })
316 }
317}
318
319func TestDictObject(t *testing.T) {
320 tests := []struct {

Callers

nothing calls this directly

Calls 6

NewMapObjectEncoderFunction · 0.92
DictFunction · 0.85
StringFunction · 0.85
AddToMethod · 0.80
assertCanBeReusedFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected