File: assert.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 872 kB
  • sloc: makefile: 4
file content (63 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (2)
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
package expect // import "github.com/anacrolix/missinggo/expect"

import (
	"database/sql"
	"fmt"
	"reflect"
)

func Nil(x interface{}) {
	if x != nil {
		panic(fmt.Sprintf("expected nil; got %v", x))
	}
}

func NotNil(x interface{}) {
	if x == nil {
		panic(x)
	}
}

func Equal(x, y interface{}) {
	if x == y {
		return
	}
	yAsXType := reflect.ValueOf(y).Convert(reflect.TypeOf(x)).Interface()
	if !reflect.DeepEqual(x, yAsXType) {
		panic(fmt.Sprintf("%v != %v", x, y))
	}
}

func StrictlyEqual(x, y interface{}) {
	if x != y {
		panic(fmt.Sprintf("%s != %s", x, y))
	}
}

func OneRowAffected(r sql.Result) {
	count, err := r.RowsAffected()
	Nil(err)
	if count != 1 {
		panic(count)
	}
}

func True(b bool) {
	if !b {
		panic(b)
	}
}

var Ok = True

func False(b bool) {
	if b {
		panic(b)
	}
}

func Zero(x interface{}) {
	if x != reflect.Zero(reflect.TypeOf(x)).Interface() {
		panic(x)
	}
}