-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
ArgumentOutOfRangeException
when formatting objects using UseLineBreaks
#2695
Comments
The second one is actually a pretty easy fix. But the first one is pretty tricky.. because if you handle the See: {
{
{P}
P
}
} |
What where your findings? Preferably we should not handle |
[Fact]
public void Array_of_objects_with_array_of_toStringable_objects()
{
var sigmets = new[]
{
new
{
Points = new Point[] { new() }
},
new
{
Points = new Point[] { new() }
}
};
var result = Formatter.ToString(sigmets, new() { UseLineBreaks = true });
result.Should().Be(
"""
{
{
Points =
{
P
}
},
{
Points =
{
P
}
}
}
""");
} private void InsertAtStartOfLine(int lineIndex, string insertion)
{
+ lineIndex = parentGraph.lines.Count <= lineIndex ? parentGraph.lines.Count - 1 : lineIndex;
if (!parentGraph.lines[lineIndex].StartsWith(insertion, StringComparison.Ordinal))
{
parentGraph.lines[lineIndex] = parentGraph.lines[lineIndex].Insert(0, insertion);
}
} All tests green (except the first one in this ticket)
That's what I meant 😉 |
In
|
It's something to do with the first sub-array...
results in
|
The var sigmets = new Point[][]
{
[new Point(), new Point()],
[new Point()],
[new Point()],
}; |
Interesting findings from both of you. Thanks for helping looking into this. |
As it seems, the formatting does not recognize, that the first item in the first sub-array is one intendation layer deeper var sigmets = new Point[][]
{
[new Point(), new Point(), new Point()],
[new Point(), new Point()],
[new Point(), new Point()],
};
|
I suggest we remove the usage of While it doesn't solve the problem if an end user chooses to use |
Yeah, makes sense. We should also investigate what we intend to accomplish with |
I think the problem boils down to this:
The formatted string is actually
and this is because I traced through what's going on when we format those arrays, and these are the calls made on
which calls fluentassertions/Src/FluentAssertions/Formatting/Formatter.cs Lines 146 to 150 in 08178fc
which uses
The problem is that |
Description
When using
ReferenceTypeAssertions.BeSameAs
and failing I got aArgumentOutOfRangeException
instead of anXunitException
.From the stack trace the problem lies somewhere in the formatting of the subject combined with using
UseLineBreaks
.Only a few assertions specify
UseLineBreaks
per default, which is why we might not have seen this before.Reproduction Steps
Expected behavior
Both tests should be able to complete without throwing an exception
Actual behavior
Array_of_arrays_of_toStringable_objects
:Array_of_objects_with_array_of_toStringable_objects
:Regression?
Yes
In 6.11.0
Formatter.ToString
doesn't throw.Known Workarounds
No response
Configuration
Tried with both Version 6.12 and develop
Other information
By looking in the release notes for 6.12 I suspect #2144
CC: @benagain
Are you willing to help with a pull-request?
Yes, if anyone can figure out what the problem is
The text was updated successfully, but these errors were encountered: