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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ indent_style = space
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf
max_line_length = 120

# Verify settings
# https://github.com/VerifyTests/Verify?tab=readme-ov-file#text-file-settings
Expand Down
7 changes: 2 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference
Include="Microsoft.VisualStudio.Threading.Analyzers"
Version="17.13.61"
/>
<GlobalPackageReference Include="NetEvolve.Defaults" Version="1.3.74" />
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61" />
<GlobalPackageReference Include="NetEvolve.Defaults" Version="1.3.80" />
<GlobalPackageReference
Include="SonarAnalyzer.CSharp"
Version="10.6.0.109712"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ internal StartsWithConstraint(string compareValue, StringComparison comparison)
public override bool IsSatisfiedBy(object? value) =>
value switch
{
string stringValue when _compareValue is char compareValue => stringValue.StartsWith(
compareValue
),
string stringValue when _compareValue is char compareValue => stringValue.StartsWith(compareValue),
string stringValue when _compareValue is string compareValue => stringValue.StartsWith(
compareValue,
_comparison ?? default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public override bool IsSatisfiedBy(object? value) =>
_ => false,
};

public override void SetDescription(StringBuilder builder) =>
builder.Append(" is <whitespace>");
public override void SetDescription(StringBuilder builder) => builder.Append(" is <whitespace>");

private static bool IsWhiteSpace(ReadOnlySpan<char> value)
{
Expand Down
6 changes: 1 addition & 5 deletions src/NetEvolve.FluentValue/IConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
/// <summary>
/// Public interface for constraints, which can be used to build complex expressions.
/// </summary>
[SuppressMessage(
"Naming",
"CA1716:Identifiers should not match keywords",
Justification = "As designed."
)]
[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "As designed.")]
public interface IConstraint
{
/// <summary>
Expand Down
19 changes: 5 additions & 14 deletions src/NetEvolve.FluentValue/IOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
/// <summary>
/// Public interface for operators, which can be used to build complex expressions.
/// </summary>
[SuppressMessage(
"Naming",
"CA1716:Identifiers should not match keywords",
Justification = "As designed."
)]
[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "As designed.")]
public interface IOperator : IConstraint
{
/// <summary>
Expand Down Expand Up @@ -51,8 +47,7 @@ IConstraint Contains(char compareValue, StringComparison comparison = default) =
/// <returns>
/// The current instance.
/// </returns>
IConstraint Contains(object? compareValue) =>
SetConstraint(new ContainsConstraint(compareValue));
IConstraint Contains(object? compareValue) => SetConstraint(new ContainsConstraint(compareValue));

/// <summary>
/// Appends a constraint that the value contains the specified string.
Expand Down Expand Up @@ -147,9 +142,7 @@ IConstraint Matches(
#if NET7_0_OR_GREATER
[StringSyntax(StringSyntaxAttribute.Regex)]
#endif
string pattern,
RegexOptions? options = null
) => SetConstraint(new MatchesConstraint(pattern, options));
string pattern, RegexOptions? options = null) => SetConstraint(new MatchesConstraint(pattern, options));

/// <summary>
/// Appends a negation operator.
Expand Down Expand Up @@ -186,8 +179,7 @@ IOperator Not
/// <returns>
/// The current instance.
/// </returns>
IConstraint Parenthesis(IConstraint constraint) =>
SetConstraint(new ParenthesisConstraint(constraint));
IConstraint Parenthesis(IConstraint constraint) => SetConstraint(new ParenthesisConstraint(constraint));

/// <summary>
/// Appends a constraint that the value starts with the specified character.
Expand All @@ -198,8 +190,7 @@ IConstraint Parenthesis(IConstraint constraint) =>
/// <returns>
/// The current instance.
/// </returns>
IConstraint StartsWith(char compareValue) =>
SetConstraint(new StartsWithConstraint(compareValue));
IConstraint StartsWith(char compareValue) => SetConstraint(new StartsWithConstraint(compareValue));

/// <summary>
/// Appends a constraint that the value starts with the specified string.
Expand Down
31 changes: 10 additions & 21 deletions src/NetEvolve.FluentValue/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ public static IConstraint Contains(char compareValue, StringComparison compariso
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint Contains(
string compareValue,
StringComparison comparison = default
) => new ContainsConstraint(compareValue, comparison);
public static IConstraint Contains(string compareValue, StringComparison comparison = default) =>
new ContainsConstraint(compareValue, comparison);

/// <summary>
/// Appends a constraint that the value contains a <see langword="object"/>.
Expand All @@ -51,8 +49,7 @@ public static IConstraint Contains(
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint Contains(object? compareValue) =>
new ContainsConstraint(compareValue);
public static IConstraint Contains(object? compareValue) => new ContainsConstraint(compareValue);

/// <summary>
/// Appends a constraint that the value is the default value.
Expand Down Expand Up @@ -87,10 +84,8 @@ public static IConstraint Contains(object? compareValue) =>
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint EndsWith(
string compareValue,
StringComparison comparison = default
) => new EndsWithConstraint(compareValue, comparison);
public static IConstraint EndsWith(string compareValue, StringComparison comparison = default) =>
new EndsWithConstraint(compareValue, comparison);

/// <summary>
/// Appends a constraint that the value is equal to the specified <see langword="object"/>.
Expand Down Expand Up @@ -132,9 +127,7 @@ public static IConstraint EqualTo(string compareValue, StringComparison comparis
/// </returns>
public static IConstraint Matches(
#if NET7_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.StringSyntax(
System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex
)]
[System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex)]
#endif
string pattern,
RegexOptions? options = null
Expand All @@ -159,8 +152,7 @@ public static IConstraint Matches(
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint Parenthesis(IConstraint constraint) =>
new ParenthesisConstraint(constraint);
public static IConstraint Parenthesis(IConstraint constraint) => new ParenthesisConstraint(constraint);

/// <summary>
/// Appends a constraint that the value starts with the specified character.
Expand All @@ -171,8 +163,7 @@ public static IConstraint Parenthesis(IConstraint constraint) =>
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint StartsWith(char compareValue) =>
new StartsWithConstraint(compareValue);
public static IConstraint StartsWith(char compareValue) => new StartsWithConstraint(compareValue);

/// <summary>
/// Appends a constraint that the value starts with the specified string.
Expand All @@ -186,10 +177,8 @@ public static IConstraint StartsWith(char compareValue) =>
/// <returns>
/// The current instance.
/// </returns>
public static IConstraint StartsWith(
string compareValue,
StringComparison comparison = default
) => new StartsWithConstraint(compareValue, comparison);
public static IConstraint StartsWith(string compareValue, StringComparison comparison = default) =>
new StartsWithConstraint(compareValue, comparison);

/// <summary>
/// Appends a constraint that the value is a whitespace character.
Expand Down
33 changes: 6 additions & 27 deletions tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public void Value_MultipleOperators_ThrowsInvalidOperationException() =>

[Fact]
public void Value_Contains_Object_ThrowsNotSupportedException() =>
_ = Assert.Throws<NotSupportedException>(() =>
Value.Contains(new object()).IsSatisfiedBy(new object())
);
_ = Assert.Throws<NotSupportedException>(() => Value.Contains(new object()).IsSatisfiedBy(new object()));

[Theory]
[MemberData(nameof(InvalidConstraintData))]
Expand Down Expand Up @@ -149,33 +147,17 @@ public void Value_Theory_Expected(bool expected, IConstraint constraint, object?
{ true, Value.WhiteSpace, '\n' },
{ false, Value.WhiteSpace, 1 },
// .And Operators
{
false,
Value.Contains("Hello", OrdinalIgnoreCase).And.Contains("Welt!", Ordinal),
"Hello World!"
},
{
true,
Value.Contains("Hello", OrdinalIgnoreCase).And.Contains("World!", Ordinal),
"Hello World!"
},
{ false, Value.Contains("Hello", OrdinalIgnoreCase).And.Contains("Welt!", Ordinal), "Hello World!" },
{ true, Value.Contains("Hello", OrdinalIgnoreCase).And.Contains("World!", Ordinal), "Hello World!" },
// .Or Operators
{ false, Value.Null.Or.Empty, "Hello World!" },
{ true, Value.Null.Or.Empty, null },
{ true, Value.Null.Or.Empty, string.Empty },
// .Xor Operators
{ false, Value.Null.Xor.Empty, "Hello World!" },
{ true, Value.Null.Xor.Empty, string.Empty },
{
false,
Value.Contains("Hello", OrdinalIgnoreCase).Xor.Contains("World!", Ordinal),
"Hello World!"
},
{
true,
Value.Contains("Hello", OrdinalIgnoreCase).Xor.Not.Contains("World!", Ordinal),
"Hello World!"
},
{ false, Value.Contains("Hello", OrdinalIgnoreCase).Xor.Contains("World!", Ordinal), "Hello World!" },
{ true, Value.Contains("Hello", OrdinalIgnoreCase).Xor.Not.Contains("World!", Ordinal), "Hello World!" },
// .Not Operators
{ false, Value.Not.EqualTo(2), "2" },
{ false, Value.Not.EqualTo("Hello World!"), "Hello World!" },
Expand Down Expand Up @@ -247,10 +229,7 @@ public void ToString_Theory_Expected(string expected, IConstraint constraint)
// .WhiteSpace
{ "\"{Value} is <whitespace>.\"", Value.WhiteSpace },
// .And Operators
{
"\"{Value} contains `Hello` and contains `World!`.\"",
Value.Contains("Hello").And.Contains("World!")
},
{ "\"{Value} contains `Hello` and contains `World!`.\"", Value.Contains("Hello").And.Contains("World!") },
// .Or Operators
{ "\"{Value} is <null> or is <empty>.\"", Value.Null.Or.Empty },
// .Not.Null
Expand Down