github.com/onsi/gomega@v1.32.0/matchers/be_true_matcher.go (about) 1 // untested sections: 2 2 3 package matchers 4 5 import ( 6 "fmt" 7 8 "github.com/onsi/gomega/format" 9 ) 10 11 type BeTrueMatcher struct { 12 Reason string 13 } 14 15 func (matcher *BeTrueMatcher) Match(actual interface{}) (success bool, err error) { 16 if !isBool(actual) { 17 return false, fmt.Errorf("Expected a boolean. Got:\n%s", format.Object(actual, 1)) 18 } 19 20 return actual.(bool), nil 21 } 22 23 func (matcher *BeTrueMatcher) FailureMessage(actual interface{}) (message string) { 24 if matcher.Reason == "" { 25 return format.Message(actual, "to be true") 26 } else { 27 return matcher.Reason 28 } 29 } 30 31 func (matcher *BeTrueMatcher) NegatedFailureMessage(actual interface{}) (message string) { 32 if matcher.Reason == "" { 33 return format.Message(actual, "not to be true") 34 } else { 35 return fmt.Sprintf(`Expected not true but got true\nNegation of "%s" failed`, matcher.Reason) 36 } 37 }