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

Feature Request: TrimEquals, compare strings trimming leading whitespace #819

Open
keyneston opened this issue Sep 12, 2019 · 0 comments

Comments

@keyneston
Copy link

commented Sep 12, 2019

I often will write code like:

func TestThing(t *testing.T) {
    expected := `
this
is a
multiline string
`

   actual := myFun()
   assert.Equal(t, strings.Trim(expected), strings.Trim(actual))
}

I was writing it enough that I ended up writing a helper function:

func trimAndEqual(t *testing.T, expected string, actual string, stuff ...interface{}) {
	assert.Equal(t,
		strings.TrimSpace(expected),
		strings.TrimSpace(actual),
		stuff...,
	)
}

It would be nice if a similar function existed natively in testify. Even nicer is if it handled not just stripping leading/trailing whitespace, but also would handle cases where your code ends up being formatted like:

    a := `this is
    a multiline
    string
`

Where you end up with leading whitespace on each line of the multiline string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.