Skip to content

CSHARP-5966 Add support of string.TrimStart and TrimEnd methods to SerializerFinder#1953

Open
kyra-rk wants to merge 6 commits intomongodb:mainfrom
kyra-rk:csharp-5966
Open

CSHARP-5966 Add support of string.TrimStart and TrimEnd methods to SerializerFinder#1953
kyra-rk wants to merge 6 commits intomongodb:mainfrom
kyra-rk:csharp-5966

Conversation

@kyra-rk
Copy link
Copy Markdown
Contributor

@kyra-rk kyra-rk commented Apr 15, 2026

No description provided.

@kyra-rk kyra-rk requested a review from sanych-sun April 15, 2026 18:36
@kyra-rk kyra-rk added the bug Fixes issues or unintended behavior. label Apr 15, 2026
@kyra-rk
Copy link
Copy Markdown
Contributor Author

kyra-rk commented Apr 15, 2026

(will keep open until next week, once 3.8 is released)

@kyra-rk kyra-rk marked this pull request as ready for review April 15, 2026 19:50
@kyra-rk kyra-rk requested a review from a team as a code owner April 15, 2026 19:50
Copilot AI review requested due to automatic review settings April 15, 2026 19:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds LINQ3 serializer-finder support for string.TrimStart/TrimEnd so these method calls can be translated with the correct string serializer, and validates behavior with unit + integration tests.

Changes:

  • Extend SerializerFinderVisitor method-call handling to recognize TrimStart and TrimEnd.
  • Expand serializer-finder string method coverage to include TrimStart(char[]) and TrimEnd(char[]).
  • Add a Jira integration test validating translation to $ltrim / $rtrim and expected results.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/StringTests.cs Adds serializer-finder coverage for TrimStart/TrimEnd returning StringSerializer.
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5966Tests.cs New integration tests validating $ltrim/$rtrim translation and runtime results.
src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs Routes TrimStart/TrimEnd method calls through existing trim serializer deduction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5966Tests.cs Outdated
Comment thread tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5966Tests.cs Outdated

public class CSharp5966Tests : LinqIntegrationTest<CSharp5966Tests.ClassFixture>
{
public CSharp5966Tests(ClassFixture fixture)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's technically outside of the ticket scope, but if we are adding integration tests for TrimStart and TrimEnd methods, let's use the "newly suggested approach" instead of Jira-Ticket-number class name. We can discuss the pros and cons of both approaches tomorrow after stand up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'm not sure what you mean by newer approach, so will wait to do this after we chat

[TestHelpers.MakeLambda((MyModel model) => model.Name.ToUpperInvariant()), typeof(StringSerializer)],
[TestHelpers.MakeLambda((MyModel model) => model.Name.Trim()), typeof(StringSerializer)],
[TestHelpers.MakeLambda((MyModel model) => model.Name.Trim(new char[] { ' ' })), typeof(StringSerializer)],
[TestHelpers.MakeLambda((MyModel model) => model.Name.TrimStart(new char[] { ' ' })), typeof(StringSerializer)],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add parameter-less methods as non-supported, probably together with the link to Jira ticket where we will implement them. Example of negative tests could be find here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the team usually link the Jira ticket? In Server it would have been something like // TODO CSHARP-5979 Make these tests supported, but the closest example I found was:

// https://jira.mongodb.org/browse/CSHARP-2678
if (IsRetryableWriteExceptionAndDeploymentDoesNotSupportRetryableWrites(exception))
{ 
    ....
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, iirc they had a PR-level check for any remaining TODO SERVER-XXXX tickets matching the ticket name. Not sure if the team has something like this already, or if might be worth trying

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I put comment something like:

Not supported yet, see https://jira.mongodb.org/browse/CSHARP-2678

@kyra-rk kyra-rk requested a review from sanych-sun April 16, 2026 14:46
Copy link
Copy Markdown
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. 1 comment + please investigate the failed unit test on net472. It's interesting case :). Reach me out if you need some clues and directions.


public class TrimTests : LinqIntegrationTest<TrimTests.ClassFixture>
{
public TrimTests(ClassFixture fixture)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to StringTrimTests.

@kyra-rk
Copy link
Copy Markdown
Contributor Author

kyra-rk commented Apr 17, 2026

Almost there. 1 comment + please investigate the failed unit test on net472. It's interesting case :). Reach me out if you need some clues and directions.

Ahhh, seems like Trim(' '), TrimStart() and TrimEnd() were all added in .Net Core/Standard 2.1 onwards and the compiler was matching these to the Trim(params char[]) version. I just pushed a fix, but waiting to see if the evg patch is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants