MCPcopy
hub / github.com/stretchr/testify / TestEqual

Function TestEqual

assert/assertions_test.go:588–629  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

586}
587
588func TestEqual(t *testing.T) {
589 t.Parallel()
590
591 type myType string
592
593 mockT := new(testing.T)
594 var m map[string]interface{}
595
596 cases := []struct {
597 expected interface{}
598 actual interface{}
599 result bool
600 remark string
601 }{
602 {"Hello World", "Hello World", true, ""},
603 {123, 123, true, ""},
604 {123.5, 123.5, true, ""},
605 {[]byte("Hello World"), []byte("Hello World"), true, ""},
606 {nil, nil, true, ""},
607 {int32(123), int32(123), true, ""},
608 {uint64(123), uint64(123), true, ""},
609 {myType("1"), myType("1"), true, ""},
610 {&struct{}{}, &struct{}{}, true, "pointer equality is based on equality of underlying value"},
611
612 // Not expected to be equal
613 {m["bar"], "something", false, ""},
614 {myType("1"), myType("2"), false, ""},
615
616 // A case that might be confusing, especially with numeric literals
617 {10, uint(10), false, ""},
618 }
619
620 for _, c := range cases {
621 t.Run(fmt.Sprintf("Equal(%#v, %#v)", c.expected, c.actual), func(t *testing.T) {
622 res := Equal(mockT, c.expected, c.actual)
623
624 if res != c.result {
625 t.Errorf("Equal(%#v, %#v) should return %#v: %s", c.expected, c.actual, c.result, c.remark)
626 }
627 })
628 }
629}
630
631func ptr(i int) *int {
632 return &i

Callers

nothing calls this directly

Calls 4

myTypeTypeAlias · 0.85
EqualFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected