...

Source file src/github.com/rs/zerolog/array_test.go

Documentation: github.com/rs/zerolog

     1  package zerolog
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestArray(t *testing.T) {
    10  	a := Arr().
    11  		Bool(true).
    12  		Int(1).
    13  		Int8(2).
    14  		Int16(3).
    15  		Int32(4).
    16  		Int64(5).
    17  		Uint(6).
    18  		Uint8(7).
    19  		Uint16(8).
    20  		Uint32(9).
    21  		Uint64(10).
    22  		Float32(11.98122).
    23  		Float64(12.987654321).
    24  		Str("a").
    25  		Bytes([]byte("b")).
    26  		Hex([]byte{0x1f}).
    27  		RawJSON([]byte(`{"some":"json"}`)).
    28  		Time(time.Time{}).
    29  		IPAddr(net.IP{192, 168, 0, 10}).
    30  		Dur(0).
    31  		Dict(Dict().
    32  			Str("bar", "baz").
    33  			Int("n", 1),
    34  		)
    35  	want := `[true,1,2,3,4,5,6,7,8,9,10,11.98122,12.987654321,"a","b","1f",{"some":"json"},"0001-01-01T00:00:00Z","192.168.0.10",0,{"bar":"baz","n":1}]`
    36  	if got := decodeObjectToStr(a.write([]byte{})); got != want {
    37  		t.Errorf("Array.write()\ngot:  %s\nwant: %s", got, want)
    38  	}
    39  }
    40  

View as plain text