2015-12-02 09:27:18 -05:00
|
|
|
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.
|
2015-12-02 09:27:18 -05:00
|
|
|
func Bool(value bool) *BoolSubject {
|
|
|
|
return &BoolSubject{value: value}
|
2015-09-16 11:29:00 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 09:27:18 -05: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)
|
|
|
|
}
|
|
|
|
}
|