be_empty_matcher.go 689 B

123456789101112131415161718192021222324252627282930
  1. // untested sections: 2
  2. package matchers
  3. import (
  4. "fmt"
  5. "github.com/onsi/gomega/format"
  6. )
  7. type BeEmptyMatcher struct {
  8. }
  9. func (matcher *BeEmptyMatcher) Match(actual interface{}) (success bool, err error) {
  10. length, ok := lengthOf(actual)
  11. if !ok {
  12. return false, fmt.Errorf("BeEmpty matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1))
  13. }
  14. return length == 0, nil
  15. }
  16. func (matcher *BeEmptyMatcher) FailureMessage(actual interface{}) (message string) {
  17. return format.Message(actual, "to be empty")
  18. }
  19. func (matcher *BeEmptyMatcher) NegatedFailureMessage(actual interface{}) (message string) {
  20. return format.Message(actual, "not to be empty")
  21. }