This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Test StringComparer.FromComparison #14623
Closed
AlexRadch
wants to merge
10
commits into
dotnet:master
from
AlexRadch:StringComparerTests-FromComparisonTest
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
586b6d3
Make it easier to use StringComparison & StringComparer with GetHashCode
AlexRadch 2623c40
comparison
AlexRadch 153bb1d
StringComparison.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase
AlexRadch 2f468d8
@justinvp Code review
AlexRadch 45a204a
FromComparisonInvalidTest
AlexRadch 4e6b38c
@justinvp Code review
AlexRadch 8a2f6b5
comparisonType
AlexRadch ae7a430
public static readonly object[][] FromComparison_TestData =
AlexRadch 4bce08f
Assert.Throw<ArgumentException>(() => StringComparer.FromComparison(m…
AlexRadch 689a0d1
Throws
AlexRadch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/System.Runtime.Extensions/tests/System/StringComparer.netcoreapp1.1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace System.Tests | ||
| { | ||
| public static partial class MiscStringComparerTests | ||
| { | ||
| public static readonly object[][] FromComparison_TestData = | ||
| { | ||
| // StringComparison StringComparer | ||
| new object[] { StringComparison.CurrentCulture, StringComparer.CurrentCulture }, | ||
| new object[] { StringComparison.CurrentCultureIgnoreCase, StringComparer.CurrentCultureIgnoreCase }, | ||
| new object[] { StringComparison.InvariantCulture, StringComparer.InvariantCulture }, | ||
| new object[] { StringComparison.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase }, | ||
| new object[] { StringComparison.Ordinal, StringComparer.Ordinal }, | ||
| new object[] { StringComparison.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase }, | ||
| }; | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(FromComparison_TestData))] | ||
| public static void FromComparisonTest(StringComparison comparison, StringComparer comparer) | ||
| { | ||
| Assert.Equal(comparer, StringComparer.FromComparison(comparison)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void FromComparisonInvalidTest() | ||
| { | ||
| StringComparison minInvalid = Enum.GetValues(typeof(StringComparison)).Cast<StringComparison>().Min() - 1; | ||
| StringComparison maxInvalid = Enum.GetValues(typeof(StringComparison)).Cast<StringComparison>().Max() + 1; | ||
|
|
||
| Assert.Throws<ArgumentException>(() => StringComparer.FromComparison(minInvalid)); | ||
| Assert.Throws<ArgumentException>(() => StringComparer.FromComparison(maxInvalid)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.