Skip to content

String comparison without whitespace #3918

@Crown0815

Description

@Crown0815

In some situations a string comparison without taking whitespace into account is desirable.

A use-case would be JSON string comparison, which should be whitespace agnostic but requires perfect whitespace matching when using the EqualConstraint.

Current solution to the issue

To avoid this issue I have to write

Assert.That(resultingJsonString.WithoutWhitespace(), Is.EqualTo(expectedJsonString.WithoutWhitespace()));

where WithoutWhitespace() is an extension method removing all whitespace characters.

Prefered syntax

It would be more fluent to write

Assert.That(resultingJsonString, Is.EqualTo(expectedJsonString).IgnoreWhitespace));

IgnoreWhitespace was inspired by the existing IgnoreCase configuration.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions