Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | package matchers |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/onsi/gomega/format" |
| 7 | ) |
| 8 | |
| 9 | type BeEmptyMatcher struct { |
| 10 | } |
| 11 | |
| 12 | func (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 | |
| 21 | func (matcher *BeEmptyMatcher) FailureMessage(actual interface{}) (message string) { |
| 22 | return format.Message(actual, "to be empty") |
| 23 | } |
| 24 | |
| 25 | func (matcher *BeEmptyMatcher) NegatedFailureMessage(actual interface{}) (message string) { |
| 26 | return format.Message(actual, "not to be empty") |
| 27 | } |