Repository navigation
fix: bind a tuple row whole to a tuple parameter followed by optional parameters #7341
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,23 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests; | ||
|
|
||
| /// <summary> | ||
| /// A tuple row binds whole to a tuple parameter followed by optional or params parameters (#7212). | ||
| /// </summary> | ||
| public class Issue7212Tests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| [Test] | ||
| public async Task Tuple_Parameter_Followed_By_Optional_Parameters_Binds_Whole() | ||
| { | ||
| await RunTestsWithFilter( | ||
| "/*/TUnit.TestProject.Bugs._7212/*/*", | ||
| [ | ||
| result => result.ResultSummary.Outcome.ShouldBe("Completed"), | ||
| result => result.ResultSummary.Counters.Total.ShouldBe(8), | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(8), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(0) | ||
| ]); | ||
| } | ||
| } |
94 changes: 94 additions & 0 deletions
94
tests/TUnit.TestProject/Bugs/_7212/TupleParameterWithOptionalParameterTests.cs
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,94 @@ | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7212; | ||
|
|
||
| /// <summary> | ||
| /// A row whose single value is a tuple of the first data parameter's type binds to that parameter | ||
| /// whole, and the remaining optional or params parameters take their defaults, in both | ||
| /// source-generated and reflection mode (#7212). | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class TupleParameterWithOptionalParameterTests | ||
| { | ||
| public static IEnumerable<object[]> TupleRows() | ||
| { | ||
| yield return [(25, 26)]; | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> TupleAndValueRows() | ||
| { | ||
| yield return [(25, 26), 7]; | ||
| } | ||
|
|
||
| public static IEnumerable<((int, int), int)> NestedTupleRows() | ||
| { | ||
| yield return ((25, 26), 7); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Tuple_And_Optional((int, int) pair, int extra = 5) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(5); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Tuple_And_Two_Optionals((int, int) pair, int extra = 5, string name = "default") | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(5); | ||
| await Assert.That(name).IsEqualTo("default"); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Tuple_Optional_And_Token((int, int) pair, int extra = 5, CancellationToken token = default) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(5); | ||
| await Assert.That(token.CanBeCanceled).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Token_Tuple_And_Optional(CancellationToken token, (int, int) pair, int extra = 5) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(5); | ||
| await Assert.That(token.CanBeCanceled).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Tuple_And_Params((int, int) pair, params int[] rest) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(rest).IsEmpty(); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleRows))] | ||
| public async Task Tuple_And_Params_Collection((int, int) pair, params IEnumerable<int> rest) | ||
|
thomhurst marked this conversation as resolved.
Resolved
|
||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(rest).IsEmpty(); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(TupleAndValueRows))] | ||
| public async Task Tuple_And_Supplied_Optional((int, int) pair, int extra = 5) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(7); | ||
| } | ||
|
|
||
| [Test] | ||
| [MethodDataSource(nameof(NestedTupleRows))] | ||
| public async Task Nested_Tuple_Row_Is_Spread((int, int) pair, int extra = 5) | ||
| { | ||
| await Assert.That(pair).IsEqualTo((25, 26)); | ||
| await Assert.That(extra).IsEqualTo(7); | ||
| } | ||
| } | ||
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.