Created
April 25, 2013 09:25
-
-
Save wellle/5458580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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