-
Notifications
You must be signed in to change notification settings - Fork 0
/
int.go
101 lines (80 loc) · 2.48 KB
/
int.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package tort
import (
"fmt"
"reflect"
"strconv"
)
// Code generated from templates/ints.tmpl; DO NOT EDIT.
// IntAssertions are tests around integer (int) values.
type IntAssertions struct {
Assertions
name string
num int
}
// Int identifies an integer variable value and returns test functions for its values.
func (assert Assertions) Int(value int) IntAssertions {
assert.t.Helper()
return IntAssertions{
Assertions: assert,
name: "int",
num: value,
}
}
// Int looks for the given struct field, confirms it's an int, and returns the assertions valid for
// the integer.
func (assert StructAssertions) Int(field string) IntAssertions {
assert.t.Helper()
name := fmt.Sprintf("%s.%s", assert.Type(), field)
property := assert.Field(field)
if property.Kind() != reflect.Int {
assert.Fatal("field %s is not an int", name)
}
return IntAssertions{
Assertions: assert.Assertions,
name: name,
num: int(property.Int()),
}
}
// Int looks for the given slice element, confirms it's an int, and returns the assertions valid for
// the integer.
func (assert SliceAssertions) Int(idx int) IntAssertions {
assert.t.Helper()
name := strconv.Itoa(idx)
property := assert.Element(idx)
if property.Kind() != reflect.Int {
assert.Fatal("element %d is not an int", idx)
}
return IntAssertions{
Assertions: assert.Assertions,
name: name,
num: int(property.Int()),
}
}
// Equals generates an error if the integer value isn't the same as other.
func (assert IntAssertions) Equals(other int) {
assert.t.Helper()
if assert.num != other {
assert.Failed(`expected %s to be %d, but it was %d`, assert.name, other, assert.num)
}
}
// Equals generates an error if the integer value is the same as the other.
func (assert IntAssertions) NotEquals(other int) {
assert.t.Helper()
if assert.num == other {
assert.Failed(`expected %s to not be %d`, assert.name, other)
}
}
// GreaterThan generates an error if the integer value is less than or equal to the other.
func (assert IntAssertions) GreaterThan(other int) {
assert.t.Helper()
if assert.num <= other {
assert.Failed(`expected %s to be greater than %d, but it was %d`, assert.name, other, assert.num)
}
}
// LessThan generates an error if the integer value is greater than or equal to the other.
func (assert IntAssertions) LessThan(other int) {
assert.t.Helper()
if assert.num >= other {
assert.Failed(`expected %s to be less than %d, but it was %d`, assert.name, other, assert.num)
}
}