Skip to content

Instantly share code, notes, and snippets.

@wellle
Created April 25, 2013 09:25
Show Gist options
  • Save wellle/5458580 to your computer and use it in GitHub Desktop.
Save wellle/5458580 to your computer and use it in GitHub Desktop.
package main
import (
"launchpad.net/gocheck"
)
type containsChecker struct {
*gocheck.CheckerInfo
}
var Contains gocheck.Checker = &containsChecker{
&gocheck.CheckerInfo{Name: "Contains", Params: []string{"obtained", "expected"}},
}
func (checker *containsChecker) Check(params []interface{}, name []string) (result bool, err string) {
slice, ok := params[0].([]string)
if !ok {
return false, "obtained value must be a []string"
}
expected, ok := params[1].(string)
if !ok {
return false, "expected value must be a string"
}
for _, value := range slice {
if value == expected {
return true, ""
}
}
return false, "expected string not found in obtained array"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment