JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Specify which whitespace definition is used for matchers

Open krichter722 opened this issue 7 years ago • 4 comments

I'd be nice if matchers involving whitespace, like equalToCompressingWhiteSpace would expand on which whitespace definition is used since there're a lot of them out there. For instance, it's not even clear whether Hamcrest considers newline characters whitespace or not. Wikipedia mentions a unicode character property "WSpace=Y" which seems reasonable.

krichter722 avatar Mar 29 '18 14:03 krichter722

This is a good point.

sf105 avatar Apr 03 '18 10:04 sf105

This is a good point.

I would like to work with this issue. I have tried to expand equalToCompressingWhiteSpace by adding a property whiteSpaceType which is a enum type variable with 6 types of whitespace: space, tab, line feed, form feed, carriagereturn, mix(mix types above), and I modify the constructor and stripSpaces to strip string according to different types of whitespace. To prevent conflicts, I added 6 types of matcher generators, like public static Matcher<String> equalToCompressingSPACE(String expectedString){}.

Harlan1997 avatar Apr 25 '21 08:04 Harlan1997

Interesting point. Another option would be to introduce a policy object for the kind of white space to be stripped, that would allow new combinations. With the current approach, you could stash the regex in the enum value, which would avoid the chained if statements (which should be a switch anyway).

sf105 avatar Apr 25 '21 18:04 sf105

Interesting point. Another option would be to introduce a policy object for the kind of white space to be stripped, that would allow new combinations. With the current approach, you could stash the regex in the enum value, which would avoid the chained if statements (which should be a switch anyway).

Thank you. I will have a try.

Harlan1997 avatar May 24 '21 04:05 Harlan1997