blob: 8b00311b0db1c8e0358a7e871e298a408c326955 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001package matchers
2
3import (
4 "fmt"
5
6 "github.com/onsi/gomega/format"
7)
8
9type BeEmptyMatcher struct {
10}
11
12func (matcher *BeEmptyMatcher) Match(actual interface{}) (success bool, err error) {
13 length, ok := lengthOf(actual)
14 if !ok {
15 return false, fmt.Errorf("BeEmpty matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1))
16 }
17
18 return length == 0, nil
19}
20
21func (matcher *BeEmptyMatcher) FailureMessage(actual interface{}) (message string) {
22 return format.Message(actual, "to be empty")
23}
24
25func (matcher *BeEmptyMatcher) NegatedFailureMessage(actual interface{}) (message string) {
26 return format.Message(actual, "not to be empty")
27}