JavaHamcrest
JavaHamcrest copied to clipboard
Specify which whitespace definition is used for matchers
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.
This is a good point.
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){}.
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).
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
ifstatements (which should be aswitchanyway).
Thank you. I will have a try.