-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5793: Map MemoryExtensions Contains and SequenceEqual with null comparer to Enumerable methods with no comparer parameter #1828
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
+50
−43
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e847fe
Handle 3-arg/null versions of MemoryExtensions Contains and SequenceE…
damieng 95ce2a9
Alternative approach based on PR review.
damieng 522d48e
Move IsOneOf args to a static readonly to avoid new array alloc per c…
damieng 56dc0b5
Update src/MongoDB.Driver/Linq/Linq3Implementation/Translators/Expres…
damieng dac4bbd
Update src/MongoDB.Driver/Linq/Linq3Implementation/Translators/Expres…
damieng 4dad79f
Update tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CShar…
damieng 368eeae
Clarify private static field name.
damieng b380d62
Depluralize internal and test method names.
damieng a19fb9e
CSHARP-5793: Requested changes submitted as a commit to save you work
rstam 5f4f07e
CSHARP-5793: Reject all suggested changes and revert to original commit
rstam 73ebfbc
CSHARP-5793: Carry forward one minor change from rejected commits
rstam 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,20 @@ public void MemoryExtensions_Contains_in_Where_should_work() | |
| results.Select(x => x.Id).Should().Equal(2, 3); | ||
| } | ||
|
|
||
| [Fact] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new tests are fine. I would also add these new tests:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| public void MemoryExtensions_Contains_in_Where_should_work_with_enum() | ||
| { | ||
| var collection = Fixture.Collection; | ||
| var daysOfWeek = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday }; | ||
|
|
||
| // Can't actually rewrite/fake these with MemoryExtensions.Contains overload with 3 args from .NET 10 | ||
| // This test will activate correctly on .NET 10+ | ||
| var queryable = collection.AsQueryable().Where(x => daysOfWeek.Contains(x.Day)); | ||
|
|
||
| var results = queryable.ToArray(); | ||
| results.Select(x => x.Id).Should().Equal(2, 3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MemoryExtensions_Contains_in_Single_should_work() | ||
| { | ||
|
|
@@ -93,6 +107,20 @@ public void MemoryExtensions_SequenceEqual_in_Where_should_work() | |
| results.Select(x => x.Id).Should().Equal(3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MemoryExtensions_SequenceEqual_in_Where_should_work_with_enum() | ||
| { | ||
| var collection = Fixture.Collection; | ||
| var daysOfWeek = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday }; | ||
|
|
||
| // Can't actually rewrite/fake these with MemoryExtensions.Contains overload with 3 args from .NET 10 | ||
damieng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // This test will activate correctly on .NET 10+ | ||
| var queryable = collection.AsQueryable().Where(x => daysOfWeek.SequenceEqual(x.Days)); | ||
|
|
||
| var results = queryable.ToArray(); | ||
| results.Select(x => x.Id).Should().Equal(1); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MemoryExtensions_SequenceEqual_in_Single_should_work() | ||
| { | ||
|
|
@@ -129,17 +157,19 @@ public void MemoryExtensions_SequenceEqual_in_Count_should_work() | |
| public class C | ||
| { | ||
| public int Id { get; set; } | ||
| public DayOfWeek Day { get; set; } | ||
| public string Name { get; set; } | ||
| public int[] Ratings { get; set; } | ||
| public DayOfWeek[] Days { get; set; } | ||
| } | ||
|
|
||
| public sealed class ClassFixture : MongoCollectionFixture<C, BsonDocument> | ||
| { | ||
| protected override IEnumerable<BsonDocument> InitialData => | ||
| [ | ||
| BsonDocument.Parse("{ _id : 1, Name : \"One\", Ratings : [1, 2, 3, 4, 5] }"), | ||
| BsonDocument.Parse("{ _id : 2, Name : \"Two\", Ratings : [3, 4, 5, 6, 7] }"), | ||
| BsonDocument.Parse("{ _id : 3, Name : \"Three\", Ratings : [1, 9, 6] }") | ||
| BsonDocument.Parse("{ _id : 1, Name : \"One\", Day : 0, Ratings : [1, 2, 3, 4, 5], Days : [1, 2] }"), | ||
| BsonDocument.Parse("{ _id : 2, Name : \"Two\", Day : 1, Ratings : [3, 4, 5, 6, 7], Days: [1, 2, 3] }"), | ||
| BsonDocument.Parse("{ _id : 3, Name : \"Three\", Day : 2, Ratings : [1, 9, 6], Days: [2, 3, 4] }") | ||
| ]; | ||
| } | ||
|
|
||
|
|
@@ -175,10 +205,13 @@ static Expression VisitContainsMethod(MethodCallExpression node, MethodInfo meth | |
| if (source.Type.IsArray) | ||
| { | ||
| var readOnlySpan = ImplicitCastArrayToSpan(source, typeof(ReadOnlySpan<>), itemType); | ||
| return | ||
| Expression.Call( | ||
| MemoryExtensionsMethod.ContainsWithReadOnlySpanAndValue.MakeGenericMethod(itemType), | ||
| [readOnlySpan, value]); | ||
|
|
||
| // Not worth checking for IEquatable<T> and generating 3 args overload as that requires .NET 10 | ||
| // which if we had we could run the tests on natively without this visitor. | ||
|
|
||
| return Expression.Call( | ||
| MemoryExtensionsMethod.ContainsWithReadOnlySpanAndValue.MakeGenericMethod(itemType), | ||
| [readOnlySpan, value]); | ||
| } | ||
| } | ||
| else if (method.Is(EnumerableMethod.ContainsWithComparer)) | ||
|
|
||
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.