Visitar URL original
Feature request: make a version from string BeEquivalentTo which ignores \n <> \r\n · Issue #1247 · fluentassertions/fluentassertions · GitHub
Skip to content

Feature request: make a version from string BeEquivalentTo which ignores \n <> \r\n #1247

Open

Description

@StefH

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

Activity

  1. markusschaber commented on Jul 31, 2023

    @markusschaber

    We could also use this.

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

  2. jimSampica commented on Oct 2, 2023

    @jimSampica

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

  3. dennisdoomen commented on Oct 4, 2023

    @dennisdoomen
    Member

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

  4. riezebosch commented on Dec 9, 2023

    @riezebosch

    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());
  5. vbreuss commented on Oct 26, 2024

    @vbreuss
    Contributor

    Isn't this issue fixed with #2565 and should be closed?

  6. Kryptos-FR commented on Dec 4, 2024

    @Kryptos-FR

    It's not released yet apparently. It was in the alpha version but not in the release.

  7. jnyrup commented on Dec 4, 2024

    @jnyrup
    Member

    It's not released yet apparently. It was in the alpha version but not in the release.

    See #2864 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions