greater_or_equal.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2011 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. import (
  17. "fmt"
  18. "reflect"
  19. )
  20. // GreaterOrEqual returns a matcher that matches integer, floating point, or
  21. // strings values v such that v >= x. Comparison is not defined between numeric
  22. // and string types, but is defined between all integer and floating point
  23. // types.
  24. //
  25. // x must itself be an integer, floating point, or string type; otherwise,
  26. // GreaterOrEqual will panic.
  27. func GreaterOrEqual(x interface{}) Matcher {
  28. desc := fmt.Sprintf("greater than or equal to %v", x)
  29. // Special case: make it clear that strings are strings.
  30. if reflect.TypeOf(x).Kind() == reflect.String {
  31. desc = fmt.Sprintf("greater than or equal to \"%s\"", x)
  32. }
  33. return transformDescription(Not(LessThan(x)), desc)
  34. }