Ejemplo n.º 1
0
func DiffValues(a, b interface{}) string {
	printer := colour.String()
	diff := diffmatchpatch.New()
	at := repr.String(a, repr.OmitEmpty())
	bt := repr.String(b, repr.OmitEmpty())
	diffs := diff.DiffMain(at, bt, true)
	for _, d := range diffs {
		switch d.Type {
		case diffmatchpatch.DiffEqual:
			if len(d.Text) <= 40 {
				printer.Print(d.Text)
			} else {
				printer.Printf("%s^B...^R%s", d.Text[:15], d.Text[len(d.Text)-15:])
			}
		case diffmatchpatch.DiffDelete:
			printer.Printf("^9%s^R", d.Text)
		case diffmatchpatch.DiffInsert:
			printer.Printf("^a%s^R", d.Text)
		}
	}
	return printer.String()
}
Ejemplo n.º 2
0
// NotEqual asserts that the specified values are NOT equal.
//
//    assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) {

	if ObjectsAreEqual(expected, actual) {
		Fail(t, fmt.Sprintf("Should not be: %s\n", repr.String(actual, repr.OmitEmpty())), msgAndArgs...)
	}
}
Ejemplo n.º 3
0
// Nil asserts that the specified object is nil.
//
//    assert.Nil(t, err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
	if isNil(object) {
		return
	}
	Fail(t, fmt.Sprintf("Expected nil, but got: %s", repr.String(object, repr.OmitEmpty())), msgAndArgs...)
}