-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytes.go
43 lines (40 loc) · 903 Bytes
/
bytes.go
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
package assert
import (
"bytes"
"fmt"
"testing"
)
// BytesEqual asserts that b1 and b2 are equal.
// It uses [bytes.Equal] to compare the two byte slices.
//
//nolint:thelper // It's called below.
func BytesEqual(tb testing.TB, b1, b2 []byte, opts ...Option) bool {
ok := bytes.Equal(b1, b2)
if !ok {
tb.Helper()
Fail(
tb,
"bytes_equal",
fmt.Sprintf("not equal:\nb1 = %s\nb2 = %s", ValueStringer(b1), ValueStringer(b2)),
opts...,
)
}
return ok
}
// BytesNotEqual asserts that b1 and b2 are not equal.
// It uses [bytes.Equal] to compare the two byte slices.
//
//nolint:thelper // It's called below.
func BytesNotEqual(tb testing.TB, b1, b2 []byte, opts ...Option) bool {
ok := !bytes.Equal(b1, b2)
if !ok {
tb.Helper()
Fail(
tb,
"bytes_not_equal",
fmt.Sprintf("equal:\nb1 = %s\nb2 = %s", ValueStringer(b1), ValueStringer(b2)),
opts...,
)
}
return ok
}