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

Test StringComparer.FromComparison#14623

Closed
AlexRadch wants to merge 10 commits into
dotnet:masterfrom
AlexRadch:StringComparerTests-FromComparisonTest
Closed

Test StringComparer.FromComparison#14623
AlexRadch wants to merge 10 commits into
dotnet:masterfrom
AlexRadch:StringComparerTests-FromComparisonTest

Conversation

@AlexRadch
Copy link
Copy Markdown

Add API to convert a StringComparison to a StringComparer, to avoid bunch of switch-statements in user code (see 'Motivation' section below).
See https://github.com/dotnet/corefx/issues/13800 and dotnet/coreclr#8633

@AlexGhiondea
Copy link
Copy Markdown
Contributor

@AlexRadch the tests look good but they are currently failing because we haven't yet moved to a CoreCLR version that has those new methods.

@AlexGhiondea
Copy link
Copy Markdown
Contributor

@AlexRadch thanks for doing this!

@justinvp
Copy link
Copy Markdown
Contributor

The API needs to be exposed in the contract by adding it to src/System.Runtime.Extensions/ref/System.Runtime.Extensions.cs within #if netcoreapp11.

Also, instead of adding the tests to StringComparer.netstandard1.7.cs, a new file (e.g. StringComparer.netcoreapp1.1.cs) should be created that is conditionally included for netcoreapp11, and the tests should be added there.

Assert.Equal(0, StringComparer.InvariantCultureIgnoreCase.Compare("test", "TEST"));
}

public static IEnumerable<object[]> FromComparison_TestData()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Could be simplified slightly, e.g.:

public static readonly object[][] FromComparison_TestData =
{
    new object[] { StringComparison.CurrentCulture, StringComparer.CurrentCulture },
    new object[] { StringComparison.CurrentCultureIgnoreCase, StringComparer.CurrentCultureIgnoreCase },
    ...
};

@justinvp
Copy link
Copy Markdown
Contributor

justinvp commented Dec 19, 2016

Another test should be added that ensures ArgumentException is thrown for invalid StringComparison values.

public static System.StringComparer Ordinal { get { throw null; } }
public static System.StringComparer OrdinalIgnoreCase { get { throw null; } }
#if netcoreapp11
public static System.StringComparer FromComparison(System.StringComparison comparison) { throw null; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The parameter should be named comparisonType

{
public static object[][] FromComparison_TestData()
{
return new object[][] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My suggestion was to turn this into a static read only field, instead of a method. Then you won't need the return statement.

public static readonly object[][] FromComparison_TestData =
{
    new object[] { StringComparison.CurrentCulture, StringComparer.CurrentCulture },
    new object[] { StringComparison.CurrentCultureIgnoreCase, StringComparer.CurrentCultureIgnoreCase },
    // etc.
};

public static object[][] FromComparison_TestData()
{
return new object[][] {
// StringComparison StringComparer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I'd just remove this comment

{
public static partial class MiscStringComparerTests
{
public static object[][] FromComparison_TestData = new object[][] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: The field should be readonly and new object[][] is unnecessary and can be removed.

StringComparison maxInvalid = Enum.GetValues(typeof(StringComparison)).Cast<StringComparison>().Max() + 1;

Assert.Throw<ArgumentException>(() => { StringComparer.FromComparison(minInvalid); });
Assert.Throw<ArgumentException>(() => { StringComparer.FromComparison(maxInvalid); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These should be Assert.Throws<ArgumentException> (Throws plural).

Also, the brackets aren't needed, they can be written as:

Assert.Throws<ArgumentException>(() => StringComparer.FromComparison(minInvalid));
Assert.Throws<ArgumentException>(() => StringComparer.FromComparison(maxInvalid));

StringComparison maxInvalid = Enum.GetValues(typeof(StringComparison)).Cast<StringComparison>().Max() + 1;

Assert.Throw<ArgumentException>(() => StringComparer.FromComparison(minInvalid));
Assert.Throw<ArgumentException>(() => StringComparer.FromComparison(maxInvalid));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Throws. The name of the xunit method is "Throws" with an "s" at the end, not "Throw".

{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}.netstandard1.7_Debug|Any CPU.ActiveCfg = net461_Release|Any CPU
{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}.netstandard1.7_Debug|Any CPU.Build.0 = net461_Release|Any CPU
{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}.netstandard1.7_Release|Any CPU.ActiveCfg = net461_Release|Any CPU
{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}.netstandard1.7_Release|Any CPU.Build.0 = net461_Release|Any CPU
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are the changes in this file necessary?

Copy link
Copy Markdown
Author

@AlexRadch AlexRadch Dec 20, 2016

Choose a reason for hiding this comment

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

I think No. I will remove this. My VS created this.

@danmoseley
Copy link
Copy Markdown
Member

@dotnet-bot test this (logs gone)

@danmoseley
Copy link
Copy Markdown
Member

@mmitche the results all just have

Problem accessing /job/dotnet_corefx/job/master/job/centos7.1_debug_prtest/1560/. Reason:

    Not Found

Any ideas? Perhaps it just didn't rerun them for some reason. I'll try open/close to do it.

@danmoseley
Copy link
Copy Markdown
Member

It says the type is not there. Maybe it just arrived.
@dotnet-bot test this please

@danmoseley
Copy link
Copy Markdown
Member

@dotnet-bot test this (logs gone)

@danmoseley
Copy link
Copy Markdown
Member

@mmitche the request to retest apparently didn't work as there are still no logs.

@mmitche
Copy link
Copy Markdown
Member

mmitche commented Jan 3, 2017

@dotnet-bot test this please

@mmitche
Copy link
Copy Markdown
Member

mmitche commented Jan 3, 2017

@danmosemsft Looks like the phrase is actually test this pease (spelled correctly) not just test this

@danmoseley
Copy link
Copy Markdown
Member

@dotnet-bot help

@dotnet-bot
Copy link
Copy Markdown

Welcome to the dotnet/corefx Repository

The following is a list of valid commands on this PR. To invoke a command, comment the indicated phrase on the PR

The following commands are valid for all PRs and repositories.

Comment Phrase Action
@dotnet-bot test this please Re-run all legs. Use sparingly
@dotnet-bot test ci please Generates (but does not run) jobs based on changes to the groovy job definitions in this branch
@dotnet-bot help Print this help message

The following jobs are launched by default for each PR against dotnet/corefx:master.

Comment Phrase Job Launched
@dotnet-bot test Innerloop CentOS7.1 Debug Build and Test Innerloop CentOS7.1 Debug Build and Test
@dotnet-bot test Innerloop CentOS7.1 Release Build and Test Innerloop CentOS7.1 Release Build and Test
@dotnet-bot test Innerloop OSX Debug Build and Test Innerloop OSX Debug Build and Test
@dotnet-bot test Innerloop OSX Release Build and Test Innerloop OSX Release Build and Test
@dotnet-bot test Innerloop Ubuntu14.04 Debug Build and Test Innerloop Ubuntu14.04 Debug Build and Test
@dotnet-bot test Innerloop Ubuntu14.04 Release Build and Test Innerloop Ubuntu14.04 Release Build and Test
@dotnet-bot test Innerloop Windows_NT Debug Build and Test Innerloop Windows_NT Debug Build and Test
@dotnet-bot test Innerloop Windows_NT Release Build and Test Innerloop Windows_NT Release Build and Test

The following optional jobs are available in PRs against dotnet/corefx:master.

Comment Phrase Job Launched
@dotnet-bot test code coverage Queues Code Coverage Windows Debug
@dotnet-bot test innerloop Debian8.4 Debug Queues Innerloop Debian8.4 Debug Build and Test
@dotnet-bot test innerloop Debian8.4 Release Queues Innerloop Debian8.4 Release Build and Test
@dotnet-bot test innerloop Fedora23 Debug Queues Innerloop Fedora23 Debug Build and Test
@dotnet-bot test innerloop Fedora23 Release Queues Innerloop Fedora23 Release Build and Test
@dotnet-bot test innerloop Fedora24 Debug Queues Innerloop Fedora24 Debug Build and Test
@dotnet-bot test innerloop Fedora24 Release Queues Innerloop Fedora24 Release Build and Test
@dotnet-bot test innerloop linuxarmemulator HardFP Debug Queues Innerloop Linux ARM Emulator HardFP Debug Cross Build
@dotnet-bot test innerloop linuxarmemulator HardFP Release Queues Innerloop Linux ARM Emulator HardFP Release Cross Build
@dotnet-bot test innerloop linuxarmemulator SoftFP Debug Queues Innerloop Linux ARM Emulator SoftFP Debug Cross Build
@dotnet-bot test innerloop linuxarmemulator SoftFP Release Queues Innerloop Linux ARM Emulator SoftFP Release Cross Build
@dotnet-bot test code formatter check Queues Code Formatter Check
@dotnet-bot test innerloop OpenSUSE13.2 Debug Queues Innerloop OpenSUSE13.2 Debug Build and Test
@dotnet-bot test innerloop OpenSUSE13.2 Release Queues Innerloop OpenSUSE13.2 Release Build and Test
@dotnet-bot test innerloop OpenSUSE42.1 Debug Queues Innerloop OpenSUSE42.1 Debug Build and Test
@dotnet-bot test innerloop OpenSUSE42.1 Release Queues Innerloop OpenSUSE42.1 Release Build and Test
@dotnet-bot test outerloop CentOS7.1 Debug Queues OuterLoop CentOS7.1 Debug
@dotnet-bot test outerloop CentOS7.1 Release Queues OuterLoop CentOS7.1 Release
@dotnet-bot test outerloop Debian8.4 Debug Queues OuterLoop Debian8.4 Debug
@dotnet-bot test outerloop Debian8.4 Release Queues OuterLoop Debian8.4 Release
@dotnet-bot test outerloop Fedora23 Debug Queues OuterLoop Fedora23 Debug
@dotnet-bot test outerloop Fedora23 Release Queues OuterLoop Fedora23 Release
@dotnet-bot test outerloop Fedora24 Debug Queues OuterLoop Fedora24 Debug
@dotnet-bot test outerloop Fedora24 Release Queues OuterLoop Fedora24 Release
@dotnet-bot test outerloop OpenSUSE13.2 Debug Queues OuterLoop OpenSUSE13.2 Debug
@dotnet-bot test outerloop OpenSUSE13.2 Release Queues OuterLoop OpenSUSE13.2 Release
@dotnet-bot test outerloop OpenSUSE42.1 Debug Queues OuterLoop OpenSUSE42.1 Debug
@dotnet-bot test outerloop OpenSUSE42.1 Release Queues OuterLoop OpenSUSE42.1 Release
@dotnet-bot test outerloop OSX Debug Queues OuterLoop OSX Debug
@dotnet-bot test outerloop OSX Release Queues OuterLoop OSX Release
@dotnet-bot test outerloop RHEL7.2 Debug Queues OuterLoop RHEL7.2 Debug
@dotnet-bot test outerloop RHEL7.2 Release Queues OuterLoop RHEL7.2 Release
@dotnet-bot test outerloop Ubuntu14.04 Debug Queues OuterLoop Ubuntu14.04 Debug
@dotnet-bot test outerloop Ubuntu14.04 Release Queues OuterLoop Ubuntu14.04 Release
@dotnet-bot test outerloop Ubuntu16.04 Debug Queues OuterLoop Ubuntu16.04 Debug
@dotnet-bot test outerloop Ubuntu16.04 Release Queues OuterLoop Ubuntu16.04 Release
@dotnet-bot test outerloop Ubuntu16.10 Debug Queues OuterLoop Ubuntu16.10 Debug
@dotnet-bot test outerloop Ubuntu16.10 Release Queues OuterLoop Ubuntu16.10 Release
@dotnet-bot test outerloop Windows 10 Debug Queues OuterLoop Windows 10 Debug
@dotnet-bot test outerloop Windows 10 Release Queues OuterLoop Windows 10 Release
@dotnet-bot test outerloop Windows 7 Debug Queues OuterLoop Windows 7 Debug
@dotnet-bot test outerloop Windows 7 Release Queues OuterLoop Windows 7 Release
@dotnet-bot test outerloop Windows_NT Debug Queues OuterLoop Windows_NT Debug
@dotnet-bot test outerloop Windows_NT Release Queues OuterLoop Windows_NT Release
@dotnet-bot test outerloop Windows Nano 2016 Debug Queues OuterLoop Windows Nano 2016 Debug
@dotnet-bot test outerloop Windows Nano 2016 Release Queues OuterLoop Windows Nano 2016 Release
@dotnet-bot test innerloop RHEL7.2 Debug Queues Innerloop RHEL7.2 Debug Build and Test
@dotnet-bot test innerloop RHEL7.2 Release Queues Innerloop RHEL7.2 Release Build and Test
@dotnet-bot test innerloop Ubuntu16.04 Debug Queues Innerloop Ubuntu16.04 Debug Build and Test
@dotnet-bot test innerloop Ubuntu16.04 Release Queues Innerloop Ubuntu16.04 Release Build and Test
@dotnet-bot test innerloop Ubuntu16.10 Debug Queues Innerloop Ubuntu16.10 Debug Build and Test
@dotnet-bot test innerloop Ubuntu16.10 Release Queues Innerloop Ubuntu16.10 Release Build and Test

Have a nice day!

@danmoseley
Copy link
Copy Markdown
Member

@mmitche oh - didn't realize as none of hte others need please. maybe better to take that off..

@mmitche
Copy link
Copy Markdown
Member

mmitche commented Jan 3, 2017

@danmosemsft Someone at some time had requested that it be added. But yeah we can remove it.

@joperezr
Copy link
Copy Markdown
Member

joperezr commented Jan 4, 2017

@AlexRadch seems like you need to rebase the changes you made on System.Runtime.Extensions.Tests.csproj, do you mind doing it so that we can re-run the CI?

@karelz
Copy link
Copy Markdown
Member

karelz commented Jan 11, 2017

@AlexRadch ping?

@karelz
Copy link
Copy Markdown
Member

karelz commented Jan 19, 2017

The PR seems to be abandoned for 1 month. Closing for now.

@karelz karelz closed this Jan 19, 2017
@karelz karelz modified the milestone: 2.0.0 Jan 21, 2017
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.

9 participants