Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change: Add DoesNotMatch assertion to DoesNotExtensions_String
  • Loading branch information
AnnaSasDev committed May 1, 2025
commit dcd212b1c9de6821bb50f5980215c94d49aeb97c
18 changes: 0 additions & 18 deletions TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,4 @@ public static InvokableValueAssertionBuilder<string> Matches(this IValueSource<s
$"match {expression}")
, [expression]);
}

public static InvokableValueAssertionBuilder<string> DoesNotMatch(this IValueSource<string> valueSource, string regex, [CallerArgumentExpression(nameof(regex))] string expression = "")
{
return DoesNotMatch(valueSource, new Regex(regex), expression);
}

public static InvokableValueAssertionBuilder<string> DoesNotMatch(this IValueSource<string> valueSource, Regex regex, [CallerArgumentExpression(nameof(regex))] string expression = "")
{
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, Regex>(regex,
(actual, _, _) =>
{
Verify.ArgNotNull(actual);
return !regex.IsMatch(actual);
},
(actual, _, _) => $"The regex \"{regex}\" matches with \"{actual}\"",
$"does not match with {expression}")
, [expression]);
}
}
19 changes: 19 additions & 0 deletions TUnit.Assertions/Assertions/Strings/DoesNotExtensions_String.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable

using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Interfaces;
using TUnit.Assertions.AssertConditions.String;
Expand Down Expand Up @@ -57,4 +58,22 @@ public static InvokableValueAssertionBuilder<string> DoesNotEndWith(this IValueS
$"not end with {expected}")
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);
}

public static InvokableValueAssertionBuilder<string> DoesNotMatch(this IValueSource<string> valueSource, string regex, [CallerArgumentExpression(nameof(regex))] string expression = "")
{
return DoesNotMatch(valueSource, new Regex(regex), expression);
}

public static InvokableValueAssertionBuilder<string> DoesNotMatch(this IValueSource<string> valueSource, Regex regex, [CallerArgumentExpression(nameof(regex))] string expression = "")
{
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, Regex>(regex,
(actual, _, _) =>
{
Verify.ArgNotNull(actual);
return !regex.IsMatch(actual);
},
(actual, _, _) => $"The regex \"{regex}\" matches with \"{actual}\"",
$"does not match with {expression}")
, [expression]);
}
}