Skip to content

Commit

Permalink
Fix inconsistency between MapObjectEncoder's AddByteString and Append…
Browse files Browse the repository at this point in the history
…ByteString (uber-go#657)
  • Loading branch information
NWilson authored and prashantv committed Apr 29, 2019
1 parent 932547e commit f2a0457
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestArrayWrappers(t *testing.T) {
{"empty uint8s", Uint8s("", []uint8{}), []interface{}{}},
{"empty uintptrs", Uintptrs("", []uintptr{}), []interface{}{}},
{"bools", Bools("", []bool{true, false}), []interface{}{true, false}},
{"byte strings", ByteStrings("", [][]byte{{1, 2}, {3, 4}}), []interface{}{[]byte{1, 2}, []byte{3, 4}}},
{"byte strings", ByteStrings("", [][]byte{{1, 2}, {3, 4}}), []interface{}{"\x01\x02", "\x03\x04"}},
{"complex128s", Complex128s("", []complex128{1 + 2i, 3 + 4i}), []interface{}{1 + 2i, 3 + 4i}},
{"complex64s", Complex64s("", []complex64{1 + 2i, 3 + 4i}), []interface{}{complex64(1 + 2i), complex64(3 + 4i)}},
{"durations", Durations("", []time.Duration{1, 2}), []interface{}{time.Nanosecond, 2 * time.Nanosecond}},
Expand Down
2 changes: 1 addition & 1 deletion zapcore/memory_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *sliceArrayEncoder) AppendReflected(v interface{}) error {
}

func (s *sliceArrayEncoder) AppendBool(v bool) { s.elems = append(s.elems, v) }
func (s *sliceArrayEncoder) AppendByteString(v []byte) { s.elems = append(s.elems, v) }
func (s *sliceArrayEncoder) AppendByteString(v []byte) { s.elems = append(s.elems, string(v)) }
func (s *sliceArrayEncoder) AppendComplex128(v complex128) { s.elems = append(s.elems, v) }
func (s *sliceArrayEncoder) AppendComplex64(v complex64) { s.elems = append(s.elems, v) }
func (s *sliceArrayEncoder) AppendDuration(v time.Duration) { s.elems = append(s.elems, v) }
Expand Down
6 changes: 6 additions & 0 deletions zapcore/memory_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func TestMapObjectEncoderAdd(t *testing.T) {
f: func(e ObjectEncoder) { e.AddBinary("k", []byte("foo")) },
expected: []byte("foo"),
},
{
desc: "AddByteString",
f: func(e ObjectEncoder) { e.AddByteString("k", []byte("foo")) },
expected: "foo",
},
{
desc: "AddBool",
f: func(e ObjectEncoder) { e.AddBool("k", true) },
Expand Down Expand Up @@ -228,6 +233,7 @@ func TestSliceArrayEncoderAppend(t *testing.T) {
// AppendObject and AppendArray are covered by the AddObject (nested) and
// AddArray (nested) cases above.
{"AppendBool", func(e ArrayEncoder) { e.AppendBool(true) }, true},
{"AppendByteString", func(e ArrayEncoder) { e.AppendByteString([]byte("foo")) }, "foo"},
{"AppendComplex128", func(e ArrayEncoder) { e.AppendComplex128(1 + 2i) }, 1 + 2i},
{"AppendComplex64", func(e ArrayEncoder) { e.AppendComplex64(1 + 2i) }, complex64(1 + 2i)},
{"AppendDuration", func(e ArrayEncoder) { e.AppendDuration(time.Second) }, time.Second},
Expand Down

0 comments on commit f2a0457

Please sign in to comment.