Skip to content

Support ignoring line ending format when comparing strings #4975

Description

@Bartleby2718

Context

When you compare multi-line strings in NUnit test code, you often need to normalize line endings beforehand. A simple .Replace() will do, but:

  1. it's annoying to put it everywhere.
  2. the string replacement causes unnecessary memory allocations even when the string doesn't contain any newlines.

Proposal

A more user-friendly option would be handle this at the framework level, similar to the IgnoreCase modifier or the IgnoreWhiteSpace modifier which exist for some constraints.

Example

[Test]
public void TestIgnoringLineEndingFormat(string actual)
{
    const string expected = """
        multi-line
        raw
        string
        literal
        """;
    Assert.That(actual, Is.EqualTo(expected).IgnoreLineEndingFormat);
}

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions