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

Function samePointers

assert/assertions.go:584–597  ·  view source on GitHub ↗

samePointers checks if two generic interface objects are pointers of the same type pointing to the same object. It returns two values: same indicating if they are the same type and point to the same object, and ok indicating that both inputs are pointers.

(first, second interface{})

Source from the content-addressed store, hash-verified

582// they are the same type and point to the same object, and ok indicating that
583// both inputs are pointers.
584func samePointers(first, second interface{}) (same bool, ok bool) {
585 firstPtr, secondPtr := reflect.ValueOf(first), reflect.ValueOf(second)
586 if firstPtr.Kind() != reflect.Ptr || secondPtr.Kind() != reflect.Ptr {
587 return false, false // not both are pointers
588 }
589
590 firstType, secondType := reflect.TypeOf(first), reflect.TypeOf(second)
591 if firstType != secondType {
592 return false, true // both are pointers, but of different types
593 }
594
595 // compare pointer addresses
596 return first == second, true
597}
598
599// formatUnequalValues takes two values of arbitrary types and returns string
600// representations appropriate to be presented to the user.

Callers 3

Test_samePointersFunction · 0.85
SameFunction · 0.85
NotSameFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_samePointersFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…