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

Add string-option for ignoring newline style #2612

Closed
jnyrup opened this issue Mar 23, 2024 · 2 comments · Fixed by #2565
Closed

Add string-option for ignoring newline style #2612

jnyrup opened this issue Mar 23, 2024 · 2 comments · Fixed by #2565
Labels
api-approved API was approved, it can be implemented

Comments

@jnyrup
Copy link
Member

jnyrup commented Mar 23, 2024

Background and motivation

Split of from #2496 to ease review.

Some operating systems (Windows) use \r\n as newlines while others (Unix-based) use \n.

In some text-based protocol it's well-defined which type of newline should be used and one would explicitly test that.

var subject = GetValue("a", "b");
subject.Should().Be("a\r\nb");

Manually specifying newlines in tests is cumbersome and easily becomes less readable.
So in all remaining tests we simply wants to test that some newline is used.
Instead of explicitly specifying the newline character

var subject = GetValue();
subject.Should().Be("some\r\nvalue");

it would be a nice to write the tests using verbatim string literals

var subject = GetValue();
subject.Should().BeEquivalentTo(@"some
value");

or even more readable with the C# 11 raw string literals

var subject = GetValue();
subject.Should().BeEquivalentTo("""
    some
    value
    """);

API Proposal

public EquivalencyAssertionOptions<T> IgnoringNewlineStyle()
{
    // This will replace "\r\n" with "\n" in actual and expected before comparison
    return this;
}

API Usage

var windows = "a\r\nb";
var linux = "a\nb"

windows.Should().BeEquivalentTo(linux, o => o.IgnoringNewlineStyle());

Alternative Designs

No response

Risks

No response

Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?

No

@jnyrup jnyrup added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 23, 2024
@jnyrup
Copy link
Member Author

jnyrup commented Mar 23, 2024

I'm good with this

@dennisdoomen
Copy link
Member

Me too

@dennisdoomen dennisdoomen added api-approved API was approved, it can be implemented and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved, it can be implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants