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

Function TestDictObject

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

Source from the content-addressed store, hash-verified

317}
318
319func TestDictObject(t *testing.T) {
320 tests := []struct {
321 desc string
322 field Field
323 expected any
324 }{
325 {
326 "empty",
327 Object("", DictObject()),
328 map[string]any{},
329 },
330 {
331 "object",
332 Object("", DictObject(String("k", "v"))),
333 map[string]any{"k": "v"},
334 },
335 {
336 "objects",
337 Objects("", []zapcore.ObjectMarshaler{
338 DictObject(String("k", "v")),
339 DictObject(String("k2", "v2")),
340 }),
341 []any{
342 map[string]any{"k": "v"},
343 map[string]any{"k2": "v2"},
344 },
345 },
346 }
347
348 for _, tt := range tests {
349 t.Run(tt.desc, func(t *testing.T) {
350 enc := zapcore.NewMapObjectEncoder()
351 tt.field.Key = "k"
352 tt.field.AddTo(enc)
353 assert.Equal(t, tt.expected, enc.Fields["k"], "unexpected map contents")
354 assert.Len(t, enc.Fields, 1, "found extra keys in map: %v", enc.Fields)
355
356 assertCanBeReused(t, tt.field)
357 })
358 }
359}

Callers

nothing calls this directly

Calls 8

NewMapObjectEncoderFunction · 0.92
ObjectFunction · 0.85
DictObjectFunction · 0.85
StringFunction · 0.85
ObjectsFunction · 0.85
AddToMethod · 0.80
assertCanBeReusedFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected