-
-
Notifications
You must be signed in to change notification settings - Fork 132
Fix Type assignability assertions to evaluate represented type (not RuntimeType)
#6711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+436
−8
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
11525b4
Initial plan
Copilot 38b97aa
Fix Type assignability assertions for Type values
Copilot 2ae67b7
fix(assertions): preserve represented Type
thomhurst 8e58dc6
fix(assertions): keep generic type semantics
thomhurst 1e7bda7
fix(assertions): align Type assignability
thomhurst ddf953c
fix(assertions): preserve generic return value
thomhurst c8eebf7
fix(assertions): scope represented type checks
thomhurst 8f653af
fix(assertions): prioritize Type overload
thomhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| using TUnit.Assertions.Conditions; | ||
| using TUnit.Assertions.Core; | ||
|
|
||
| namespace TUnit.Assertions.Sources; | ||
|
|
||
| /// <summary> | ||
| /// Source assertion for represented types. | ||
| /// </summary> | ||
| public sealed class TypeValueAssertion : ValueAssertion<Type> | ||
| { | ||
| public TypeValueAssertion(Type? value, string? expression) | ||
| : base(value, expression) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the represented type is assignable to <typeparamref name="TTarget"/>. | ||
| /// The assertion retains the represented <see cref="Type"/> for awaiting and chaining. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Represented-type semantics apply only when this is the first assertion after <c>Assert.That(type)</c>. | ||
| /// After <c>.And</c> or <c>.Or</c>, assignability assertions inspect the runtime type instead. | ||
| /// </remarks> | ||
| public new TypeIsAssignableToAssertion<TTarget> IsAssignableTo<TTarget>() | ||
| { | ||
| Context.ExpressionBuilder.Append($".IsAssignableTo<{typeof(TTarget).Name}>()"); | ||
| return new TypeIsAssignableToAssertion<TTarget>(Context); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the represented type is not assignable to <typeparamref name="TTarget"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Represented-type semantics apply only when this is the first assertion after <c>Assert.That(type)</c>. | ||
| /// After <c>.And</c> or <c>.Or</c>, assignability assertions inspect the runtime type instead. | ||
| /// </remarks> | ||
| public new IsNotAssignableToAssertion<TTarget, Type> IsNotAssignableTo<TTarget>() | ||
| { | ||
| Context.ExpressionBuilder.Append($".IsNotAssignableTo<{typeof(TTarget).Name}>()"); | ||
| return new IsNotAssignableToAssertion<TTarget, Type>(Context, useRepresentedType: true); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that <typeparamref name="TSource"/> is assignable to the represented type. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Represented-type semantics apply only when this is the first assertion after <c>Assert.That(type)</c>. | ||
| /// After <c>.And</c> or <c>.Or</c>, assignability assertions inspect the runtime type instead. | ||
| /// </remarks> | ||
| public new IsAssignableFromAssertion<TSource, Type> IsAssignableFrom<TSource>() | ||
| { | ||
| Context.ExpressionBuilder.Append($".IsAssignableFrom<{typeof(TSource).Name}>()"); | ||
| return new IsAssignableFromAssertion<TSource, Type>(Context, useRepresentedType: true); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that <typeparamref name="TSource"/> is not assignable to the represented type. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Represented-type semantics apply only when this is the first assertion after <c>Assert.That(type)</c>. | ||
| /// After <c>.And</c> or <c>.Or</c>, assignability assertions inspect the runtime type instead. | ||
| /// </remarks> | ||
| public new IsNotAssignableFromAssertion<TSource, Type> IsNotAssignableFrom<TSource>() | ||
| { | ||
| Context.ExpressionBuilder.Append($".IsNotAssignableFrom<{typeof(TSource).Name}>()"); | ||
| return new IsNotAssignableFromAssertion<TSource, Type>(Context, useRepresentedType: true); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.