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: make a version from string BeEquivalentTo which ignores \n <> \r\n #1247

Open
StefH opened this issue Feb 8, 2020 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation feature

Comments

@StefH
Copy link

StefH commented Feb 8, 2020

Description

The currentBeEquivalentTo() method asserts that a string is exactly the same as another string, including any leading or trailing whitespace, with the exception of the casing.

It would be very useful to add a new method or extend this method to support also \n and \r\n.

Complete minimal example reproducing the issue

// Arrange
string expected= "foo\r\n";

// Act
string result = "foo\n";

// Assert
result.Should().BeEquivalentTo(expected);

Expected behavior:

Assertion is OK

Actual behavior:

Assertion FAILS

Versions

  • Latest version
@markusschaber
Copy link

We could also use this.

Workaround: use .Replace("\r\n","\n") on the strings in question before comparing.

@dennisdoomen dennisdoomen added feature api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jul 31, 2023
@jamesSampica
Copy link

This would be very useful when writing tests that are expected to pass cross-platform

@dennisdoomen
Copy link
Member

This is very similar to what is suggested here #2339 (comment)

@riezebosch
Copy link

We could also use this.

Workaround: use .Replace("\r\n","\n") on the strings in question before comparing.

Was about to do this workaround an then I found out about this extension method I hadn't seen before: https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-8.0 🥳

and it really is working for me (though I still would favour a more generic solution):

exception
    .Message
    .Should()
    .Be("""
        expectations not met
        Matched:
        * 1
        * null
        Unmatched:
           <none>
        """.ReplaceLineEndings());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation feature
Projects
None yet
Development

No branches or pull requests

5 participants