示例#1
0
文件: checker.go 项目: h12w/gspec
// Equal checks for the equality of contents and is tolerant of type differences.
func Equal(actual, expected interface{}, name string, skip int) error {
	if reflect.DeepEqual(actual, expected) {
		return nil
	}
	if fmt.Sprint(actual) == fmt.Sprint(expected) {
		return nil
	}
	return errors.Compare(actual, expected, "to equal", name, skip+1)
}
示例#2
0
文件: string.go 项目: h12w/gspec
// Contains checks if the actual value contains expected value.
func Contains(actual, expected interface{}, name string, skip int) error {
	a, e, err := checkStringType(actual, expected, skip+1)
	if err != nil {
		return err
	}
	if strings.Contains(a, e) {
		return nil
	}
	return ge.Compare(actual, expected, "to contain", name, skip+1)
}
示例#3
0
文件: string.go 项目: h12w/gspec
// HasSuffix checks if the actual value has a suffix of expected value.
func HasSuffix(actual, expected interface{}, name string, skip int) error {
	a, e, err := checkStringType(actual, expected, skip+1)
	if err != nil {
		return err
	}
	if strings.HasSuffix(a, e) {
		return nil
	}
	return ge.Compare(actual, expected, "to has the suffix of", name, skip+1)
}
示例#4
0
文件: checker.go 项目: h12w/gspec
// IsType checks if the actual value is of the same type as the expected value.
func IsType(actual, expected interface{}, name string, skip int) error {
	if reflect.TypeOf(actual) != reflect.TypeOf(expected) {
		return errors.Compare(actual, expected, "to have type of", name, skip+1)
	}
	return nil
}
示例#5
0
文件: checker.go 项目: h12w/gspec
// NotEqual is the reverse of Equal.
func NotEqual(actual, expected interface{}, name string, skip int) error {
	if Equal(actual, expected, name, skip+1) != nil {
		return nil
	}
	return errors.Compare(actual, expected, "not to equal", name, skip+1)
}