...

Source file src/github.com/jackc/pgio/write_test.go

Documentation: github.com/jackc/pgio

     1  package pgio
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestAppendUint16NilBuf(t *testing.T) {
     9  	buf := AppendUint16(nil, 1)
    10  	if !reflect.DeepEqual(buf, []byte{0, 1}) {
    11  		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
    12  	}
    13  }
    14  
    15  func TestAppendUint16EmptyBuf(t *testing.T) {
    16  	buf := []byte{}
    17  	buf = AppendUint16(buf, 1)
    18  	if !reflect.DeepEqual(buf, []byte{0, 1}) {
    19  		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
    20  	}
    21  }
    22  
    23  func TestAppendUint16BufWithCapacityDoesNotAllocate(t *testing.T) {
    24  	buf := make([]byte, 0, 4)
    25  	AppendUint16(buf, 1)
    26  	buf = buf[0:2]
    27  	if !reflect.DeepEqual(buf, []byte{0, 1}) {
    28  		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
    29  	}
    30  }
    31  
    32  func TestAppendUint32NilBuf(t *testing.T) {
    33  	buf := AppendUint32(nil, 1)
    34  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
    35  		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
    36  	}
    37  }
    38  
    39  func TestAppendUint32EmptyBuf(t *testing.T) {
    40  	buf := []byte{}
    41  	buf = AppendUint32(buf, 1)
    42  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
    43  		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
    44  	}
    45  }
    46  
    47  func TestAppendUint32BufWithCapacityDoesNotAllocate(t *testing.T) {
    48  	buf := make([]byte, 0, 4)
    49  	AppendUint32(buf, 1)
    50  	buf = buf[0:4]
    51  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
    52  		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
    53  	}
    54  }
    55  
    56  func TestAppendUint64NilBuf(t *testing.T) {
    57  	buf := AppendUint64(nil, 1)
    58  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
    59  		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
    60  	}
    61  }
    62  
    63  func TestAppendUint64EmptyBuf(t *testing.T) {
    64  	buf := []byte{}
    65  	buf = AppendUint64(buf, 1)
    66  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
    67  		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
    68  	}
    69  }
    70  
    71  func TestAppendUint64BufWithCapacityDoesNotAllocate(t *testing.T) {
    72  	buf := make([]byte, 0, 8)
    73  	AppendUint64(buf, 1)
    74  	buf = buf[0:8]
    75  	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
    76  		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
    77  	}
    78  }
    79  

View as plain text