Repository navigation
Expand file tree
/
Copy pathbuffer.go
More file actions
81 lines (72 loc) · 1.68 KB
/
Copy pathbuffer.go
File metadata and controls
81 lines (72 loc) · 1.68 KB
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
79
80
81
package gunit
import (
"bytes"
"strings"
)
func Buffer(t T, actual *bytes.Buffer) *Buf {
return &Buf{T: t, actual: actual}
}
type Buf struct {
T
actual *bytes.Buffer
}
func (b *Buf) EqualToString(expected string) {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted string <%s>", expected)
return
}
if b.actual.String() != expected {
b.Errorf("got buffer string <%s>, wanted <%s>", b.actual.String(), expected)
}
}
func (b *Buf) ContainsString(expected string) {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted substring <%s>", expected)
return
}
if !strings.Contains(b.actual.String(), expected) {
b.Errorf("got buffer string <%s>, wanted substring <%s>", b.actual.String(), expected)
}
}
func (b *Buf) EqualToBytes(expected []byte) {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted bytes <%v>", expected)
return
}
if !bytes.Equal(b.actual.Bytes(), expected) {
b.Errorf("got buffer bytes <%v>, wanted <%v>", b.actual.Bytes(), expected)
}
}
func (b *Buf) Len(expected int) {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted len()=%d", expected)
return
}
if b.actual.Len() != expected {
b.Errorf("got buffer len()=%d, wanted %d", b.actual.Len(), expected)
}
}
func (b *Buf) IsEmpty() {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted empty buffer")
return
}
if b.actual.Len() != 0 {
b.Errorf("got buffer len()=%d, wanted empty buffer", b.actual.Len())
}
}
func (b *Buf) IsNotEmpty() {
b.Helper()
if b.actual == nil {
b.Errorf("got nil buffer, wanted non-empty buffer")
return
}
if b.actual.Len() == 0 {
b.Errorf("got empty buffer, wanted non-empty buffer")
}
}