Skip to content

Commit

Permalink
Get TUnit.Assertions building
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Dec 20, 2024
1 parent d88ddc7 commit b77e7e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public OrAssertionGroup<TActual, TAssertionBuilder> Or(Func<TAssertionBuilder, I

private void Push(TAssertionBuilder assertionBuilder, Func<TAssertionBuilder, InvokableAssertionBuilder<TActual>> assert)
{
if (_assertConditions.Count > 0)
if (_assertConditions.TryPop(out var assertCondition))
{
var assertCondition = _assertConditions.Pop();
_assertConditions.Push(new OrAssertCondition<TActual>(assertCondition, assert(assertionBuilder).Assertions.Pop()));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
{
MembersToIgnore = [.._ignoredMembers]
})),
() => $"it is {string.Join(',', actualEnumerable)}");
() => $"it is {string.Join(",", actualEnumerable)}");
}

bool? isEqual = null;
Expand Down Expand Up @@ -78,7 +78,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
}

return FailWithMessage($"""
{firstFailure.Type} {string.Join('.', firstFailure.NestedMemberNames)} did not match
{firstFailure.Type} {string.Join(".", firstFailure.NestedMemberNames)} did not match
Expected: {Formatter.Format(firstFailure.Expected)}
Received: {Formatter.Format(firstFailure.Actual)}
""");
Expand Down
6 changes: 3 additions & 3 deletions TUnit.Assertions/Compare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static IEnumerable<ComparisonFailure> CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, $"[{i}]"];

if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
Expand All @@ -106,7 +106,7 @@ private static IEnumerable<ComparisonFailure> CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, fieldName];

if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ private static IEnumerable<ComparisonFailure> CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, propertyName];

if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
Expand Down
25 changes: 24 additions & 1 deletion TUnit.Engine/PolyfillExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TUnit;
using System.Diagnostics.CodeAnalysis;

namespace TUnit;

static class PolyfillExtensions
{
Expand All @@ -8,6 +10,27 @@ internal static void Deconstruct<K, V>(this KeyValuePair<K, V> pair, out K key,
val = pair.Value;
}

internal static string ReplaceLineEndings(this string value, string replacement)
{
return value.Replace("\r\n", replacement)
.Replace("\n", replacement)
.Replace("\r", replacement);
}

internal static bool StartsWith(this string value, char ch) => value.Length > 0 && value[0] == ch;

internal static bool TryPop<T>(this Stack<T> stack, [MaybeNullWhen(false)] out T value)
{
if (stack.Count == 0)
{
value = default;
return false;
}

value = stack.Pop();
return true;
}

internal static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) => source.OrderBy(v => v);

/// <summary>Returns the minimum value in a generic sequence according to a specified key selector function.</summary>
Expand Down

0 comments on commit b77e7e9

Please sign in to comment.