new_matcher.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 Aaron Jacobs. All Rights Reserved.
  2. // Author: aaronjjacobs@gmail.com (Aaron Jacobs)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. package oglematchers
  16. // Create a matcher with the given description and predicate function, which
  17. // will be invoked to handle calls to Matchers.
  18. //
  19. // Using this constructor may be a convenience over defining your own type that
  20. // implements Matcher if you do not need any logic in your Description method.
  21. func NewMatcher(
  22. predicate func(interface{}) error,
  23. description string) Matcher {
  24. return &predicateMatcher{
  25. predicate: predicate,
  26. description: description,
  27. }
  28. }
  29. type predicateMatcher struct {
  30. predicate func(interface{}) error
  31. description string
  32. }
  33. func (pm *predicateMatcher) Matches(c interface{}) error {
  34. return pm.predicate(c)
  35. }
  36. func (pm *predicateMatcher) Description() string {
  37. return pm.description
  38. }