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
2 changes: 1 addition & 1 deletion Pipeline/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ partial class Build : NukeBuild
/// <para />
/// Afterward, you can update the package reference in `Directory.Packages.props` and reset this flag.
/// </summary>
readonly BuildScope BuildScope = BuildScope.Default;
readonly BuildScope BuildScope = BuildScope.CoreOnly;
Comment thread
vbreuss marked this conversation as resolved.

[Parameter("Github Token")] readonly string GithubToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static void Format(
stringBuilder.Append(Format(formatter, v, options with
{
IncludeType = false,
UseLineBreaks = options.UseLineBreaks && v?.GetType() != typeof(string),
}).Indent(" ", false));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using aweXpect.Core;
using aweXpect.Equivalency;
using aweXpect.Options;

namespace aweXpect.Results;
Expand All @@ -12,41 +10,35 @@ namespace aweXpect.Results;
/// <remarks>
/// <seealso cref="HasItemResult{TCollection}" />
/// </remarks>
public class HasItemObjectResult<TCollection, TItem>(
public class ObjectHasItemResult<TCollection, TItem>(
ExpectationBuilder expectationBuilder,
IThat<TCollection> collection,
CollectionIndexOptions collectionIndexOptions,
ObjectEqualityOptions<TItem> options)
: HasItemObjectResult<TCollection, TItem,
HasItemObjectResult<TCollection, TItem>>(
: ObjectHasItemResult<TCollection, TItem,
ObjectHasItemResult<TCollection, TItem>>(
expectationBuilder,
collection,
collectionIndexOptions,
options);


/// <summary>
/// The result for verifying that a collection has a specific item at a given index.
/// </summary>
/// <remarks>
/// <seealso cref="HasItemResult{TCollection}" />
/// </remarks>
public class HasItemObjectResult<TCollection, TItem, TSelf>(
public class ObjectHasItemResult<TCollection, TItem, TSelf>(
ExpectationBuilder expectationBuilder,
IThat<TCollection> collection,
CollectionIndexOptions collectionIndexOptions,
ObjectEqualityOptions<TItem> options)
: HasItemResult<TCollection>(expectationBuilder, collection, collectionIndexOptions)
where TSelf : HasItemObjectResult<TCollection, TItem, TSelf>
: HasItemResult<TCollection>(expectationBuilder, collection, collectionIndexOptions),
IOptionsProvider<ObjectEqualityOptions<TItem>>
where TSelf : ObjectHasItemResult<TCollection, TItem, TSelf>
{
/// <summary>
/// Use equivalency to compare objects.
/// </summary>
public TSelf Equivalent(Func<EquivalencyOptions, EquivalencyOptions>? optionsCallback = null)
{
options.Equivalent(EquivalencyOptionsExtensions.FromCallback(optionsCallback));
return (TSelf)this;
}
/// <inheritdoc cref="IOptionsProvider{TOptions}.Options" />
ObjectEqualityOptions<TItem> IOptionsProvider<ObjectEqualityOptions<TItem>>.Options => options;

/// <summary>
/// Uses the provided <paramref name="comparer" /> for comparing <see langword="object" />s.
Expand Down
138 changes: 138 additions & 0 deletions Source/aweXpect.Core/Results/StringHasItemResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using aweXpect.Core;
using aweXpect.Options;

namespace aweXpect.Results;

/// <summary>
/// The result for verifying that a collection has a specific item at a given index.
/// </summary>
/// <remarks>
/// <seealso cref="HasItemResult{TCollection}" />
/// </remarks>
public class StringHasItemResult<TCollection>(
ExpectationBuilder expectationBuilder,
IThat<TCollection> collection,
CollectionIndexOptions collectionIndexOptions,
StringEqualityOptions options)
: StringHasItemResult<TCollection,
StringHasItemResult<TCollection>>(
expectationBuilder,
collection,
collectionIndexOptions,
options);

/// <summary>
/// The result for verifying that a collection has a specific item at a given index.
/// </summary>
/// <remarks>
/// <seealso cref="HasItemResult{TCollection}" />
/// </remarks>
public class StringHasItemResult<TCollection, TSelf>(
ExpectationBuilder expectationBuilder,
IThat<TCollection> collection,
CollectionIndexOptions collectionIndexOptions,
StringEqualityOptions options)
: HasItemResult<TCollection>(expectationBuilder, collection, collectionIndexOptions),
IOptionsProvider<StringEqualityOptions>
where TSelf : StringHasItemResult<TCollection, TSelf>
{
/// <inheritdoc cref="IOptionsProvider{TOptions}.Options" />
StringEqualityOptions IOptionsProvider<StringEqualityOptions>.Options => options;

/// <summary>
/// Ignores casing when comparing the <see langword="string" />s,
/// according to the <paramref name="ignoreCase" /> parameter.
/// </summary>
public TSelf IgnoringCase(bool ignoreCase = true)
{
options.IgnoringCase(ignoreCase);
return (TSelf)this;
}

/// <summary>
/// Ignores the newline style when comparing <see langword="string" />s,
/// according to the <paramref name="ignoreNewlineStyle" /> parameter.
/// </summary>
/// <remarks>
/// Enabling this option will replace all occurrences of <c>\r\n</c> and <c>\r</c> with <c>\n</c> in the strings before
/// comparing them.
/// </remarks>
public TSelf IgnoringNewlineStyle(bool ignoreNewlineStyle = true)
{
options.IgnoringNewlineStyle(ignoreNewlineStyle);
return (TSelf)this;
}

/// <summary>
/// Ignores leading white-space when comparing <see langword="string" />s,
/// according to the <paramref name="ignoreLeadingWhiteSpace" /> parameter.
/// </summary>
/// <remarks>
/// Note:<br />
/// This affects the index of first mismatch, as the removed whitespace is also ignored for the index calculation!
/// </remarks>
public TSelf IgnoringLeadingWhiteSpace(bool ignoreLeadingWhiteSpace = true)
{
options.IgnoringLeadingWhiteSpace(ignoreLeadingWhiteSpace);
return (TSelf)this;
}

/// <summary>
/// Ignores trailing white-space when comparing <see langword="string" />s,
/// according to the <paramref name="ignoreTrailingWhiteSpace" /> parameter.
/// </summary>
public TSelf IgnoringTrailingWhiteSpace(bool ignoreTrailingWhiteSpace = true)
{
options.IgnoringTrailingWhiteSpace(ignoreTrailingWhiteSpace);
return (TSelf)this;
}

/// <summary>
/// Uses the provided <paramref name="comparer" /> for comparing <see langword="string" />s.
/// </summary>
public TSelf Using(
IEqualityComparer<string> comparer)
{
options.UsingComparer(comparer);
return (TSelf)this;
}

/// <summary>
/// Interprets the expected <see langword="string" /> as a prefix, so that the actual value starts with it.
/// </summary>
public TSelf AsPrefix()
{
options.AsPrefix();
return (TSelf)this;
}

/// <summary>
/// Interprets the expected <see langword="string" /> as <see cref="Regex" /> pattern.
/// </summary>
public TSelf AsRegex()
{
options.AsRegex();
return (TSelf)this;
}

/// <summary>
/// Interprets the expected <see langword="string" /> as a suffix, so that the actual value ends with it.
/// </summary>
public TSelf AsSuffix()
{
options.AsSuffix();
return (TSelf)this;
}

/// <summary>
/// Interprets the expected <see langword="string" /> as wildcard pattern.<br />
/// Supports * to match zero or more characters and ? to match exactly one character.
/// </summary>
public TSelf AsWildcard()
{
options.AsWildcard();
return (TSelf)this;
}
}
13 changes: 13 additions & 0 deletions Source/aweXpect/Equivalency/EquivalencyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ public static TSelf Equivalent<TType, TThat, TElement, TSelf>(
return (TSelf)result;
}

/// <summary>
/// Use equivalency to compare objects.
/// </summary>
public static TSelf Equivalent<TCollection, TItem, TSelf>(
this ObjectHasItemResult<TCollection, TItem, TSelf> result,
Func<EquivalencyOptions, EquivalencyOptions>? options = null)
where TSelf : ObjectHasItemResult<TCollection, TItem, TSelf>
{
((IOptionsProvider<ObjectEqualityOptions<TItem>>)result).Options.SetMatchType(
new EquivalencyComparer(EquivalencyOptionsExtensions.FromCallback(options)));
return (TSelf)result;
}

/// <summary>
/// Use equivalency to compare objects.
/// </summary>
Expand Down
24 changes: 22 additions & 2 deletions Source/aweXpect/That/Collections/ThatAsyncEnumerable.HasItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public static partial class ThatAsyncEnumerable
/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static HasItemObjectResult<IAsyncEnumerable<TItem>?, TItem> HasItem<TItem>(
public static ObjectHasItemResult<IAsyncEnumerable<TItem>?, TItem> HasItem<TItem>(
this IThat<IAsyncEnumerable<TItem>?> source, TItem expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
ObjectEqualityOptions<TItem> options = new();
return new HasItemObjectResult<IAsyncEnumerable<TItem>?, TItem>(
return new ObjectHasItemResult<IAsyncEnumerable<TItem>?, TItem>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemConstraint<TItem>(expectationBuilder, it, grammars,
a => options.AreConsideredEqual(a, expected),
Expand All @@ -55,6 +55,26 @@ public static partial class ThatAsyncEnumerable
options);
}

/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static StringHasItemResult<IAsyncEnumerable<string?>?> HasItem(
this IThat<IAsyncEnumerable<string?>?> source, string? expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
StringEqualityOptions options = new();
return new StringHasItemResult<IAsyncEnumerable<string?>?>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemConstraint<string?>(expectationBuilder, it, grammars,
a => options.AreConsideredEqual(a, expected),
() => options.GetExpectation(expected, grammars),
indexOptions)),
source,
indexOptions,
options);
}

private sealed class HasItemConstraint<TItem>(
ExpectationBuilder expectationBuilder,
string it,
Expand Down
55 changes: 49 additions & 6 deletions Source/aweXpect/That/Collections/ThatEnumerable.HasItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public static partial class ThatEnumerable
/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static HasItemObjectResult<IEnumerable<TItem>?, TItem> HasItem<TItem>(
public static ObjectHasItemResult<IEnumerable<TItem>?, TItem> HasItem<TItem>(
this IThat<IEnumerable<TItem>?> source, TItem expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
ObjectEqualityOptions<TItem> options = new();
return new HasItemObjectResult<IEnumerable<TItem>?, TItem>(
return new ObjectHasItemResult<IEnumerable<TItem>?, TItem>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemConstraint<TItem>(expectationBuilder, it, grammars,
a => options.AreConsideredEqual(a, expected),
Expand All @@ -57,6 +57,26 @@ public static partial class ThatEnumerable
options);
}

/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static StringHasItemResult<IEnumerable<string?>?> HasItem(
this IThat<IEnumerable<string?>?> source, string? expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
StringEqualityOptions options = new();
return new StringHasItemResult<IEnumerable<string?>?>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemConstraint<string?>(expectationBuilder, it, grammars,
a => options.AreConsideredEqual(a, expected),
() => options.GetExpectation(expected, grammars),
indexOptions)),
source,
indexOptions,
options);
}

/// <summary>
/// Verifies that the collection has an item matching the <paramref name="predicate" />…
/// </summary>
Expand All @@ -80,13 +100,13 @@ public static HasItemResult<IEnumerable> HasItem(
/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static HasItemObjectResult<IEnumerable, object?> HasItem(
public static ObjectHasItemResult<IEnumerable, object?> HasItem(
this IThat<IEnumerable> source, object? expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
ObjectEqualityOptions<object?> options = new();
return new HasItemObjectResult<IEnumerable, object?>(
return new ObjectHasItemResult<IEnumerable, object?>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemForEnumerableConstraint<IEnumerable, object?>(
expectationBuilder, it, grammars,
Expand Down Expand Up @@ -124,13 +144,13 @@ public static HasItemResult<ImmutableArray<TItem>> HasItem<TItem>(
/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static HasItemObjectResult<ImmutableArray<TItem>, TItem> HasItem<TItem>(
public static ObjectHasItemResult<ImmutableArray<TItem>, TItem> HasItem<TItem>(
this IThat<ImmutableArray<TItem>> source, TItem expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
ObjectEqualityOptions<TItem> options = new();
return new HasItemObjectResult<ImmutableArray<TItem>, TItem>(
return new ObjectHasItemResult<ImmutableArray<TItem>, TItem>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemForEnumerableConstraint<ImmutableArray<TItem>, TItem>(
expectationBuilder, it, grammars,
Expand All @@ -143,6 +163,29 @@ public static HasItemObjectResult<ImmutableArray<TItem>, TItem> HasItem<TItem>(
}
#endif

#if NET8_0_OR_GREATER
/// <summary>
/// Verifies that the collection has the <paramref name="expected" /> item…
/// </summary>
public static StringHasItemResult<ImmutableArray<string?>> HasItem(
this IThat<ImmutableArray<string?>> source, string? expected)
{
CollectionIndexOptions indexOptions = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
StringEqualityOptions options = new();
return new StringHasItemResult<ImmutableArray<string?>>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemForEnumerableConstraint<ImmutableArray<string?>, string?>(
expectationBuilder, it, grammars,
a => options.AreConsideredEqual(a, expected),
() => $"{Formatter.Format(expected)}{options}",
indexOptions)),
source,
indexOptions,
options);
}
#endif

private sealed class HasItemConstraint<TItem>(
ExpectationBuilder expectationBuilder,
string it,
Expand Down
Loading
Loading