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

Function TestJSONEncoderArrays

zapcore/json_encoder_impl_test.go:340–457  ·  zapcore/json_encoder_impl_test.go::TestJSONEncoderArrays
(t *testing.T)

Source from the content-addressed store, hash-verified

338}
339
340func TestJSONEncoderArrays(t *testing.T) {
341 tests := []struct {
342 desc string
343 expected string // expect f to be called twice
344 f func(ArrayEncoder)
345 }{
346 {"bool", `[true,true]`, func(e ArrayEncoder) { e.AppendBool(true) }},
347 {"byteString", `["k","k"]`, func(e ArrayEncoder) { e.AppendByteString([]byte("k")) }},
348 {"byteString", `["k\\","k\\"]`, func(e ArrayEncoder) { e.AppendByteString([]byte(`k\`)) }},
349 {"complex128", `["1+2i","1+2i"]`, func(e ArrayEncoder) { e.AppendComplex128(1 + 2i) }},
350 {"complex64", `["1+2i","1+2i"]`, func(e ArrayEncoder) { e.AppendComplex64(1 + 2i) }},
351 {"durations", `[0.000000002,0.000000002]`, func(e ArrayEncoder) { e.AppendDuration(2) }},
352 {"float64", `[3.14,3.14]`, func(e ArrayEncoder) { e.AppendFloat64(3.14) }},
353 {"float32", `[3.14,3.14]`, func(e ArrayEncoder) { e.AppendFloat32(3.14) }},
354 {"int", `[42,42]`, func(e ArrayEncoder) { e.AppendInt(42) }},
355 {"int64", `[42,42]`, func(e ArrayEncoder) { e.AppendInt64(42) }},
356 {"int32", `[42,42]`, func(e ArrayEncoder) { e.AppendInt32(42) }},
357 {"int16", `[42,42]`, func(e ArrayEncoder) { e.AppendInt16(42) }},
358 {"int8", `[42,42]`, func(e ArrayEncoder) { e.AppendInt8(42) }},
359 {"string", `["k","k"]`, func(e ArrayEncoder) { e.AppendString("k") }},
360 {"string", `["k\\","k\\"]`, func(e ArrayEncoder) { e.AppendString(`k\`) }},
361 {"times", `[1,1]`, func(e ArrayEncoder) { e.AppendTime(time.Unix(1, 0)) }},
362 {"uint", `[42,42]`, func(e ArrayEncoder) { e.AppendUint(42) }},
363 {"uint64", `[42,42]`, func(e ArrayEncoder) { e.AppendUint64(42) }},
364 {"uint32", `[42,42]`, func(e ArrayEncoder) { e.AppendUint32(42) }},
365 {"uint16", `[42,42]`, func(e ArrayEncoder) { e.AppendUint16(42) }},
366 {"uint8", `[42,42]`, func(e ArrayEncoder) { e.AppendUint8(42) }},
367 {"uintptr", `[42,42]`, func(e ArrayEncoder) { e.AppendUintptr(42) }},
368 {
369 desc: "arrays (success)",
370 expected: `[[true],[true]]`,
371 f: func(arr ArrayEncoder) {
372 assert.NoError(t, arr.AppendArray(ArrayMarshalerFunc(func(inner ArrayEncoder) error {
373 inner.AppendBool(true)
374 return nil
375 })), "Unexpected error appending an array.")
376 },
377 },
378 {
379 desc: "arrays (error)",
380 expected: `[[true],[true]]`,
381 f: func(arr ArrayEncoder) {
382 assert.Error(t, arr.AppendArray(ArrayMarshalerFunc(func(inner ArrayEncoder) error {
383 inner.AppendBool(true)
384 return errors.New("fail")
385 })), "Expected an error appending an array.")
386 },
387 },
388 {
389 desc: "objects (success)",
390 expected: `[{"loggable":"yes"},{"loggable":"yes"}]`,
391 f: func(arr ArrayEncoder) {
392 assert.NoError(t, arr.AppendObject(loggable{true}), "Unexpected error appending an object.")
393 },
394 },
395 {
396 desc: "objects (error)",
397 expected: `[{},{}]`,

Callers

nothing calls this directly

Calls 15

ArrayMarshalerFuncFuncType · 0.85
assertOutputFunction · 0.85
AppendBoolMethod · 0.65
AppendByteStringMethod · 0.65
AppendComplex128Method · 0.65
AppendComplex64Method · 0.65
AppendDurationMethod · 0.65
AppendFloat64Method · 0.65
AppendFloat32Method · 0.65
AppendIntMethod · 0.65
AppendInt64Method · 0.65
AppendInt32Method · 0.65

Tested by

no test coverage detected