Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion Source/aweXpect.Core/Core/IStringMatchType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace aweXpect.Core;

Expand All @@ -11,7 +12,12 @@ public interface IStringMatchType
/// Returns <see langword="true" /> if the two strings <paramref name="actual" /> and <paramref name="expected" /> are
/// considered equal; otherwise <see langword="false" />.
/// </summary>
bool AreConsideredEqual(string? actual, string? expected,
#if NET8_0_OR_GREATER
ValueTask<bool>
#else
Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected,
bool ignoreCase,
IEqualityComparer<string> comparer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Helpers;

Expand Down Expand Up @@ -96,20 +97,37 @@ public string GetExtendedFailure(string it, string? actual, string? expected,
}

/// <inheritdoc cref="IStringMatchType.AreConsideredEqual(string?, string?, bool, IEqualityComparer{string})" />
public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
IEqualityComparer<string> comparer)
{
if (actual is null && expected is null)
{
return true;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(true);
#else
return Task.FromResult(true);
#endif
}

if (actual is null || expected is null)
{
return false;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(false);
#else
return Task.FromResult(false);
#endif
}

return comparer.Equals(actual, expected);
#if NET8_0_OR_GREATER
return ValueTask.FromResult(comparer.Equals(actual, expected));
#else
return Task.FromResult(comparer.Equals(actual, expected));
#endif
Comment thread
vbreuss marked this conversation as resolved.
}

/// <inheritdoc cref="IStringMatchType.GetExpectation(string?, ExpectationGrammars)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Helpers;

Expand Down Expand Up @@ -83,20 +84,37 @@ public string GetExtendedFailure(string it, string? actual, string? expected,
}

/// <inheritdoc cref="IStringMatchType.AreConsideredEqual(string?, string?, bool, IEqualityComparer{string})" />
public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
IEqualityComparer<string> comparer)
{
if (actual is null && expected is null)
{
return true;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(true);
#else
return Task.FromResult(true);
#endif
}

if (actual is null || expected is null)
{
return false;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(false);
#else
return Task.FromResult(false);
#endif
}

return actual.Length >= expected.Length && comparer.Equals(actual[..expected.Length], expected);
#if NET8_0_OR_GREATER
return ValueTask.FromResult(actual.Length >= expected.Length && comparer.Equals(actual[..expected.Length], expected));
#else
return Task.FromResult(actual.Length >= expected.Length && comparer.Equals(actual[..expected.Length], expected));
#endif
Comment thread
vbreuss marked this conversation as resolved.
}

/// <inheritdoc cref="IStringMatchType.GetExpectation(string?, ExpectationGrammars)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Helpers;

Expand Down Expand Up @@ -40,12 +41,21 @@ public string GetExtendedFailure(string it, string? actual, string? expected,
}

/// <inheritdoc cref="IStringMatchType.AreConsideredEqual(string?, string?, bool, IEqualityComparer{string})" />
public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
IEqualityComparer<string> comparer)
{
if (actual is null || expected is null)
{
return false;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(false);
#else
return Task.FromResult(false);
#endif
}

RegexOptions options = RegexOptions.Multiline;
Expand All @@ -54,7 +64,11 @@ public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase
options |= RegexOptions.IgnoreCase;
}

return Regex.IsMatch(actual, expected, options, RegexTimeout);
#if NET8_0_OR_GREATER
return ValueTask.FromResult(Regex.IsMatch(actual, expected, options, RegexTimeout));
#else
return Task.FromResult(Regex.IsMatch(actual, expected, options, RegexTimeout));
#endif
}

/// <inheritdoc cref="IStringMatchType.GetExpectation(string?, ExpectationGrammars)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Helpers;

Expand Down Expand Up @@ -90,20 +91,37 @@ public string GetExtendedFailure(string it, string? actual, string? expected,
}

/// <inheritdoc cref="IStringMatchType.AreConsideredEqual(string?, string?, bool, IEqualityComparer{string})" />
public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
IEqualityComparer<string> comparer)
{
if (actual is null && expected is null)
{
return true;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(true);
#else
return Task.FromResult(true);
#endif
}

if (actual is null || expected is null)
{
return false;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(false);
#else
return Task.FromResult(false);
#endif
}

return actual.Length >= expected.Length && comparer.Equals(actual[^expected.Length..], expected);
#if NET8_0_OR_GREATER
return ValueTask.FromResult(actual.Length >= expected.Length && comparer.Equals(actual[^expected.Length..], expected));
#else
return Task.FromResult(actual.Length >= expected.Length && comparer.Equals(actual[^expected.Length..], expected));
#endif
Comment thread
vbreuss marked this conversation as resolved.
}

/// <inheritdoc cref="IStringMatchType.GetExpectation(string?, ExpectationGrammars)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Helpers;

Expand Down Expand Up @@ -49,20 +50,34 @@ public string GetExtendedFailure(string it, string? actual, string? expected,
}

/// <inheritdoc cref="IStringMatchType.AreConsideredEqual(string?, string?, bool, IEqualityComparer{string})" />
public bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
AreConsideredEqual(string? actual, string? expected, bool ignoreCase,
IEqualityComparer<string> comparer)
{
if (actual is null || expected is null)
{
return false;
#if NET8_0_OR_GREATER
return ValueTask.FromResult(false);
#else
return Task.FromResult(false);
#endif
}

RegexOptions options = ignoreCase
? RegexOptions.Multiline | RegexOptions.IgnoreCase
: RegexOptions.Multiline;

return Regex.IsMatch(actual, WildcardToRegularExpression(expected), options,
RegexTimeout);
#if NET8_0_OR_GREATER
return ValueTask.FromResult(Regex.IsMatch(actual, WildcardToRegularExpression(expected), options,
RegexTimeout));
#else
return Task.FromResult(Regex.IsMatch(actual, WildcardToRegularExpression(expected), options,
RegexTimeout));
#endif
Comment thread
vbreuss marked this conversation as resolved.
}

/// <inheritdoc cref="IStringMatchType.GetExpectation(string?, ExpectationGrammars)" />
Expand Down
20 changes: 6 additions & 14 deletions Source/aweXpect.Core/Options/StringEqualityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ public partial class StringEqualityOptions : IOptionsEquality<string?>

/// <inheritdoc />
#if NET8_0_OR_GREATER
public ValueTask<bool> AreConsideredEqual<TExpected>(string? actual, TExpected expected)
public async ValueTask<bool> AreConsideredEqual<TExpected>(string? actual, TExpected expected)
#else
public Task<bool> AreConsideredEqual<TExpected>(string? actual, TExpected expected)
public async Task<bool> AreConsideredEqual<TExpected>(string? actual, TExpected expected)
#endif
{
bool result;
if (expected is not string expectedString)
{
result = _matchType.AreConsideredEqual(actual, null, _ignoreCase,
result = await _matchType.AreConsideredEqual(actual, null, _ignoreCase,
_comparer ?? UseDefaultComparer(_ignoreCase));
#if NET8_0_OR_GREATER
return ValueTask.FromResult(result);
#else
return Task.FromResult(result);
#endif
return result;
}

if (_ignoreNewlineStyle)
Expand All @@ -59,13 +55,9 @@ public Task<bool> AreConsideredEqual<TExpected>(string? actual, TExpected expect
expectedString = expectedString.TrimEnd();
}

result = _matchType.AreConsideredEqual(actual, expectedString, _ignoreCase,
result = await _matchType.AreConsideredEqual(actual, expectedString, _ignoreCase,
_comparer ?? UseDefaultComparer(_ignoreCase));
#if NET8_0_OR_GREATER
return ValueTask.FromResult(result);
#else
return Task.FromResult(result);
#endif
return result;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace aweXpect.Core
}
public interface IStringMatchType
{
bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer);
System.Threading.Tasks.ValueTask<bool> AreConsideredEqual(string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer);
string GetExpectation(string? expected, aweXpect.Core.ExpectationGrammars grammars);
string GetExtendedFailure(string it, string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer, aweXpect.Core.StringDifferenceSettings? settings);
string GetOptionString(bool ignoreCase, System.Collections.Generic.IEqualityComparer<string>? comparer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace aweXpect.Core
}
public interface IStringMatchType
{
bool AreConsideredEqual(string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer);
System.Threading.Tasks.Task<bool> AreConsideredEqual(string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer);
string GetExpectation(string? expected, aweXpect.Core.ExpectationGrammars grammars);
string GetExtendedFailure(string it, string? actual, string? expected, bool ignoreCase, System.Collections.Generic.IEqualityComparer<string> comparer, aweXpect.Core.StringDifferenceSettings? settings);
string GetOptionString(bool ignoreCase, System.Collections.Generic.IEqualityComparer<string>? comparer);
Expand Down
Loading