Exemplo n.º 1
0
// 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)
}
Exemplo n.º 2
0
Arquivo: string.go Projeto: 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)
}
Exemplo n.º 3
0
Arquivo: string.go Projeto: 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)
}
Exemplo n.º 4
0
// 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
}
Exemplo n.º 5
0
// 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)
}