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
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 @@ -46,12 +46,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 @@ -124,12 +140,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 @@ -275,9 +275,6 @@ private static string BuildUserMessageForTwoExpressions(string? format, string c
private static string BuildUserMessageForCollectionExpression(string? format, string collectionExpression)
=> BuildUserMessageForSingleExpression(format, collectionExpression, "collection");

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

private static string BuildUserMessageForExpectedExpressionAndActualExpression(string? format, string expectedExpression, string actualExpression)
=> BuildUserMessageForTwoExpressions(format, expectedExpression, "expected", actualExpression, "actual");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ 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>
<data name="ContainsSingleFailedSummary" xml:space="preserve">
<value>Expected collection to contain exactly one element.</value>
</data>
Expand Down
143 changes: 139 additions & 4 deletions src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,111 @@
<target state="translated">Očekávaná délka řetězce je {0}, ale byla {1}.</target>
<note></note>
</trans-unit>
<trans-unit id="AreEquivalentFailedSummary">
<source>Expected values to be structurally equivalent.</source>
<target state="new">Expected values to be structurally equivalent.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentFailedSummaryStrict">
<source>Expected values to be structurally equivalent (strict mode).</source>
<target state="new">Expected values to be structurally equivalent (strict mode).</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchActualDictionaryThrew">
<source>reading the actual dictionary threw {0}: {1}.</source>
<target state="new">reading the actual dictionary threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchActualEnumerationThrew">
<source>enumerating the actual collection threw {0}: {1}.</source>
<target state="new">enumerating the actual collection threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchActualMemberThrew">
<source>reading the actual member threw {0}: {1}.</source>
<target state="new">reading the actual member threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchAt">
<source>Mismatch at '{0}': {1}</source>
<target state="new">Mismatch at '{0}': {1}</target>
<note>{0} is a member path (e.g., 'Order.Items[2].Price'), {1} is a localized reason describing the kind of mismatch.</note>
</trans-unit>
<trans-unit id="AreEquivalentMismatchExpectedDictionaryThrew">
<source>reading the expected dictionary threw {0}: {1}.</source>
<target state="new">reading the expected dictionary threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchExpectedEnumerationThrew">
<source>enumerating the expected collection threw {0}: {1}.</source>
<target state="new">enumerating the expected collection threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchExpectedMemberThrew">
<source>reading the expected member threw {0}: {1}.</source>
<target state="new">reading the expected member threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchExtraMembers">
<source>actual has unexpected members not present on expected: {0}.</source>
<target state="new">actual has unexpected members not present on expected: {0}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchIEquatableThrew">
<source>IEquatable.Equals threw {0}: {1}.</source>
<target state="new">IEquatable.Equals threw {0}: {1}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchLength">
<source>collections differ in length (expected {0} elements, actual {1}).</source>
<target state="new">collections differ in length (expected {0} elements, actual {1}).</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchMaxDepth">
<source>comparison exceeded the maximum supported depth of {0}.</source>
<target state="new">comparison exceeded the maximum supported depth of {0}.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchMissingKey">
<source>key {0} present on expected is missing from actual.</source>
<target state="new">key {0} present on expected is missing from actual.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchMissingMember">
<source>member '{0}' present on expected is missing from actual.</source>
<target state="new">member '{0}' present on expected is missing from actual.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchNull">
<source>one side is null, the other is not.</source>
<target state="new">one side is null, the other is not.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchTopology">
<source>graph topology differs (the same reference on one side appears paired with different references on the other side).</source>
<target state="new">graph topology differs (the same reference on one side appears paired with different references on the other side).</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchType">
<source>incompatible types (expected '{0}', actual '{1}').</source>
<target state="new">incompatible types (expected '{0}', actual '{1}').</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchUnexpectedKey">
<source>key {0} present on actual is not on expected.</source>
<target state="new">key {0} present on actual is not on expected.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentMismatchValue">
<source>values are not equal.</source>
<target state="new">values are not equal.</target>
<note />
</trans-unit>
<trans-unit id="AreEquivalentRootPath">
<source>&lt;root&gt;</source>
<target state="new">&lt;root&gt;</target>
<note>Placeholder used in equivalence-mismatch messages when the difference is at the top of the object graph.</note>
</trans-unit>
<trans-unit id="AreNotEqualFailMsg">
<source>Expected any value except:&lt;{1}&gt;. Actual:&lt;{2}&gt;. {0}</source>
<target state="translated">Nebyla očekávána žádná hodnota kromě:&lt;{1}&gt;. Aktuálně:&lt;{2}&gt;. {0}</target>
Expand All @@ -78,6 +183,26 @@
<target state="translated">Očekáván rozdíl, který je větší jak &lt;{3}&gt; mezi očekávanou hodnotou &lt;{1}&gt; a aktuální hodnotou &lt;{2}&gt;. {0}</target>
<note></note>
</trans-unit>
<trans-unit id="AreNotEquivalentComparisonFailedSummary">
<source>Could not complete structural comparison.</source>
<target state="new">Could not complete structural comparison.</target>
<note />
</trans-unit>
<trans-unit id="AreNotEquivalentComparisonFailedSummaryStrict">
<source>Could not complete structural comparison (strict mode).</source>
<target state="new">Could not complete structural comparison (strict mode).</target>
<note />
</trans-unit>
<trans-unit id="AreNotEquivalentFailedSummary">
<source>Expected values to be structurally different.</source>
<target state="new">Expected values to be structurally different.</target>
<note />
</trans-unit>
<trans-unit id="AreNotEquivalentFailedSummaryStrict">
<source>Expected values to be structurally different (strict mode).</source>
<target state="new">Expected values to be structurally different (strict mode).</target>
<note />
</trans-unit>
<trans-unit id="AreNotSameBothNull">
<source>Both values are &lt;null&gt;. {0}</source>
<target state="translated">Obě hodnoty jsou &lt;null&gt;. {0}</target>
Expand Down Expand Up @@ -248,6 +373,11 @@
<target state="new">Expected string to not end with the specified suffix.</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 @@ -329,7 +459,7 @@ Skutečnost: {2}</target>
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="translated">Očekávala se podmínka false.</target>
<target state="new">Expected condition to be false.</target>
<note />
</trans-unit>
<trans-unit id="IsGreaterThanFailedSummary">
Expand Down Expand Up @@ -409,12 +539,12 @@ Skutečnost: {2}</target>
</trans-unit>
<trans-unit id="IsNotNullFailedSummary">
<source>Expected value to not be null.</source>
<target state="translated">Očekávaná hodnota nesmí být null.</target>
<target state="new">Expected value to not be null.</target>
<note />
</trans-unit>
<trans-unit id="IsNullFailedSummary">
<source>Expected value to be null.</source>
<target state="translated">Očekávaná hodnota bude null.</target>
<target state="new">Expected value to be null.</target>
<note />
</trans-unit>
<trans-unit id="IsPositiveFailedSummary">
Expand All @@ -424,7 +554,12 @@ Skutečnost: {2}</target>
</trans-unit>
<trans-unit id="IsTrueFailedSummary">
<source>Expected condition to be true.</source>
<target state="translated">Očekávala se podmínka true.</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">
Expand Down
Loading
Loading