forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboolsubject.go
49 lines (40 loc) · 1.01 KB
/
boolsubject.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
package assert
import (
"strconv"
)
// Assert on a boolean variable.
func Bool(value bool) *BoolSubject {
return &BoolSubject{value: value}
}
type BoolSubject struct {
Subject
value bool
}
func (subject *BoolSubject) Named(name string) *BoolSubject {
subject.Subject.Named(name)
return subject
}
func (subject *BoolSubject) Fail(verb string, other bool) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.FormatBool(other) + ">.")
}
func (subject *BoolSubject) DisplayString() string {
return subject.Subject.DisplayString(strconv.FormatBool(subject.value))
}
// to be equal to another boolean variable.
func (subject *BoolSubject) Equals(expectation bool) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
// to be true.
func (subject *BoolSubject) IsTrue() {
if subject.value != true {
subject.Fail("is", true)
}
}
// to be false.
func (subject *BoolSubject) IsFalse() {
if subject.value != false {
subject.Fail("is", false)
}
}