Exemple #1
0
// ExpectNe(e, a) is equivalent to
// ExpectThat(a, oglematchers.Not(oglematchers.Equals(e))).
func ExpectNe(expected, actual interface{}, errorParts ...interface{}) {
	expectThat(
		actual,
		oglematchers.Not(oglematchers.Equals(expected)),
		1,
		errorParts)
}
// AssertEq(e, a) is equivalent to AssertThat(a, oglematchers.Equals(e)).
func AssertEq(expected, actual interface{}, errorParts ...interface{}) {
	assertThat(
		actual,
		oglematchers.Equals(expected),
		1,
		errorParts)
}
// InternalNewExpectation is exported for purposes of testing only. You should
// not touch it.
func InternalNewExpectation(
	reporter ErrorReporter,
	methodSignature reflect.Type,
	args []interface{},
	fileName string,
	lineNumber int) *InternalExpectation {
	result := &InternalExpectation{}

	// Store fields that can be stored directly.
	result.methodSignature = methodSignature
	result.errorReporter = reporter
	result.FileName = fileName
	result.LineNumber = lineNumber

	// Set up defaults.
	result.ExpectedNumMatches = -1
	result.OneTimeActions = make([]Action, 0)

	// Set up the ArgMatchers slice, using Equals(x) for each x that is not a
	// matcher itself.
	result.ArgMatchers = make([]oglematchers.Matcher, len(args))
	for i, x := range args {
		if matcher, ok := x.(oglematchers.Matcher); ok {
			result.ArgMatchers[i] = matcher
		} else {
			result.ArgMatchers[i] = oglematchers.Equals(x)
		}
	}

	return result
}
Exemple #4
0
// AssertNe(e, a) is equivalent to AssertThat(a, oglematchers.Not(oglematchers.Equals(e))).
func AssertNe(expected, actual interface{}, errorParts ...interface{}) ExpectationResult {
	res := ExpectThat(actual, oglematchers.Not(oglematchers.Equals(expected)), errorParts...)
	res.SetCaller(getCallerForAlias())

	matcherErr := res.MatchResult()
	if matcherErr != nil {
		panic(&assertThatError{})
	}

	return res
}
Exemple #5
0
// AssertFalse(b) is equivalent to AssertThat(b, oglematchers.Equals(false)).
func AssertFalse(b interface{}, errorParts ...interface{}) ExpectationResult {
	res := ExpectThat(b, oglematchers.Equals(false), errorParts...)
	res.SetCaller(getCallerForAlias())

	matcherErr := res.MatchResult()
	if matcherErr != nil {
		panic(&assertThatError{})
	}

	return res
}
Exemple #6
0
func shouldEqual(actual, expected interface{}) (message string) {
	defer func() {
		if r := recover(); r != nil {
			message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual))
			return
		}
	}()

	if matchError := oglematchers.Equals(expected).Matches(actual); matchError != nil {
		message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual))
		return
	}

	return success
}
Exemple #7
0
func shouldEqual(actual, expected interface{}) (message string) {
	defer func() {
		if r := recover(); r != nil {
			message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual))
			return
		}
	}()

	if matchError := oglematchers.Equals(expected).Matches(actual); matchError != nil {
		expectedSyntax := fmt.Sprintf("%v", expected)
		actualSyntax := fmt.Sprintf("%v", actual)
		if expectedSyntax == actualSyntax && reflect.TypeOf(expected) != reflect.TypeOf(actual) {
			message = fmt.Sprintf(shouldHaveBeenEqualTypeMismatch, expected, expected, actual, actual)
		} else {
			message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual)
		}
		message = serializer.serialize(expected, actual, message)
		return
	}

	return success
}
Exemple #8
0
// ExpectFalse(b) is equivalent to ExpectThat(b, oglematchers.Equals(false)).
func ExpectFalse(b interface{}, errorParts ...interface{}) {
	expectThat(b, oglematchers.Equals(false), 1, errorParts)
}
Exemple #9
0
// ExpectFalse(b) is equivalent to ExpectThat(b, oglematchers.Equals(false)).
func ExpectFalse(b interface{}, errorParts ...interface{}) ExpectationResult {
	res := ExpectThat(b, oglematchers.Equals(false), errorParts...)
	res.SetCaller(getCallerForAlias())
	return res
}
Exemple #10
0
// ExpectNe(e, a) is equivalent to ExpectThat(a, oglematchers.Not(oglematchers.Equals(e))).
func ExpectNe(expected, actual interface{}, errorParts ...interface{}) ExpectationResult {
	res := ExpectThat(actual, oglematchers.Not(oglematchers.Equals(expected)), errorParts...)
	res.SetCaller(getCallerForAlias())
	return res
}
// AssertFalse(b) is equivalent to AssertThat(b, oglematchers.Equals(false)).
func AssertFalse(b interface{}, errorParts ...interface{}) {
	assertThat(b, oglematchers.Equals(false), 1, errorParts)
}