equalsIgnoringWhitespace method
Expects that the String
contains the same content as expected
,
ignoring differences in whitsepace.
All runs of whitespace characters are collapsed to a single space, and leading and traiilng whitespace are removed before comparison.
For example the following will succeed:
check(' hello world ').equalsIgnoringWhitespace('hello world');
While the following will fail:
check('helloworld').equalsIgnoringWhitespace('hello world');
check('he llo world').equalsIgnoringWhitespace('hello world');
Implementation
void equalsIgnoringWhitespace(String expected) {
context.expect(
() => prefixFirst('equals ignoring whitespace ', literal(expected)),
(actual) {
final collapsedActual = _collapseWhitespace(actual);
final collapsedExpected = _collapseWhitespace(expected);
return _findDifference(collapsedActual, collapsedExpected,
collapsedActual, collapsedExpected);
});
}