be_empty_matcher.go 664 B

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