Skip to content

Commit

Permalink
Various internal naming improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Aug 28, 2024
1 parent ae5b04c commit 8d1b924
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Src/FluentAssertions/AndConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace FluentAssertions;

[DebuggerNonUserCode]
public class AndConstraint<T>
public class AndConstraint<TParent>
{
public T And { get; }
public TParent And { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AndConstraint{T}"/> class.
/// </summary>
public AndConstraint(T parentConstraint)
public AndConstraint(TParent parent)
{
And = parentConstraint;
And = parent;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Equivalency/EquivalencyStep.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FluentAssertions.Equivalency;
namespace FluentAssertions.Equivalency;

/// <summary>
/// Convenient implementation of <see cref="IEquivalencyStep"/> that will only invoke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void AddSet(object key, string[] failures)
/// The closest match is the set that contains the least amount of failures, or no failures at all, and preferably
/// the set that is identified by the <paramref name="key"/>.
/// </remarks>
public string[] SelectClosestMatchFor(object key = null)
public string[] GetTheFailuresForTheSetWithTheFewestFailures(object key = null)
{
if (ContainsSuccessfulSet())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private bool LooselyMatchAgainst<T>(IList<object> subjects, T expectation, int e
unmatchedSubjectIndexes.RemoveAt(indexToBeRemoved);
}

foreach (string failure in results.SelectClosestMatchFor(expectationIndex))
foreach (string failure in results.GetTheFailuresForTheSetWithTheFewestFailures(expectationIndex))
{
AssertionScope.Current.AddPreFormattedFailure(failure);
}
Expand Down
12 changes: 6 additions & 6 deletions Src/FluentAssertions/Execution/AssertionScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class AssertionScope : IAssertionScope
#region Private Definitions

private readonly IAssertionStrategy assertionStrategy;
private readonly ContextDataItems contextData = new();
private readonly ContextDataDictionary contextData = new();
private readonly StringBuilder tracing = new();

private Func<string> reason;
Expand Down Expand Up @@ -219,8 +219,8 @@ public AssertionScope WithExpectation(string message, params object[] args)

internal void TrackComparands(object subject, object expectation)
{
contextData.Add(new ContextDataItems.DataItem("subject", subject, reportable: false, requiresFormatting: true));
contextData.Add(new ContextDataItems.DataItem("expectation", expectation, reportable: false, requiresFormatting: true));
contextData.Add(new ContextDataDictionary.DataItem("subject", subject, reportable: false, requiresFormatting: true));
contextData.Add(new ContextDataDictionary.DataItem("expectation", expectation, reportable: false, requiresFormatting: true));
}

/// <inheritdoc/>
Expand Down Expand Up @@ -359,7 +359,7 @@ public void AppendTracing(string tracingBlock)
/// </summary>
public void AddNonReportable(string key, object value)
{
contextData.Add(new ContextDataItems.DataItem(key, value, reportable: false, requiresFormatting: false));
contextData.Add(new ContextDataDictionary.DataItem(key, value, reportable: false, requiresFormatting: false));
}

/// <summary>
Expand All @@ -368,7 +368,7 @@ public void AddNonReportable(string key, object value)
/// </summary>
public void AddReportable(string key, string value)
{
contextData.Add(new ContextDataItems.DataItem(key, value, reportable: true, requiresFormatting: false));
contextData.Add(new ContextDataDictionary.DataItem(key, value, reportable: true, requiresFormatting: false));
}

/// <summary>
Expand All @@ -377,7 +377,7 @@ public void AddReportable(string key, string value)
/// </summary>
public void AddReportable(string key, Func<string> valueFunc)
{
contextData.Add(new ContextDataItems.DataItem(key, new DeferredReportable(valueFunc), reportable: true,
contextData.Add(new ContextDataDictionary.DataItem(key, new DeferredReportable(valueFunc), reportable: true,
requiresFormatting: false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FluentAssertions.Execution;
/// <summary>
/// Represents a collection of data items that are associated with an <see cref="AssertionScope"/>.
/// </summary>
internal class ContextDataItems
internal class ContextDataDictionary
{
private readonly List<DataItem> items = [];

Expand All @@ -33,9 +33,9 @@ public string AsStringOrDefault(string key)
return null;
}

public void Add(ContextDataItems contextDataItems)
public void Add(ContextDataDictionary contextDataDictionary)
{
foreach (DataItem item in contextDataItems.items)
foreach (DataItem item in contextDataDictionary.items)
{
Add(item.Clone());
}
Expand All @@ -61,28 +61,20 @@ public T Get<T>(string key)
return (T)(item?.Value ?? default(T));
}

internal class DataItem
internal class DataItem(string key, object value, bool reportable, bool requiresFormatting)
{
public DataItem(string key, object value, bool reportable, bool requiresFormatting)
{
Key = key;
Value = value;
Reportable = reportable;
RequiresFormatting = requiresFormatting;
}

public string Key { get; }
public string Key { get; } = key;

public object Value { get; }
public object Value { get; } = value;

public bool Reportable { get; }
public bool Reportable { get; } = reportable;

public bool RequiresFormatting { get; }
public bool RequiresFormatting { get; } = requiresFormatting;

public DataItem Clone()
{
object value = Value is ICloneable2 cloneable ? cloneable.Clone() : Value;
return new DataItem(Key, value, Reportable, RequiresFormatting);
object clone = Value is ICloneable2 cloneable ? cloneable.Clone() : Value;
return new DataItem(Key, clone, Reportable, RequiresFormatting);
}
}
}
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Execution/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MessageBuilder(FormattingOptions formattingOptions)
}

// SMELL: Too many parameters.
public string Build(string message, object[] messageArgs, string reason, ContextDataItems contextData, string identifier,
public string Build(string message, object[] messageArgs, string reason, ContextDataDictionary contextData, string identifier,
string fallbackIdentifier)
{
message = message.Replace("{reason}", SanitizeReason(reason), StringComparison.Ordinal);
Expand Down Expand Up @@ -75,7 +75,7 @@ private static string SubstituteIdentifier(string message, string identifier, st
return message.TrimStart();
}

private static string SubstituteContextualTags(string message, ContextDataItems contextData)
private static string SubstituteContextualTags(string message, ContextDataDictionary contextData)
{
const string pattern = @"(?<!\{)\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}(?!\})";

Expand Down
14 changes: 4 additions & 10 deletions Src/FluentAssertions/Formatting/FormattedObjectGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ namespace FluentAssertions.Formatting;
/// to the maximum number of lines provided through its constructor. It will throw
/// a <see cref="MaxLinesExceededException"/> if the number of lines exceeds the maximum.
/// </remarks>
public class FormattedObjectGraph
public class FormattedObjectGraph(int maxLines)
{
private readonly int maxLines;
private readonly List<string> lines = [];
private readonly StringBuilder lineBuilder = new();
private int indentation;
private string lineBuilderWhitespace = string.Empty;

public FormattedObjectGraph(int maxLines)
{
this.maxLines = maxLines;
}

/// <summary>
/// The number of spaces that should be used by every indentation level.
/// </summary>
Expand Down Expand Up @@ -57,7 +51,7 @@ public void AddLine(string line)
{
FlushCurrentLine();

AppendSafely(Whitespace + line);
AppendWithoutExceedingMaximumLines(Whitespace + line);
}

/// <summary>
Expand Down Expand Up @@ -101,14 +95,14 @@ private void FlushCurrentLine()
{
if (lineBuilder.Length > 0)
{
AppendSafely($"{lineBuilderWhitespace}{lineBuilder}");
AppendWithoutExceedingMaximumLines($"{lineBuilderWhitespace}{lineBuilder}");

lineBuilder.Clear();
lineBuilderWhitespace = Whitespace;
}
}

private void AppendSafely(string line)
private void AppendWithoutExceedingMaximumLines(string line)
{
if (lines.Count == maxLines)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Specialized/ExceptionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static void Execute(IEnumerable<string> messages, string expectation, [St
}
}

foreach (string failure in results.SelectClosestMatchFor())
foreach (string failure in results.GetTheFailuresForTheSetWithTheFewestFailures())
{
string replacedCurlyBraces =
failure.EscapePlaceholders();
Expand Down

0 comments on commit 8d1b924

Please sign in to comment.