forked from fluentassertions/fluentassertions
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked formatting and support multi-dimensional arrays.
- Loading branch information
1 parent
669f817
commit e9357fb
Showing
20 changed files
with
699 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ProjectConfiguration> | ||
<Settings> | ||
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> | ||
</Settings> | ||
</ProjectConfiguration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<SolutionConfiguration> | ||
<Settings> | ||
<AllowParallelTestExecution>True</AllowParallelTestExecution> | ||
<EnableRDI>False</EnableRDI> | ||
<RdiConfigured>True</RdiConfigured> | ||
<SolutionConfigured>True</SolutionConfigured> | ||
</Settings> | ||
</SolutionConfiguration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace FluentAssertions.Formatting; | ||
|
||
/// <summary> | ||
/// Write fragments that may be on a single line or span multiple lines, | ||
/// and this is not known until later parts of the fragment are written. | ||
/// </summary> | ||
internal class Anchor | ||
{ | ||
private readonly FormattedObjectGraph parent; | ||
private readonly int indentation; | ||
private readonly int characterIndex; | ||
private readonly Line line; | ||
private readonly bool lineWasEmptyAtCreation; | ||
|
||
public Anchor(FormattedObjectGraph parent, Line line) | ||
{ | ||
indentation = parent.Indentation; | ||
this.parent = parent; | ||
this.line = line; | ||
lineWasEmptyAtCreation = line is null || line.Length == 0; | ||
|
||
// Track the point in the graph where this instance was created. | ||
characterIndex = line?.LengthWithoutOffset ?? 0; | ||
} | ||
|
||
public bool UseLineBreaks { get; set; } | ||
|
||
public void InsertFragment(string fragment) | ||
{ | ||
// 3. If there are no lines following the current, insert at the character index | ||
// 4. If there are more lines following the current, insert at the character index and add a new line | ||
line.Insert(characterIndex, fragment); | ||
|
||
if (!RenderOnSingleLine) | ||
{ | ||
// Split the line at the character index | ||
// REFACTOR: Don't even split if there's nothing beyond the character index (other than whitespace) | ||
parent.SplitLine(line, characterIndex + fragment.Length); | ||
} | ||
} | ||
|
||
public void InsertLineOrFragment(string fragment) | ||
{ | ||
if (RenderOnSingleLine) | ||
{ | ||
if (line is null) | ||
{ | ||
parent.InsertAtTop(fragment); | ||
} | ||
else | ||
{ | ||
line.Insert(characterIndex, fragment); | ||
} | ||
} | ||
else | ||
{ | ||
// FIX: We sometimes need to insert the new line before the current line. | ||
|
||
// Insert a new line in-between the current line and the next line and put the fragment there. | ||
if (lineWasEmptyAtCreation) | ||
{ | ||
parent.InsertLineBefore(line, FormattedObjectGraph.MakeWhitespace(indentation) + fragment); | ||
} | ||
else | ||
{ | ||
parent.AddLineAfter(line, FormattedObjectGraph.MakeWhitespace(indentation) + fragment); | ||
} | ||
} | ||
} | ||
|
||
internal void AddLineOrFragment(string fragment) | ||
{ | ||
if (line is null) | ||
{ | ||
parent.AddLineOrFragment(fragment); | ||
} | ||
else if (RenderOnSingleLine) | ||
{ | ||
line.Append(fragment); | ||
} | ||
else | ||
{ | ||
parent.AddLine(fragment); | ||
} | ||
} | ||
|
||
private bool RenderOnSingleLine => !UseLineBreaks && !parent.HasLinesBeyond(line); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.