-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassertions_test.go
122 lines (106 loc) · 3.76 KB
/
assertions_test.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import "testing"
func TestEqualsAssertion(t *testing.T) {
type testCase struct {
Value interface{}
Comparison interface{}
Expected bool
}
cases := []testCase{
testCase{Value: "123", Comparison: 123, Expected: true},
testCase{Value: "123", Comparison: 124, Expected: false},
testCase{Value: 123, Comparison: 123, Expected: true},
testCase{Value: "the quick brown fox", Comparison: "the quick brown fox", Expected: true},
testCase{Value: "quick", Comparison: 421421, Expected: false},
testCase{Value: 123.4, Comparison: 123.4, Expected: true},
testCase{Value: 123.4, Comparison: 123.5, Expected: false},
}
for _, c := range cases {
err := checkAssertions(c.Value, map[string]interface{}{"equals": c.Comparison})
if (err == nil) != c.Expected {
t.Errorf("failed: expected %v == %v to have been %v; %v", c.Value, c.Comparison, c.Expected, err)
}
}
}
// TestLTAssertion tests the "less than" comparison rule
func TestLTAssertion(t *testing.T) {
type testCase struct {
Value interface{}
Comparison interface{}
Expected bool
}
cases := []testCase{
testCase{Value: "123", Comparison: 123, Expected: false},
testCase{Value: "123", Comparison: 124, Expected: true},
testCase{Value: 123, Comparison: 124, Expected: true},
testCase{Value: 123, Comparison: 122, Expected: false},
}
for _, c := range cases {
err := checkAssertions(c.Value, map[string]interface{}{"lt": c.Comparison})
if (err == nil) != c.Expected {
t.Errorf("failed: expected %v < %v to have been %v; %v", c.Value, c.Comparison, c.Expected, err)
}
}
}
// TestGTAssertion tests the "greater than" comparison rule
func TestGTAssertion(t *testing.T) {
type testCase struct {
Value interface{}
Comparison interface{}
Expected bool
}
cases := []testCase{
testCase{Value: "123", Comparison: 123, Expected: false},
testCase{Value: "123", Comparison: 124, Expected: false},
testCase{Value: 123, Comparison: 124, Expected: false},
testCase{Value: 123, Comparison: 122, Expected: true},
}
for _, c := range cases {
err := checkAssertions(c.Value, map[string]interface{}{"gt": c.Comparison})
if (err == nil) != c.Expected {
t.Errorf("failed: expected %v > %v to have been %v; %v", c.Value, c.Comparison, c.Expected, err)
}
}
}
// TestLEAssertion tests the "less than or equal to" comparison rule
func TestLEAssertion(t *testing.T) {
type testCase struct {
Value interface{}
Comparison interface{}
Expected bool
}
cases := []testCase{
testCase{Value: "123", Comparison: 123, Expected: true},
testCase{Value: "123", Comparison: 124, Expected: true},
testCase{Value: 123, Comparison: 124, Expected: true},
testCase{Value: 123, Comparison: 122, Expected: false},
testCase{Value: 123, Comparison: 123, Expected: true},
}
for _, c := range cases {
err := checkAssertions(c.Value, map[string]interface{}{"le": c.Comparison})
if (err == nil) != c.Expected {
t.Errorf("failed: expected %v <= %v to have been %v; %v", c.Value, c.Comparison, c.Expected, err)
}
}
}
// TestGEAssertion tests the "greater than or equal to" comparison rule
func TestGEAssertion(t *testing.T) {
type testCase struct {
Value interface{}
Comparison interface{}
Expected bool
}
cases := []testCase{
testCase{Value: "123", Comparison: 123, Expected: true},
testCase{Value: "123", Comparison: 124, Expected: false},
testCase{Value: 123, Comparison: 124, Expected: false},
testCase{Value: 123, Comparison: 122, Expected: true},
testCase{Value: 123, Comparison: 123, Expected: true},
}
for _, c := range cases {
err := checkAssertions(c.Value, map[string]interface{}{"ge": c.Comparison})
if (err == nil) != c.Expected {
t.Errorf("failed: expected %v >= %v to have been %v; %v", c.Value, c.Comparison, c.Expected, err)
}
}
}