-
Notifications
You must be signed in to change notification settings - Fork 724
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
Issue3918 white space #4664
Issue3918 white space #4664
Conversation
f786669
to
cc452f8
Compare
Awesome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome work! Really like the changes in ConstraintExpression to the Append method, making it generic fix the typecasting that is all over the other constraints. Very good!
@OsirisTerje The change to Whilst updating the documentation, I noticed an issue with the reporting when texts are too long. |
7db260e
to
21f195b
Compare
to: - AnyOfConstraint - CollectionItemsEqualConstaint - ContainsConstraint - EqualConstraint - UniqueItemsConstraint Updates to Clip String Requires individual clipping when white-space is ignored. We then also need to show two different ^ to indicate the mismatched location.
21f195b
to
8472e69
Compare
All issues fixed, PR ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I mostly have minor questions and/or comments
/// <param name="clipping">If true, the strings should be clipped to fit the line</param> | ||
public abstract void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping); | ||
public abstract void DisplayStringDifferences(string expected, string actual, int mismatchExpected, int mismatchActual, bool ignoreCase, bool ignoreWhiteSpace, bool clipping); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this change breaking? A public (abstract) class containing a public (abstract) method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would be. Thanks for noticing!
The problem then is that if I leave the original signature, I cannot do the message improvements.
Even adding a new abstract
method would be breaking.
I think adding a a new virtual
method it would be fine as it can be resolved without an implementation having to implement it. The default implementation would call into the original method unless:
if (ignoreWhiteSpace && mismatchExpected != mismatchActual)
{
throw new NotImplementedException("Please override to show difference with 'ignoreWhiteSpace'");
}
"surname": Doe" | ||
} | ||
] | ||
"""; | ||
const string condensedJson = """ | ||
"persons":[{"name":"John","surname":"Smith"},{"name": "Jane","surname": Doe"}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the missing "
before Doe
on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it wasn't. I only noticed this myself when I had copied this example into the documentation and the strings were not formatted as expected. Initially I blamed it on the new """
string syntax until I spotted the missing "
.
"
added in two places.
WriteLine(); | ||
if (mismatchExpected >= 0 && mismatchExpected != mismatchActual) | ||
WriteCaretLine(mismatchExpected); | ||
WriteActualLine(actual); | ||
//DisplayDifferences(expected, actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume you mean the one commented out and not the one I just added?
I suspect this line was commented out when the WriteCaretLine
was added, but all of this was already there in the first commit to the repo 15 years ago. I agree it should be removed.
[TestCase(S52, 26, 0, "abcdefghijklmnopqrstuvwxyz...", TestName = "ClipAtEnd")] | ||
[TestCase(S52, 26, 26, "...ABCDEFGHIJKLMNOPQRSTUVWXYZ", TestName = "ClipAtStart")] | ||
[TestCase(S52, 22, 26, "...ABCDEFGHIJKLMNOPQRSTUV...", TestName = "ClipAtStartAndEnd")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to you comment on the PR (pasted below)? If not then what is this change about?
Whilst updating the documentation, I noticed an issue with the reporting when texts are too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it isn't. The original code had one places determining if the actual visible string should be clipped and in the called method it actually reduced the maxDisplayLength
. I moved all determination code into the first method ClipWhenNeeded
and reduced the ClipString
method to do only the clipping to the length passed in.
This means that the length passed into the ClipString
method is 3 or 6 less than previously and hence the updated numbers in the test.
sb.Append($"\\x{(int)c:X4}"); | ||
break; | ||
int originalIndex = index; | ||
StringBuilder sb = new(s.Length + 32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 32 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purely to prevent an re-allocation/copy in most cases when there are a few characters to escape.
It could be any number. I can make it the magic '42' (“The Hitchhiker's Guide to the Galaxy”) or 10.
{ | ||
int clipLength = maxStringLength; | ||
StringBuilder sb = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set this to be of a certain size - e.g. s.length
+ 6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case anyone ever changes the value of ELLIPSIS
, I changed it to s.Length + 2 * ELLIPSIS.Length
@mikkelbu @manfred-brands Is this ready now to be merged ? |
@OsirisTerje I think so, but as I made changes after the review from @mikkelbu, I didn't know if he wants to look at it again. |
Fixes #3918
Adds preparation work for #4662
There are two new constraints:
One to match String.IsNullOrWhiteSpace . This I modeled on 'Empty':
The other is a modifier on existing constrains, which I modeled on
IgnoreCase
:Adding the constraint was easy, to get sensible error messages in case of failure where strings have different white space was harder. In case of mis-matched white-space, the message now contains two carrots, one for
expected
and one foractual
: