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
44 changes: 38 additions & 6 deletions src/TestFramework/TestFramework/Assertions/Assert.Matches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,28 @@ public static void MatchesRegex([NotNull] Regex? pattern, [NotNull] string? valu

if (!pattern.IsMatch(value))
{
string userMessage = BuildUserMessageForPatternExpressionAndValueExpression(message, patternExpression, valueExpression);
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsMatchFail, value, pattern, userMessage);
ReportAssertFailed("Assert.MatchesRegex", finalMessage);
ReportAssertMatchesRegexFailed(pattern, value, message, patternExpression, valueExpression);
}
}

[DoesNotReturn]
Comment thread
Evangelink marked this conversation as resolved.
private static void ReportAssertMatchesRegexFailed(Regex pattern, string value, string? userMessage, string patternExpression, string valueExpression)
{
string patternText = AssertionValueRenderer.RenderValue(pattern.ToString());
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("expected pattern:", patternText)
.AddLine("actual:", actualText);

StructuredAssertionMessage structured = new(FrameworkMessages.MatchesRegexFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(patternText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.MatchesRegex", patternExpression, valueExpression, "<pattern>", "<value>"));
Comment thread
Evangelink marked this conversation as resolved.

ReportAssertFailed(structured);
}

/// <summary>
/// Tests whether the specified string MatchesRegex a regular expression and
/// throws an exception if the string does not match the expression.
Expand Down Expand Up @@ -120,12 +136,28 @@ public static void DoesNotMatchRegex([NotNull] Regex? pattern, [NotNull] string?

if (pattern.IsMatch(value))
{
string userMessage = BuildUserMessageForPatternExpressionAndValueExpression(message, patternExpression, valueExpression);
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotMatchFail, value, pattern, userMessage);
ReportAssertFailed("Assert.DoesNotMatchRegex", finalMessage);
ReportAssertDoesNotMatchRegexFailed(pattern, value, message, patternExpression, valueExpression);
}
}

[DoesNotReturn]
private static void ReportAssertDoesNotMatchRegexFailed(Regex pattern, string value, string? userMessage, string patternExpression, string valueExpression)
{
string patternText = AssertionValueRenderer.RenderValue(pattern.ToString());
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("unexpected pattern:", patternText)
.AddLine("actual:", actualText);

StructuredAssertionMessage structured = new(FrameworkMessages.DoesNotMatchRegexFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(patternText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.DoesNotMatchRegex", patternExpression, valueExpression, "<pattern>", "<value>"));
Comment thread
Evangelink marked this conversation as resolved.

ReportAssertFailed(structured);
}

/// <summary>
/// Tests whether the specified string does not match a regular expression
/// and throws an exception if the string MatchesRegex the expression.
Comment thread
Evangelink marked this conversation as resolved.
Expand Down
3 changes: 0 additions & 3 deletions src/TestFramework/TestFramework/Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ private static string BuildUserMessageForExpectedPrefixExpressionAndValueExpress
private static string BuildUserMessageForNotExpectedPrefixExpressionAndValueExpression(string? format, string notExpectedPrefixExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, notExpectedPrefixExpression, "notExpectedPrefix", valueExpression, "value");

private static string BuildUserMessageForPatternExpressionAndValueExpression(string? format, string patternExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, patternExpression, "pattern", valueExpression, "value");

private static string BuildUserMessageForLowerBoundExpressionAndValueExpression(string? format, string lowerBoundExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, lowerBoundExpression, "lowerBound", valueExpression, "value");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,10 @@ Actual: {2}</value>
<data name="IsNotNullFailedSummary" xml:space="preserve">
<value>Expected value to not be null.</value>
</data>
<data name="MatchesRegexFailedSummary" xml:space="preserve">
<value>Expected string to match the specified regular expression.</value>
</data>
<data name="DoesNotMatchRegexFailedSummary" xml:space="preserve">
<value>Expected string to not match the specified regular expression.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">Řetězec „{0}“ končí řetězcem „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Řetězec „{0}“ začíná řetězcem „{1}“. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Skutečnost: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">Die Zeichenfolge „{0}“ endet mit der Zeichenfolge „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Die Zeichenfolge „{0}“ beginnt mit der Zeichenfolge „{1}“. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Tatsächlich: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">La cadena "{0}" termina con la cadena "{1}". {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">La cadena "{0}" comienza con la cadena "{1}". {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Real: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">La chaîne '{0}' se termine par la chaîne '{1}'. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">La chaîne '{0}' commence par la chaîne '{1}'. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Réel : {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">La stringa '{0}' termina con la stringa '{1}'. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">La stringa '{0}' inizia con la stringa '{1}'. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Effettivo: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">文字列 '{0}' の末尾は文字列 '{1}' です。{2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">文字列 '{0}' は文字列 '{1}' で始まります。 {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Actual: {2}</source>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">문자열 '{0}'은 문자열 '{1}'(으)로 끝납니다. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">문자열 '{0}'은 문자열 '{1}'(으)로 시작합니다. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Actual: {2}</source>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">Ciąg „{0}” kończy się ciągiem „{1}”. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Ciąg „{0}” rozpoczyna się od ciągu „{1}”. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Rzeczywiste: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">A cadeia de caracteres “{0}” termina com cadeia de caracteres “{1}”. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">A cadeia de caracteres “{0}” começa com a cadeia de caracteres “{1}”. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Real: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">Строка "{0}" заканчивается строкой "{1}". {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Строка "{0}" начинается со строки "{1}". {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Actual: {2}</source>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">'{0}' dizesi '{1}' dizesi ile bitiyor. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">'{0}' dizesi '{1}' dizesi ile başlıyor. {2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Gerçekte olan: {2}</target>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
<target state="translated">字符串 '{0}' 以字符串 '{1}'结尾。{2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotMatchRegexFailedSummary">
<source>Expected string to not match the specified regular expression.</source>
<target state="new">Expected string to not match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">字符串 '{0}' 以字符串 '{1}' 开头。{2}</target>
Expand Down Expand Up @@ -337,6 +342,11 @@ Actual: {2}</source>
<target state="new">Expected condition to be true.</target>
<note />
</trans-unit>
<trans-unit id="MatchesRegexFailedSummary">
<source>Expected string to match the specified regular expression.</source>
<target state="new">Expected string to match the specified regular expression.</target>
<note />
</trans-unit>
<trans-unit id="PrivateAccessorMemberNotFound">
<source>
The member specified ({0}) could not be found. You might need to regenerate your private accessor,
Expand Down
Loading
Loading