Skip to content
Discussion options

You must be logged in to vote

@tturbs

Comparing map pointers

What you mentioned focuses on comparing the keys and values within a map, but I'm wondering—wouldn't it still be possible to compare the map references themselves? If two maps share the same reference, I believe it's reasonable to consider them the same.

In the sense of SameMaps doing the pointer check a la:

func SameMap(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}

	samePtr, ok := sameMaps(expected, actual)
	if !ok {
		return Fail(t, "Both arguments must be maps", msgAndArgs...)
	}

	if !samePtr {
		return Fail(t, "Maps point to different data" +
		"expected: %#[1]p %#[1]v\n"+
		"…

Replies: 3 comments 10 replies

Comment options

You must be logged in to vote
4 replies
@Michael0x2a
Comment options

@brackendawson
Comment options

@Michael0x2a
Comment options

@brackendawson
Comment options

Comment options

You must be logged in to vote
3 replies
@brackendawson
Comment options

@breadnette
Comment options

@breadnette
Comment options

Comment options

You must be logged in to vote
3 replies
@tturbs
Comment options

@breadnette
Comment options

Answer selected by tturbs
@tturbs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants