File: write_test.go

package info (click to toggle)
golang-github-jackc-pgio 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 84 kB
  • sloc: makefile: 2
file content (78 lines) | stat: -rw-r--r-- 2,153 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pgio

import (
	"reflect"
	"testing"
)

func TestAppendUint16NilBuf(t *testing.T) {
	buf := AppendUint16(nil, 1)
	if !reflect.DeepEqual(buf, []byte{0, 1}) {
		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
	}
}

func TestAppendUint16EmptyBuf(t *testing.T) {
	buf := []byte{}
	buf = AppendUint16(buf, 1)
	if !reflect.DeepEqual(buf, []byte{0, 1}) {
		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
	}
}

func TestAppendUint16BufWithCapacityDoesNotAllocate(t *testing.T) {
	buf := make([]byte, 0, 4)
	AppendUint16(buf, 1)
	buf = buf[0:2]
	if !reflect.DeepEqual(buf, []byte{0, 1}) {
		t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1})
	}
}

func TestAppendUint32NilBuf(t *testing.T) {
	buf := AppendUint32(nil, 1)
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
	}
}

func TestAppendUint32EmptyBuf(t *testing.T) {
	buf := []byte{}
	buf = AppendUint32(buf, 1)
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
	}
}

func TestAppendUint32BufWithCapacityDoesNotAllocate(t *testing.T) {
	buf := make([]byte, 0, 4)
	AppendUint32(buf, 1)
	buf = buf[0:4]
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) {
		t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1})
	}
}

func TestAppendUint64NilBuf(t *testing.T) {
	buf := AppendUint64(nil, 1)
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
	}
}

func TestAppendUint64EmptyBuf(t *testing.T) {
	buf := []byte{}
	buf = AppendUint64(buf, 1)
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
	}
}

func TestAppendUint64BufWithCapacityDoesNotAllocate(t *testing.T) {
	buf := make([]byte, 0, 8)
	AppendUint64(buf, 1)
	buf = buf[0:8]
	if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) {
		t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1})
	}
}