Skip to content

CSHARP-5391: Add spec test for $$type operator with "number" #1739

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 2 commits into from
Jul 23, 2025

Conversation

adelinowona
Copy link
Contributor

No description provided.

@adelinowona adelinowona added the chore Label to hide PR from generated Release Notes label Jul 17, 2025
@adelinowona adelinowona marked this pull request as ready for review July 18, 2025 16:03
@adelinowona adelinowona requested a review from a team as a code owner July 18, 2025 16:03
@adelinowona adelinowona requested review from papafe and sanych-sun and removed request for a team and papafe July 18, 2025 16:03

if (expectedTypes.IsString)
{
expectedTypeNames = new List<string> { expectedTypes.AsString };
var expectedType = expectedTypes.AsString;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of asserting differently in more than one place keep the existing assert at the end of this method and change how expectedTypeNames is computed:

        if (expectedTypes.IsString)
        {
            var expectedType = expectedTypes.AsString;
            expectedTypeNames = expectedType == "number" ? __numericTypes : [expectedType];
        }
        else if (expectedTypes.IsBsonArray)
        {
            expectedTypeNames = expectedTypes.AsBsonArray
                .Select(t => t.AsString)
                .SelectMany(t => t == "number" ? __numericTypes : [t])
                .ToList();
        }
        else
        {
            throw new FormatException($"Unexpected $$type value BsonType: '{expectedTypes.BsonType}'.");
        }

Copy link
Contributor

Choose a reason for hiding this comment

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

I leave it to you to verify that all tests still pass with this proposed refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, does "number" actually ever appear as ONE element of an array?

In the json file you are adding it always appears by itself.

So the changes to the else if part might not actually be needed...

Copy link
Contributor Author

@adelinowona adelinowona Jul 22, 2025

Choose a reason for hiding this comment

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

I decided to also modify the BsonArray case as the "number" value could be used anywhere. Currently there are no instances in our spec tests where it is used as an element of an array but in the future we could have a spec test that uses the "number" value in an array. However, it is untested functionality currently and updating the array use case in the future will be easy so I'll defer it.

@adelinowona adelinowona requested a review from rstam July 22, 2025 17:38
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

LGTM

@adelinowona adelinowona merged commit 23dc1e5 into mongodb:main Jul 23, 2025
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Label to hide PR from generated Release Notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants