-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassert.go
More file actions
54 lines (44 loc) · 738 Bytes
/
assert.go
File metadata and controls
54 lines (44 loc) · 738 Bytes
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
package assert
import (
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/k0kubun/pp/v3"
)
const Name = "assert"
func Assert(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
}
func MustEqual[T any](a, b T) {
if !cmp.Equal(a, b) {
_, _ = pp.Println("a: ", a)
_, _ = pp.Println("b: ", b)
must(fmt.Errorf("a,b not equal"))
}
}
func If(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
}
func T(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
}
func Err(b bool, err error) {
if b {
must(err)
}
}
func Fn(b bool, fn func() error) {
if b {
must(fn())
}
}
func Lazy(lazy func() bool, err error) {
if lazy() {
must(err)
}
}