Add specific tests for {RO}Span.IndexOfAny<char>#32069
Conversation
| } | ||
|
|
||
| [Fact] | ||
| public static void DefaultFilledIndexOfTwo_Char() |
There was a problem hiding this comment.
I'm not sure what is this test testing.
There was a problem hiding this comment.
Not entirely sure either, copied it from the byte variant
There was a problem hiding this comment.
Yep, can't make sense of it anymore. I will have to dig up what the test used to be.
I think the intention was to look for (default, x) and (x, default) in a span containing only default, and assert we always find it at the first index.
Therefore, the inner loop is unnecessary, at least the way the test is written atm:
for (int i = 0; i < length; i++)
It should just be single check. The test should look like this:
for (int length = 0; length < byte.MaxValue; length++)
{
byte[] a = new byte[length];
Span<byte> span = new Span<byte>(a);
int idx = span.IndexOfAny(default, 99);
Assert.Equal(0, idx);
idx = span.IndexOfAny(99, default);
Assert.Equal(0, idx);
}We can leave it as is for now and fix all the tests (byte/char/etc.) in one go outside of this PR.
Edit:
I will have to dig up what the test used to be.
Found where it originated: #17472
The loop didn't make sense then either. My recommendation above holds.
|
@dotnet-bot test UWP CoreCLR x64 Debug Build |
|
Raised issue for UWP failure https://github.com/dotnet/corefx/issues/32083 |
|
@ahsonkhan is this good to merge now? |
|
@danmosemsft you triggered a rebuild with your comment, looks like infra not happy |
|
@dotnet-bot test NETFX x86 Release Build |
|
@mmitche why do random comments sometimes trigger rebuilds? |
|
@danmosemsft The comment triggers a jenkins webhook, which causes it to compare the last built sha against the current sha. That may not be up to date, and it may cause a rebuild. Jenkins also forgets that info over time (as builds are deleted, restarts, etc.) which makes a rebuild for an old PR more likely. |
I haven't gotten a chance to fully review all the tests yet, but does this PR need to wait for dotnet/coreclr#19790 to get merged first? |
No; its just a copying of the |
|
@dotnet-bot test this please |
| byte[] searchForBytes = Encoding.UTF8.GetBytes(searchFor); | ||
|
|
||
| var index = -1; | ||
| var index = span.IndexOfAny(new ReadOnlySpan<byte>(searchForBytes)); |
There was a problem hiding this comment.
Nit: var => int (I realize it was like that before... but it shouldn't have been :)
| { | ||
| byte[] buffers = Encoding.UTF8.GetBytes(raw); | ||
| var span = new ReadOnlySpan<byte>(buffers); | ||
| ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(buffers); |
There was a problem hiding this comment.
FWIW, this was fine as var. Our guidelines just outlaw it when the type isn't named on the RHS, which generally means something other than a new or a cast. But naming it in such situations is fine, too.
|
@ahsonkhan, anything more to do here? |
|
UWP infra issue |
|
@dotnet-bot test UWP NETNative x86 Release Build |
* Add specific tests for {RO}Span.IndexOfAny<char>
* Always test using IndexOfAny(ROS)
* No var
* Less var
Commit migrated from dotnet/corefx@bfcfd34
Supporting dotnet/coreclr#19790
/cc @krwq