Assertj-core: StringAssert: add variants with "Ignoring"

Created on 4 Dec 2020  路  12Comments  路  Source: assertj/assertj-core

Summary

Currently the AbstractCharSequenceAssert has a method containsIgnoringCase(...). It would appreciable to have the same variants as the isEqualToIgnoring.... So:

  • containsIgnoringWhitespaces(CharSequence sequence)
  • containsIgnoringNewLines(CharSequence sequence)

Example

assertThat("gandalf is a \r\nwizard").containsIgnoringNewLines("gandalf is a wizard") // SUCCESS
assertThat("gandalf is a wizard").containsIgnoringNewLines("gandalf is a \nwizard") // SUCCESS

All 12 comments

Fair enough, @beckerjohannes keen to contribute?

I'll check if I can squeeze in some free "sofa time" soon to create a PR. Should be an easy fix.

I minor suggestion: how about "containsPhrase()" as a slightly more readable (though slightly less descriptive) alternative?

@joel-costigliola you can assign that one to me. I'll think I will do it over the holidays. Might be a good pastime during the lockdown ;-)

@joel-costigliola you can assign that one to me. I'll think I will do it over the holidays. Might be a good pastime during the lockdown ;-)

Thanks for helping @beckerjohannes 馃檪

how about "containsPhrase()" as a slightly more readable (though slightly less descriptive) alternative?

I like it, let's see what @joel-costigliola thinks about it.

I guess your proposal is for the "ignoring newlines" use case only. What about the "ignoring whitespaces" use case? Any thoughts?

@scordio to keep it consistent I thought about those variants, but I have to take a look at the details. Personally the ignoring/normalizing newlines & whitespaces would the ones I'm interested in:
image

Uhm maybe it's not worth coming up with a new naming pattern for this change, reusing the existing one simplifies the discovery of the new assertions.

containsIgnoring / containsNormalizing is probably a good compromise for the time being.

I prefer reusing the existing pattern over containsPhrase which is not really obvious to me, the existing is verbose but more explicit so containsIgnoringNewLines, containsNormalizingNewLines, ...

@beckerjohannes I recommend you start with one assertion, we review it and then work on the next with the feedback of the first one in mind.

I prefer reusing the existing pattern over containsPhrase which is not really obvious to me, the existing is verbose but more explicit so containsIgnoringNewLines, containsNormalizingNewLines, ...

My thought was that containsPhrase() would have rules like in most natural language - differences in whitespace are not significant, only the words and their order are significant. In other words, it would be equivalent to containsNormalizingWhitespace(). While I thought this was neat and natural, it did leave open the question of what to do for ignoring new lines, ignoring whitespace, etc.

On the other hand, I do like consistency and I understand the attractiveness of reusing the existing pattern. Perhaps we could rename isEqualToNormalizingWhitespace() to "sSameAsPhrase()? :wink:

I find that everybody is going to interpret what a phrase is in its own way, that's why I prefer more explicit assertion names.

@beckerjohannes are you still interested/have time to contribute this?

@joel-costigliola Sorry, I lost track of that issue. Yes, I am still interested.

Was this page helpful?
0 / 5 - 0 ratings