You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: include missing or superfluous whitespace in message (#109)
When two strings only differ in whitespace or length, the difference is
now included in the failure message.
- Whitespace is escaped so that it is displayed as `\t`, `\n` or `\r`
- The displayed string is limited to 100 characters
*fixes#106*
return$"{prefix} which has unexpected whitespace at the beginning";
172
+
return
173
+
$"{prefix} which has unexpected whitespace (\"{actual.Substring(0,GetIndexOfFirstMatch(actual,pattern,comparer)).DisplayWhitespace().TruncateWithEllipsis(100)}\" at the beginning)";
173
174
}
174
175
175
176
if(stringDifference.IndexOfFirstMismatch==0&&
176
177
comparer.Equals(actual,pattern.TrimStart()))
177
178
{
178
-
return$"{prefix} which misses some whitespace at the beginning";
179
+
return
180
+
$"{prefix} which misses some whitespace (\"{pattern.Substring(0,GetIndexOfFirstMatch(pattern,actual,comparer)).DisplayWhitespace().TruncateWithEllipsis(100)}\" at the beginning)";
return$"{prefix} which has unexpected whitespace at the end";
186
+
return
187
+
$"{prefix} which has unexpected whitespace (\"{actual.Substring(stringDifference.IndexOfFirstMismatch).DisplayWhitespace().TruncateWithEllipsis(100)}\" at the end)";
return$"{prefix} which misses some whitespace at the end";
191
-
}
192
-
193
-
if(comparer.Equals(actual.Trim(),pattern.Trim()))
194
-
{
195
-
return$"{prefix} which differs in whitespace";
193
+
return
194
+
$"{prefix} which misses some whitespace (\"{pattern.Substring(stringDifference.IndexOfFirstMismatch).DisplayWhitespace().TruncateWithEllipsis(100)}\" at the end)";
$"{prefix} with a length of {actual.Length} which is shorter than the expected length of {pattern.Length}";
201
+
$"{prefix} with a length of {actual.Length} which is shorter than the expected length of {pattern.Length} and misses:{Environment.NewLine}\"{pattern.Substring(actual.Length).TruncateWithEllipsis(100)}\"";
$"{prefix} with a length of {actual.Length} which is longer than the expected length of {pattern.Length}";
208
+
$"{prefix} with a length of {actual.Length} which is longer than the expected length of {pattern.Length} and has superfluous:{Environment.NewLine}\"{actual.Substring(pattern.Length).TruncateWithEllipsis(100)}\"";
210
209
}
211
210
212
211
return$"{prefix} which {newStringDifference(actual,pattern,comparer)}";
0 commit comments