forked from CIP-NL/waldorf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assertions.go
72 lines (64 loc) · 2.61 KB
/
assertions.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
// Package waldorf implements a simple checking framework for doing multiple assertions and collecting the
// result of the assertions. Waldorf does not use interfaces but instead relies on the user providing statements
// which evaluate to booleans, making it typed as opposed to the assertions library by stretchr.
package waldorf
func (r *Observation) ShouldBeTrue(statement bool, msg string, formatting ...interface{}) (validated bool) {
if !statement {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return statement
}
func (r *Observation) ShouldBeFalse(statement bool, msg string, formatting ...interface{}) (validated bool) {
if statement {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return !statement
}
func (r *Observation) EitherShouldBeTrue(statementOne, statementTwo bool, msg string, formatting ...interface{}) (validated bool) {
if !(statementOne || statementTwo) {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return statementOne || statementTwo
}
func (r *Observation) BothShouldBeTrue(statementOne, statementTwo bool, msg string, formatting ...interface{}) (validated bool) {
if !(statementOne && statementTwo) {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return statementOne && statementTwo
}
func (r *Observation) BothShouldBeFalse(statementOne, statementTwo bool, msg string, formatting ...interface{}) (validated bool) {
if statementOne || statementTwo {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return !(statementOne || statementTwo)
}
func (r *Observation) EitherNeither(statementOne, statementTwo bool, msg string, formatting ...interface{}) (validated bool) {
if statementOne && statementTwo {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
}
return !(statementOne && statementTwo)
}
func (r *Observation) IfThisThenThat(statementOne, statementTwo bool, msg string, formatting ...interface{}) (validated bool) {
if !statementOne {
return true
}
if !statementTwo {
r.complaintsMu.Lock()
defer r.complaintsMu.Unlock()
r.complaints.comps = append(r.complaints.comps, generateMSG(msg, formatting...))
return false
}
return true
}