Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

improve span.StartsWith(span) test coverage#41169

Merged
adamsitnik merged 1 commit intodotnet:masterfrom
adamsitnik:spanStringTests
Sep 18, 2019
Merged

improve span.StartsWith(span) test coverage#41169
adamsitnik merged 1 commit intodotnet:masterfrom
adamsitnik:spanStringTests

Conversation

@adamsitnik
Copy link
Member

I just wanted to make sure that span.StartsWith(span) has the same test coverage as string.StartsWith(string)

Assert.Equal(
firstSpan.ToString().StartsWith(secondSpan.ToString(), StringComparison.CurrentCulture),
firstSpan.Contains(secondSpan, StringComparison.CurrentCulture));
firstSpan.ToString().StartsWith(secondSpan.ToString(), StringComparison.CurrentCultureIgnoreCase),
Copy link
Member Author

@adamsitnik adamsitnik Sep 18, 2019

Choose a reason for hiding this comment

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

this was a copy-paste error (so far StringComparison.CurrentCulture was tested twice)

firstSpan.ToString().StartsWith(secondSpan.ToString(), StringComparison.CurrentCulture),
firstSpan.Contains(secondSpan, StringComparison.CurrentCulture));
firstSpan.ToString().StartsWith(secondSpan.ToString(), StringComparison.CurrentCultureIgnoreCase),
firstSpan.Contains(secondSpan, StringComparison.CurrentCultureIgnoreCase));
Copy link
Member

Choose a reason for hiding this comment

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

As long as you're fixing this, can you instead make it something like:

Assert.All(
    new[] { StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCulture, StringComparison.InvariantCultureIgnoreCase },
    comparison =>
    {
        Assert.Equal(
            firstSpan.ToString().StartsWith(secondSpan.ToString(), comparison),
            firstSpan.Contains(secondSpan, comparison));
    });

?
That reduces the amount of code here, makes it clearer what's being tested, and helps to avoid such copy/paste issues.

@adamsitnik adamsitnik merged commit b8d1e06 into dotnet:master Sep 18, 2019
@adamsitnik adamsitnik deleted the spanStringTests branch September 18, 2019 15:47
@karelz karelz added this to the 5.0 milestone Dec 19, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants