Skip to content
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

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nuget/framework/nunit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<dependencies>
<group targetFramework="net462">
<dependency id="System.Threading.Tasks.Extensions" version="4.5.4" exclude="Build,Analyzers" />
<dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0" />
</dependencies>
Expand Down
12 changes: 12 additions & 0 deletions src/NUnitFramework/framework/Constraints/AnyOfConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public AnyOfConstraint IgnoreCase
}
}

/// <summary>
/// Flag the constraint to ignore white space and return self.
/// </summary>
public AnyOfConstraint IgnoreWhiteSpace
{
get
{
_comparer.IgnoreWhiteSpace = true;
return this;
}
}

/// <summary>
/// Flag the constraint to use the supplied IComparer object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected CollectionItemsEqualConstraint(object? arg) : base(arg)
/// </summary>
protected bool IgnoringCase => _comparer.IgnoreCase;

/// <summary>
/// Get a flag indicating whether the user requested us to ignore white space.
/// </summary>
protected bool IgnoringWhiteSpace => _comparer.IgnoreWhiteSpace;

/// <summary>
/// Get a flag indicating whether any external comparers are in use.
/// </summary>
Expand All @@ -61,6 +66,18 @@ public CollectionItemsEqualConstraint IgnoreCase
}
}

/// <summary>
/// Flag the constraint to ignore white space and return self.
/// </summary>
public CollectionItemsEqualConstraint IgnoreWhiteSpace
{
get
{
_comparer.IgnoreWhiteSpace = true;
return this;
}
}

/// <summary>
/// Flag the constraint to use the supplied IComparer object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@ public static EqualMethodResult Equal(object x, object y, ref Tolerance toleranc
if (tolerance.HasVariance)
return EqualMethodResult.ToleranceNotSupported;

var stringComparison = equalityComparer.IgnoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.Ordinal;
return xString.Equals(yString, stringComparison) ?
EqualMethodResult.ComparedEqual : EqualMethodResult.ComparedNotEqual;
return Equals(xString, yString, equalityComparer.IgnoreCase, equalityComparer.IgnoreWhiteSpace) ?
EqualMethodResult.ComparedEqual :
EqualMethodResult.ComparedNotEqual;
}

public static bool Equals(string x, string y, bool ignoreCase, bool ignoreWhiteSpace)
{
if (ignoreWhiteSpace)
{
(int mismatchExpected, int mismatchActual) = MsgUtils.FindMismatchPosition(x, y, ignoreCase, true);
return mismatchExpected == -1 && mismatchActual == -1;
}
else
{
return x.Equals(y, ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.Ordinal);
}
}
}
}
Loading