(t *testing.T)
| 257 | } |
| 258 | |
| 259 | func TestSliceArrayEncoderAppend(t *testing.T) { |
| 260 | tests := []struct { |
| 261 | desc string |
| 262 | f func(ArrayEncoder) |
| 263 | expected interface{} |
| 264 | }{ |
| 265 | // AppendObject and AppendArray are covered by the AddObject (nested) and |
| 266 | // AddArray (nested) cases above. |
| 267 | {"AppendBool", func(e ArrayEncoder) { e.AppendBool(true) }, true}, |
| 268 | {"AppendByteString", func(e ArrayEncoder) { e.AppendByteString([]byte("foo")) }, "foo"}, |
| 269 | {"AppendComplex128", func(e ArrayEncoder) { e.AppendComplex128(1 + 2i) }, 1 + 2i}, |
| 270 | {"AppendComplex64", func(e ArrayEncoder) { e.AppendComplex64(1 + 2i) }, complex64(1 + 2i)}, |
| 271 | {"AppendDuration", func(e ArrayEncoder) { e.AppendDuration(time.Second) }, time.Second}, |
| 272 | {"AppendFloat64", func(e ArrayEncoder) { e.AppendFloat64(3.14) }, 3.14}, |
| 273 | {"AppendFloat32", func(e ArrayEncoder) { e.AppendFloat32(3.14) }, float32(3.14)}, |
| 274 | {"AppendInt", func(e ArrayEncoder) { e.AppendInt(42) }, 42}, |
| 275 | {"AppendInt64", func(e ArrayEncoder) { e.AppendInt64(42) }, int64(42)}, |
| 276 | {"AppendInt32", func(e ArrayEncoder) { e.AppendInt32(42) }, int32(42)}, |
| 277 | {"AppendInt16", func(e ArrayEncoder) { e.AppendInt16(42) }, int16(42)}, |
| 278 | {"AppendInt8", func(e ArrayEncoder) { e.AppendInt8(42) }, int8(42)}, |
| 279 | {"AppendString", func(e ArrayEncoder) { e.AppendString("foo") }, "foo"}, |
| 280 | {"AppendTime", func(e ArrayEncoder) { e.AppendTime(time.Unix(0, 100)) }, time.Unix(0, 100)}, |
| 281 | {"AppendUint", func(e ArrayEncoder) { e.AppendUint(42) }, uint(42)}, |
| 282 | {"AppendUint64", func(e ArrayEncoder) { e.AppendUint64(42) }, uint64(42)}, |
| 283 | {"AppendUint32", func(e ArrayEncoder) { e.AppendUint32(42) }, uint32(42)}, |
| 284 | {"AppendUint16", func(e ArrayEncoder) { e.AppendUint16(42) }, uint16(42)}, |
| 285 | {"AppendUint8", func(e ArrayEncoder) { e.AppendUint8(42) }, uint8(42)}, |
| 286 | {"AppendUintptr", func(e ArrayEncoder) { e.AppendUintptr(42) }, uintptr(42)}, |
| 287 | { |
| 288 | desc: "AppendReflected", |
| 289 | f: func(e ArrayEncoder) { |
| 290 | assert.NoError(t, e.AppendReflected(map[string]interface{}{"foo": 5})) |
| 291 | }, |
| 292 | expected: map[string]interface{}{"foo": 5}, |
| 293 | }, |
| 294 | { |
| 295 | desc: "AppendArray (arrays of arrays)", |
| 296 | f: func(e ArrayEncoder) { |
| 297 | err := e.AppendArray(ArrayMarshalerFunc(func(inner ArrayEncoder) error { |
| 298 | inner.AppendBool(true) |
| 299 | inner.AppendBool(false) |
| 300 | return nil |
| 301 | })) |
| 302 | assert.NoError(t, err) |
| 303 | }, |
| 304 | expected: []interface{}{true, false}, |
| 305 | }, |
| 306 | { |
| 307 | desc: "object (no nested namespace) then string", |
| 308 | f: func(e ArrayEncoder) { |
| 309 | err := e.AppendArray(ArrayMarshalerFunc(func(inner ArrayEncoder) error { |
| 310 | err := inner.AppendObject(maybeNamespace{false}) |
| 311 | inner.AppendString("should-be-outside-obj") |
| 312 | return err |
| 313 | })) |
| 314 | assert.NoError(t, err) |
| 315 | }, |
| 316 | expected: []interface{}{ |
nothing calls this directly
no test coverage detected