Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add StructEqual() for verifying Equal method of structs #109

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

shoenig
Copy link
Owner

@shoenig shoenig commented Mar 3, 2023

This PR adds StructEqual which is helpful for verifying that modifying
the fields of a struct will cause its Equal method of the struct to
no longer return true.

e.g. usage

func TestAffinity_Equal(t *testing.T) {
	must.Equal[*Affinity](t, nil, nil)
	must.NotEqual[*Affinity](t, nil, new(Affinity))
	must.StructEqual(t, &Affinity{
		LTarget: "left",
		RTarget: "right",
		Operand: "op",
		Weight:  100,
	}, []must.Tweak[*Affinity]{{
		Field: "LTarget",
		Apply: func(a *Affinity) { a.LTarget = "left2" },
	}, {
		Field: "RTarget",
		Apply: func(a *Affinity) { a.RTarget = "right2" },
	}, {
		Field: "Operand",
		Apply: func(a *Affinity) { a.Operand = "op2" },
	}, {
		Field: "Weight",
		Apply: func(a *Affinity) { a.Weight = 50 },
	}})
}

This PR adds StructEqual which is helpful for verifying that modifying
the fields of a struct will cause the Equal method of the struct to
no longer return true.
@shoenig shoenig force-pushed the struct-equal-func branch from 9ea25a7 to 79af6e7 Compare March 3, 2023 21:44
@shoenig shoenig marked this pull request as ready for review March 3, 2023 21:49
@shoenig shoenig merged commit 23af83e into main Mar 3, 2023
@shoenig shoenig deleted the struct-equal-func branch December 15, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant