1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/testing/assert/boolsubject.go

50 lines
1.0 KiB
Go
Raw Normal View History

package assert
2015-09-16 11:29:00 -04:00
import (
"strconv"
)
2015-12-03 09:18:43 -05:00
// Assert on a boolean variable.
func Bool(value bool) *BoolSubject {
return &BoolSubject{value: value}
2015-09-16 11:29:00 -04:00
}
type BoolSubject struct {
Subject
value bool
2015-09-16 11:29:00 -04:00
}
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))
}
2015-12-03 09:18:43 -05:00
// to be equal to another boolean variable.
2015-09-16 11:29:00 -04:00
func (subject *BoolSubject) Equals(expectation bool) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
2015-12-03 09:18:43 -05:00
// to be true.
2015-09-16 11:29:00 -04:00
func (subject *BoolSubject) IsTrue() {
if subject.value != true {
subject.Fail("is", true)
}
}
2015-12-03 09:18:43 -05:00
// to be false.
2015-09-16 11:29:00 -04:00
func (subject *BoolSubject) IsFalse() {
if subject.value != false {
subject.Fail("is", false)
}
}