Skip to content

Specify which whitespace definition is used for matchers #196

Open

Description

@krichter722

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.

Activity

  1. sf105 commented on Apr 3, 2018

    @sf105
    Member

    This is a good point.

  2. Harlan1997 commented on Apr 25, 2021

    @Harlan1997

    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){}.

  3. sf105 commented on Apr 25, 2021

    @sf105
    Member

    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).

  4. Harlan1997 commented on May 24, 2021

    @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).

    Thank you. I will have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions