1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-20 20:24:15 -04:00
v2fly/testing/assert/boolsubject.go
2015-12-03 15:18:43 +01:00

50 lines
1.0 KiB
Go

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)
}
}